From b276416014e4ea27a523c63d912c925dd53675c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Fri, 21 Feb 2025 14:16:51 +0000 Subject: [PATCH 1/7] Update .gitignore with CodeChecker files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Edwin Török --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 8a1ce60..f581313 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ include/mtcerrno.h scripts/generr scripts/generr.o scripts/ha_errnorc +compile_commands.json +.cache/ From 9f5f8ec45baad5d238fd2333372cb903bad5916b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Fri, 21 Feb 2025 14:16:51 +0000 Subject: [PATCH 2/7] Tell the compiler that `log_message` takes a format string as argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise it warns that it is a non-literal and can't type check it. Signed-off-by: Edwin Török --- include/log.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/log.h b/include/log.h index cb2b221..3063afd 100755 --- a/include/log.h +++ b/include/log.h @@ -195,7 +195,8 @@ extern void log_message( MTC_S32 priority, PMTC_S8 fmt, - ...); + ...) +__attribute__((format (printf, 2, 3))); // log_bin From 2dadb756878e3e525cacb9d6be068d00a0a1e09b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Fri, 21 Feb 2025 14:16:51 +0000 Subject: [PATCH 3/7] CA-406953: fix potential crash in writestatefile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `v` was missing, and instead of calling the varargs version of printf, it called the regular one. Signed-off-by: Edwin Török --- commands/stubs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/commands/stubs.c b/commands/stubs.c index 7e00376..42694e7 100755 --- a/commands/stubs.c +++ b/commands/stubs.c @@ -41,6 +41,7 @@ #include "mtctypes.h" #include "mtcerrno.h" +#include "log.h" void log_message( @@ -51,7 +52,7 @@ log_message( va_list ap; va_start(ap, fmt); - fprintf(stderr, fmt, ap); + (void)vfprintf(stderr, fmt, ap); va_end(ap); fflush(stderr); From 5bcf80fb5519aba5912d2e99e1f749d845b82329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Fri, 21 Feb 2025 16:00:40 +0000 Subject: [PATCH 4/7] CA-406953: fix(open): must supply mode with O_CREAT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: ``` /usr/include/x86_64-linux-gnu/bits/fcntl2.h:50:11: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments ``` Signed-off-by: Edwin Török --- lib/weightio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/weightio.c b/lib/weightio.c index 273642c..d951beb 100644 --- a/lib/weightio.c +++ b/lib/weightio.c @@ -121,7 +121,7 @@ MTC_STATUS open_hostweight_file(int *fd, int *err_no) { - if ((*fd = open(HA_HOST_WEIGHT_FILE, O_RDWR|O_CREAT)) < 0) + if ((*fd = open(HA_HOST_WEIGHT_FILE, O_RDWR|O_CREAT, 00400)) < 0) { *err_no = errno; return MTC_ERROR_WEIGHT_OPEN; From 79ed87bfc5d37b009d42bc5717680cf3109b346f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Fri, 21 Feb 2025 14:16:51 +0000 Subject: [PATCH 5/7] CA-406953: Use fixed size integer types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not rely on size of 'int' and 'long long', although they happened to work in this case. Use stdint.h types instead. Signed-off-by: Edwin Török --- include/mtctypes.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/mtctypes.h b/include/mtctypes.h index 2e1f81e..7ba0637 100755 --- a/include/mtctypes.h +++ b/include/mtctypes.h @@ -55,6 +55,7 @@ #include #include +#include // // @@ -128,11 +129,11 @@ typedef signed short MTC_S16; // 16 bits // However, int is 4 bytes for both. // -typedef unsigned int MTC_U32; // 32 bits -typedef signed int MTC_S32; // 32 bits +typedef uint32_t MTC_U32; // 32 bits +typedef int32_t MTC_S32; // 32 bits -typedef unsigned long long MTC_U64; // 64 bits -typedef long long MTC_S64; // 64 bits +typedef uint64_t MTC_U64; // 64 bits +typedef int64_t MTC_S64; // 64 bits // From 809c70e9bd28643d02350a68eb8c58623cc928b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Fri, 21 Feb 2025 14:16:51 +0000 Subject: [PATCH 6/7] CA-406953: Fix format string warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sometimes a format string with wrong signedness, or wrong size was used. The wrong size is probably undefined behaviour. Signed-off-by: Edwin Török --- daemon/com.c | 11 ++++++----- daemon/heartbeat.c | 5 +++-- daemon/sc_func.c | 3 ++- daemon/sm.c | 10 ++++++---- daemon/watchdog.c | 2 +- daemon/xapi_mon.c | 3 ++- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/daemon/com.c b/daemon/com.c index b9a76cc..55fb450 100755 --- a/daemon/com.c +++ b/daemon/com.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "mtctypes.h" #include "mtcerrno.h" @@ -269,7 +270,7 @@ MTC_STATIC HA_COMMON_OBJECT_HANDLE_INTERNAL new_handle = malloc(sizeof(HA_COMMON_OBJECT_HANDLE_INTERNAL)); if (new_handle == NULL) { - log_internal(MTC_LOG_ERR, "COM: cannot allocate for object_handle (size=%d).\n", sizeof(HA_COMMON_OBJECT_HANDLE_INTERNAL)); + log_internal(MTC_LOG_ERR, "COM: cannot allocate for object_handle (size=%zu).\n", sizeof(HA_COMMON_OBJECT_HANDLE_INTERNAL)); return NULL; } new_handle->object = object; @@ -307,7 +308,7 @@ new_object( new = malloc(sizeof(HA_COMMON_OBJECT)); if (new == NULL) { - log_internal(MTC_LOG_ERR, "COM: cannot allocate for object (size=%d).\n", sizeof(HA_COMMON_OBJECT)); + log_internal(MTC_LOG_ERR, "COM: cannot allocate for object (size=%zu).\n", sizeof(HA_COMMON_OBJECT)); return NULL; } new->next = NULL; @@ -452,7 +453,7 @@ MTC_STATIC HA_COMMON_OBJECT_CALLBACK_LIST_ITEM new = malloc(sizeof(HA_COMMON_OBJECT_CALLBACK_LIST_ITEM)); if (new == NULL) { - log_internal(MTC_LOG_ERR, "COM: cannot allocate for callback (size=%d).\n", sizeof(HA_COMMON_OBJECT_CALLBACK_LIST_ITEM)); + log_internal(MTC_LOG_ERR, "COM: cannot allocate for callback (size=%zu).\n", sizeof(HA_COMMON_OBJECT_CALLBACK_LIST_ITEM)); return NULL; } new->next = NULL; @@ -573,7 +574,7 @@ set_thread_id_record( return; } } - log_message(MTC_LOG_WARNING, "COM: thread_id %d not found in thraed_id_record_table.\n", self); + log_message(MTC_LOG_WARNING, "COM: thread_id %lu not found in thread_id_record_table.\n", self); break; } assert(FALSE); @@ -619,7 +620,7 @@ com_log_all_objects( { if (object->thread_id_record_table[tid_index].lock_state != LOCK_STATE_NONE) { - log_message(MTC_LOG_DEBUG, "COM: lock_state=%d thread_id=%x changed_time=%d(ms) .\n", + log_message(MTC_LOG_DEBUG, "COM: lock_state=%d thread_id=0x%lx changed_time=%"PRId64"(ms) .\n", object->thread_id_record_table[tid_index].lock_state, object->thread_id_record_table[tid_index].thread_id, now - object->thread_id_record_table[tid_index].changed_time diff --git a/daemon/heartbeat.c b/daemon/heartbeat.c index 9244b3a..1543e1d 100755 --- a/daemon/heartbeat.c +++ b/daemon/heartbeat.c @@ -45,6 +45,7 @@ #include #include #include +#include // @@ -1454,7 +1455,7 @@ hb_check_fist( if (target_delay != 0) { log_message(MTC_LOG_DEBUG, - "HB(FIST): heartbeat delay is %d ms\n", target_delay); + "HB(FIST): heartbeat delay is %"PRId64" ms\n", target_delay); ts = ts_rem = mstots(target_delay); while (nanosleep(&ts, &ts_rem)) ts = ts_rem; @@ -1485,7 +1486,7 @@ hb_check_fist_sticky() if (target_delay != 0) { log_message(MTC_LOG_DEBUG, - "HB(FIST): heartbeat delay is %d ms\n", target_delay); + "HB(FIST): heartbeat delay is %"PRId64" ms\n", target_delay); ts = mstots(target_delay); while (nanosleep(&ts, &ts_rem)) ts = ts_rem; diff --git a/daemon/sc_func.c b/daemon/sc_func.c index da2cb57..258dd31 100755 --- a/daemon/sc_func.c +++ b/daemon/sc_func.c @@ -39,6 +39,7 @@ #include #include #include +#include #include "mtctypes.h" #include "mtcerrno.h" @@ -551,7 +552,7 @@ script_service_do_query_liveset( if (!xapi_approaching_timeout_reported || (logmask & MTC_LOG_MASK_SC_WARNING)) { - log_message(MTC_LOG_WARNING, "SC: (%s) reporting \"Xapi approaching timeout\". now=%d start=%d.\n", __func__, now, xapimon->time_healthcheck_start); + log_message(MTC_LOG_WARNING, "SC: (%s) reporting \"Xapi approaching timeout\". now=%"PRId64" start=%"PRId64".\n", __func__, now, xapimon->time_healthcheck_start); } l->xapi_approaching_timeout = TRUE; } diff --git a/daemon/sm.c b/daemon/sm.c index b347f00..d626a80 100755 --- a/daemon/sm.c +++ b/daemon/sm.c @@ -42,6 +42,7 @@ #include #include #include +#include @@ -322,7 +323,8 @@ MTC_STATIC void print_liveset( MTC_S32 pri, PMTC_S8 log_string, - MTC_HOSTMAP hostmap); + MTC_HOSTMAP hostmap) +__attribute__((format(printf, 2, 0))); MTC_STATIC void wait_until_HBSF_state_stable(); @@ -2289,7 +2291,7 @@ wait_until_HBSF_state_stable() { log_maskable_debug_message(FH_TRACE, "FH: waiting for HB from host (%d)," - " time since last HB receive = %d.\n", + " time since last HB receive = %"PRId64".\n", index, now - phb->time_last_HB[index]); logged_hb[index] = TRUE; } @@ -2304,7 +2306,7 @@ wait_until_HBSF_state_stable() { log_maskable_debug_message(FH_TRACE, "FH: waiting for SF from host (%d)," - " time since last SF update = %d.\n", + " time since last SF update = %"PRId64".\n", index, now - psf->time_last_SF[index]); logged_sf[index] = TRUE; @@ -2543,7 +2545,7 @@ wait_until_all_hosts_have_consistent_view( MTC_HOSTMAP_SET(removedhost, selected); } - log_message(MTC_LOG_WARNING, "after merger:\n", index); + log_message(MTC_LOG_WARNING, "after merger: %d\n", index); for (index = 0; _is_configured_host(index); index++) { MTC_HOSTMAP_INTERSECTION(phb->raw[index].hbdomain, '=', diff --git a/daemon/watchdog.c b/daemon/watchdog.c index 901fb75..7fe1ca4 100755 --- a/daemon/watchdog.c +++ b/daemon/watchdog.c @@ -752,7 +752,7 @@ watchdog_create( new = malloc(sizeof(WATCHDOG_INSTANCE)); if (new == NULL) { - log_internal(MTC_LOG_ERR, "WD: cannnot malloc size = %d.\n", sizeof(WATCHDOG_INSTANCE)); + log_internal(MTC_LOG_ERR, "WD: cannnot malloc size = %zu.\n", sizeof(WATCHDOG_INSTANCE)); ret = MTC_ERROR_WD_INSUFFICIENT_RESOURCE; goto error_return; } diff --git a/daemon/xapi_mon.c b/daemon/xapi_mon.c index a3d0ec4..5deda26 100755 --- a/daemon/xapi_mon.c +++ b/daemon/xapi_mon.c @@ -47,6 +47,7 @@ #include #include #include +#include // @@ -438,7 +439,7 @@ xapimon( if (target_delay != 0) { log_message(MTC_LOG_DEBUG, - "XM(FIST): xapi healthcheck delay is %d ms\n", target_delay); + "XM(FIST): xapi healthcheck delay is %"PRId64" ms\n", target_delay); xm_sleep(target_delay - (_getms() - start)); } From dd041673593aca72bc0a533d5cd02dab42523fcd Mon Sep 17 00:00:00 2001 From: Gerald Elder-Vass <47088217+GeraldEV@users.noreply.github.com> Date: Wed, 5 Mar 2025 15:31:13 +0000 Subject: [PATCH 7/7] Use a single leading 0 for octal permissions --- lib/weightio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/weightio.c b/lib/weightio.c index d951beb..3f24264 100644 --- a/lib/weightio.c +++ b/lib/weightio.c @@ -121,7 +121,7 @@ MTC_STATUS open_hostweight_file(int *fd, int *err_no) { - if ((*fd = open(HA_HOST_WEIGHT_FILE, O_RDWR|O_CREAT, 00400)) < 0) + if ((*fd = open(HA_HOST_WEIGHT_FILE, O_RDWR|O_CREAT, 0400)) < 0) { *err_no = errno; return MTC_ERROR_WEIGHT_OPEN;