From 0a0873252ebdda11f36e2f3ef99dd412a5b7ec78 Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Fri, 13 Aug 2021 12:28:58 -0500 Subject: [PATCH] Fix CodeQL warnings --- rigs/yaesu/ft757gx.c | 4 ++-- rigs/yaesu/newcat.c | 2 +- rotators/amsat/if100.c | 2 +- src/misc.c | 3 ++- src/sprintflst.c | 34 +++++++++++++++++++++++++--------- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/rigs/yaesu/ft757gx.c b/rigs/yaesu/ft757gx.c index 5c9ca6f89..2429017ee 100644 --- a/rigs/yaesu/ft757gx.c +++ b/rigs/yaesu/ft757gx.c @@ -691,7 +691,7 @@ int ft757_get_update_data(RIG *rig) unsigned char cmd[YAESU_CMD_LENGTH] = { 0x00, 0x00, 0x00, 0x00, 0x10}; struct ft757_priv_data *priv = (struct ft757_priv_data *)rig->state.priv; int retval = 0; - int nbtries ; + long nbtries; /* Maximum number of attempts to ask/read the data. */ int maxtries = rig->state.rigport.retry ; @@ -723,7 +723,7 @@ int ft757_get_update_data(RIG *rig) } rig_debug(RIG_DEBUG_ERR, - "%s: read update_data failed, %d octets of %d read, retry %d out of %d\n", + "%s: read update_data failed, %d octets of %d read, retry %ld out of %d\n", __func__, retval, FT757GX_STATUS_UPDATE_DATA_LENGTH, nbtries, maxtries); /* The delay is quadratic. */ diff --git a/rigs/yaesu/newcat.c b/rigs/yaesu/newcat.c index a3e608dee..bc63e96c5 100644 --- a/rigs/yaesu/newcat.c +++ b/rigs/yaesu/newcat.c @@ -2236,7 +2236,7 @@ int newcat_get_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t *offs) /* chop term */ priv->ret_data[ret_data_len - 1] = '\0'; - *offs = atoi(retoffs) * step; + *offs = atol(retoffs) * step; RETURNFUNC(RIG_OK); } diff --git a/rotators/amsat/if100.c b/rotators/amsat/if100.c index 91e445cb2..6d18abde1 100644 --- a/rotators/amsat/if100.c +++ b/rotators/amsat/if100.c @@ -45,7 +45,7 @@ if100_set_position(ROT *rot, azimuth_t az, elevation_t el) int az_i; int el_i; int dataout, i; - float az_scale, el_scale; + double az_scale, el_scale; rig_debug(RIG_DEBUG_TRACE, "%s called: %f %f\n", __func__, az, el); diff --git a/src/misc.c b/src/misc.c index 15f3d3e8a..ad9b9694c 100644 --- a/src/misc.c +++ b/src/misc.c @@ -2351,8 +2351,9 @@ char *date_strget(char *buf, int buflen) struct tm *mytm; time_t t; struct timeval tv; + struct tm result; t = time(NULL); - mytm = gmtime(&t); + mytm = gmtime_r(&t, &result); strftime(buf, buflen, "%Y-%m-%d:%H:%M:%S.", mytm); gettimeofday(&tv, NULL); sprintf(tmp, "%06ld", (long)tv.tv_usec); diff --git a/src/sprintflst.c b/src/sprintflst.c index 9ede0bd4a..4f43ea192 100644 --- a/src/sprintflst.c +++ b/src/sprintflst.c @@ -729,7 +729,7 @@ int rot_sprintf_status(char *str, int nlen, rot_status_t status) int rig_sprintf_spectrum_modes(char *str, int nlen, const enum rig_spectrum_mode_e *modes) { - int i, len = 0; + int i, len = 0, lentmp; *str = '\0'; @@ -749,16 +749,22 @@ int rig_sprintf_spectrum_modes(char *str, int nlen, const enum rig_spectrum_mode break; } - len += snprintf(str + len, nlen - len, "%d=%s ", modes[i], sm); + lentmp = snprintf(str + len, nlen - len, "%d=%s ", modes[i], sm); + if (len < 0 || lentmp >= nlen - len) + { + rig_debug(RIG_DEBUG_ERR,"%s(%d): overflowed str buffer\n", __FILE__, __LINE__); + break; + } + len += lentmp; + } - check_buffer_overflow(str, len, nlen); return len; } int rig_sprintf_spectrum_spans(char *str, int nlen, const freq_t *spans) { - int i, len = 0; + int i, len = 0, lentmp; *str = '\0'; @@ -769,16 +775,21 @@ int rig_sprintf_spectrum_spans(char *str, int nlen, const freq_t *spans) break; } - len += snprintf(str + len, nlen - len, "%.0f ", spans[i]); + lentmp = snprintf(str + len, nlen - len, "%.0f ", spans[i]); + if (len < 0 || lentmp >= nlen - len) + { + rig_debug(RIG_DEBUG_ERR,"%s(%d): overflowed str buffer\n", __FILE__, __LINE__); + break; + } + len += lentmp; } - check_buffer_overflow(str, len, nlen); return len; } int rig_sprintf_spectrum_avg_modes(char *str, int nlen, const struct rig_spectrum_avg_mode *avg_modes) { - int i, len = 0; + int i, len = 0, lentmp; *str = '\0'; @@ -789,10 +800,15 @@ int rig_sprintf_spectrum_avg_modes(char *str, int nlen, const struct rig_spectru break; } - len += snprintf(str + len, nlen - len, "%d=\"%s\" ", avg_modes[i].id, avg_modes[i].name); + lentmp = snprintf(str + len, nlen - len, "%d=\"%s\" ", avg_modes[i].id, avg_modes[i].name); + if (len < 0 || lentmp >= nlen - len) + { + rig_debug(RIG_DEBUG_ERR,"%s(%d): overflowed str buffer\n", __FILE__, __LINE__); + break; + } + len += lentmp; } - check_buffer_overflow(str, len, nlen); return len; }