Fix coverity issue 425241 (#17424)
Add check for statement preparation failure Properly check for bind failure
Stelios Fragkakis committed
Apr 17, 2024 at 18:09 UTC
2d70c2e0c9786706cf5b019e33bd24b30d06cb4c
1 file changed
+5
-5
src/database/sqlite/sqlite_health.c
+5
-5
@@ -1423,6 +1423,7 @@ void sql_alert_transitions(
1423
if (unlikely(!nodes))
1424
return;
1425
1426
+ int param = 0;
1427
if (transition) {
1428
if (uuid_parse(transition, transition_uuid)) {
1429
error_report("Invalid transition given %s", transition);
@@ -1430,12 +1431,12 @@ void sql_alert_transitions(
1431
}
1432
1433
rc = sqlite3_prepare_v2(db_meta, SQL_SEARCH_ALERT_TRANSITION_DIRECT, -1, &res, 0);
1433
-
1434
- rc = sqlite3_bind_blob(res, 1, &transition_uuid, sizeof(transition_uuid), SQLITE_STATIC);
1434
if (unlikely(rc != SQLITE_OK)) {
1436
- error_report("Failed to bind transition_id parameter");
1437
- goto done;
1435
+ error_report("Failed to prepare statement to search transition");
1436
+ goto done_only_drop;
1437
}
1438
+
1439
+ SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &transition_uuid, sizeof(transition_uuid), SQLITE_STATIC));
1440
goto run_query;
1441
}
1442
@@ -1496,7 +1497,6 @@ void sql_alert_transitions(
1497
goto done_only_drop;
1498
}
1499
1499
- int param = 0;
1500
SQLITE_BIND_FAIL(done, sqlite3_bind_int64(res, ++param, (sqlite3_int64)(after * USEC_PER_SEC)));
1501
SQLITE_BIND_FAIL(done, sqlite3_bind_int64(res, ++param, (sqlite3_int64)(before * USEC_PER_SEC)));
1502