diff --git a/cf-agent/simulate_mode.c b/cf-agent/simulate_mode.c index 0a0a7ef2c3..db56b04072 100644 --- a/cf-agent/simulate_mode.c +++ b/cf-agent/simulate_mode.c @@ -360,7 +360,7 @@ bool ManifestRename(const char *orig_name, const char *new_name) static bool RunDiff(const char *path1, const char *path2) { char diff_path[PATH_MAX]; - strncpy(diff_path, GetBinDir(), sizeof(diff_path)); + strncpy(diff_path, GetBinDir(), sizeof(diff_path) - 1); JoinPaths(diff_path, sizeof(diff_path), "diff"); /* We use the '--label' option to override the paths in the output, for example: diff --git a/cf-agent/verify_files_utils.c b/cf-agent/verify_files_utils.c index 70565706c3..99dd73f360 100644 --- a/cf-agent/verify_files_utils.c +++ b/cf-agent/verify_files_utils.c @@ -2148,7 +2148,7 @@ static PromiseResult VerifyName(EvalContext *ctx, char *path, const struct stat } else { - strncpy(newname, path, sizeof(newname)); + strncpy(newname, path, sizeof(newname) - 1); ChopLastNode(newname); if (!PathAppend(newname, sizeof(newname), diff --git a/cf-monitord/env_monitor.c b/cf-monitord/env_monitor.c index 6f68b99399..616c794097 100644 --- a/cf-monitord/env_monitor.c +++ b/cf-monitord/env_monitor.c @@ -385,7 +385,7 @@ static Averages EvalAvQ(EvalContext *ctx, char *t) char desc[CF_BUFSIZE]; double This; name[0] = '\0'; - GetObservable(i, name, desc); + GetObservable(i, name, sizeof(name), desc, sizeof(desc)); /* Overflow protection */ @@ -589,7 +589,8 @@ static void ArmClasses(EvalContext *ctx, const Averages *const av) double sigma; Item *ip, *mon_data = NULL; int i, j, k; - char buff[CF_BUFSIZE], ldt_buff[CF_BUFSIZE], name[CF_MAXVARSIZE]; + char buff[CF_BUFSIZE], ldt_buff[CF_BUFSIZE]; + char name[CF_MAXVARSIZE - 100]; /* used for names of variables with all sorts of prefixes */ static int anomaly[CF_OBSERVABLES][LDT_BUFSIZE] = { { 0 } }; extern Item *ALL_INCOMING; extern Item *MON_UDP4, *MON_UDP6, *MON_TCP4, *MON_TCP6; @@ -598,7 +599,7 @@ static void ArmClasses(EvalContext *ctx, const Averages *const av) { char desc[CF_BUFSIZE]; - GetObservable(i, name, desc); + GetObservable(i, name, sizeof(name), desc, sizeof(desc)); sigma = SetClasses(ctx, name, CF_THIS[i], av->Q[i].expect, av->Q[i].var, LOCALAV.Q[i].expect, LOCALAV.Q[i].var, &mon_data); SetVariable(name, CF_THIS[i], av->Q[i].expect, sigma, &mon_data); diff --git a/cf-monitord/monitoring.c b/cf-monitord/monitoring.c index 790ac9b3b1..f37b142f0f 100644 --- a/cf-monitord/monitoring.c +++ b/cf-monitord/monitoring.c @@ -147,26 +147,26 @@ static void Nova_DumpSlots(void) } } -void GetObservable(int i, char *name, char *desc) +void GetObservable(int i, char *name, size_t name_size, char *desc, size_t desc_size) { Nova_LoadSlots(); if (i < ob_spare) { - strncpy(name, OBSERVABLES[i][0], CF_MAXVARSIZE - 1); - strncpy(desc, OBSERVABLES[i][1], CF_MAXVARSIZE - 1); + strncpy(name, OBSERVABLES[i][0], name_size - 1); + strncpy(desc, OBSERVABLES[i][1], desc_size - 1); } else { if (SLOTS[i - ob_spare]) { - strncpy(name, SLOTS[i - ob_spare]->name, CF_MAXVARSIZE - 1); - strncpy(desc, SLOTS[i - ob_spare]->description, CF_MAXVARSIZE - 1); + strncpy(name, SLOTS[i - ob_spare]->name, name_size - 1); + strncpy(desc, SLOTS[i - ob_spare]->description, desc_size - 1); } else { - strncpy(name, OBSERVABLES[i][0], CF_MAXVARSIZE - 1); - strncpy(desc, OBSERVABLES[i][1], CF_MAXVARSIZE - 1); + strncpy(name, OBSERVABLES[i][0], name_size - 1); + strncpy(desc, OBSERVABLES[i][1], desc_size - 1); } } } diff --git a/cf-monitord/monitoring.h b/cf-monitord/monitoring.h index 10dadd02e0..1fcbd9155e 100644 --- a/cf-monitord/monitoring.h +++ b/cf-monitord/monitoring.h @@ -34,7 +34,7 @@ int NovaRegisterSlot(const char *name, const char *description, const char *units, double expected_minimum, double expected_maximum, bool consolidable); void NovaNamedEvent(const char *eventname, double value); -void GetObservable(int i, char *name, char *desc); +void GetObservable(int i, char *name, size_t name_size, char *desc, size_t desc_size); void SetMeasurementPromises(Item ** classlist); void LoadSlowlyVaryingObservations(EvalContext *ctx); void MakeTimekey(time_t time, char *result); diff --git a/libpromises/changes_chroot.c b/libpromises/changes_chroot.c index 3b97118cd1..794faba4d2 100644 --- a/libpromises/changes_chroot.c +++ b/libpromises/changes_chroot.c @@ -46,18 +46,18 @@ static inline const char *GetLastFileSeparator(const char *path, const char *end return cp; } -static char *GetFirstNonExistingParentDir(const char *path, char *buf) +static char *GetFirstNonExistingParentDir(const char *path, char buf[PATH_MAX]) { /* Get rid of the trailing file separator (if any). */ size_t path_len = strlen(path); if (path[path_len - 1] == FILE_SEPARATOR) { - strncpy(buf, path, path_len); + strncpy(buf, path, PATH_MAX - 1); buf[path_len] = '\0'; } else { - strncpy(buf, path, path_len + 1); + strncpy(buf, path, PATH_MAX - 1); } char *last_sep = (char *) GetLastFileSeparator(buf, buf + path_len); diff --git a/libpromises/cmdb.c b/libpromises/cmdb.c index 1a310e1c25..38e70e3d8b 100644 --- a/libpromises/cmdb.c +++ b/libpromises/cmdb.c @@ -505,7 +505,7 @@ static bool ReadCMDBClasses(EvalContext *ctx, JsonElement *classes) bool LoadCMDBData(EvalContext *ctx) { char file_path[PATH_MAX] = {0}; - strncpy(file_path, GetDataDir(), sizeof(file_path)); + strncpy(file_path, GetDataDir(), sizeof(file_path) - 1); JoinPaths(file_path, sizeof(file_path), HOST_SPECIFIC_DATA_FILE); if (access(file_path, F_OK) != 0) { diff --git a/libpromises/evalfunction.c b/libpromises/evalfunction.c index 43504f3ea6..82bf17054f 100644 --- a/libpromises/evalfunction.c +++ b/libpromises/evalfunction.c @@ -2744,14 +2744,9 @@ static FnCallResult FnCallUrlGet(ARG_UNUSED EvalContext *ctx, curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3L); // set default timeout curl_easy_setopt(curl, CURLOPT_VERBOSE, 0); curl_easy_setopt(curl, - CURLOPT_PROTOCOLS, - + CURLOPT_PROTOCOLS_STR, // Allowed protocols - CURLPROTO_FILE | - CURLPROTO_FTP | - CURLPROTO_FTPS | - CURLPROTO_HTTP | - CURLPROTO_HTTPS); + "file,ftp,ftps,http,https"); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cfengine_curl_write_callback); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, cfengine_curl_write_callback); diff --git a/libpromises/generic_agent.c b/libpromises/generic_agent.c index 1f545031e3..187d3df7e4 100644 --- a/libpromises/generic_agent.c +++ b/libpromises/generic_agent.c @@ -944,7 +944,7 @@ void GenericAgentDiscoverContext(EvalContext *ctx, GenericAgentConfig *config, strcpy(VPREFIX, ""); if (program_name != NULL) { - strncpy(CF_PROGRAM_NAME, program_name, sizeof(CF_PROGRAM_NAME)); + strncpy(CF_PROGRAM_NAME, program_name, sizeof(CF_PROGRAM_NAME) - 1); } Log(LOG_LEVEL_VERBOSE, " %s", NameVersion()); diff --git a/tests/static-check/run.sh b/tests/static-check/run.sh index 5cfdfb74d9..9b47189ea2 100755 --- a/tests/static-check/run.sh +++ b/tests/static-check/run.sh @@ -4,7 +4,7 @@ set -e trap "echo FAILURE" ERR if [ -z "$STATIC_CHECKS_FEDORA_VERSION" ]; then - default_f_ver="37" + default_f_ver="39" echo "No Fedora version for static checks specified, using the default (Fedora $default_f_ver)" BASE_IMG="fedora:$default_f_ver" STATIC_CHECKS_FEDORA_VERSION="$default_f_ver" diff --git a/tests/static-check/run_checks.sh b/tests/static-check/run_checks.sh index 07853c02fc..8077c69b81 100755 --- a/tests/static-check/run_checks.sh +++ b/tests/static-check/run_checks.sh @@ -8,7 +8,7 @@ function check_with_gcc() { rm -f config.cache make clean ./configure -C --enable-debug CC=gcc - local gcc_exceptions="-Wno-sign-compare" + local gcc_exceptions="-Wno-sign-compare -Wno-enum-int-mismatch" make -j -l${n_procs} --keep-going CFLAGS="-Werror -Wall -Wextra $gcc_exceptions" }