Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fedora 39 based static checks and necessary fixes #5381

Merged
merged 5 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cf-agent/simulate_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cf-agent/verify_files_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 4 additions & 3 deletions cf-monitord/env_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down
14 changes: 7 additions & 7 deletions cf-monitord/monitoring.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cf-monitord/monitoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions libpromises/changes_chroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion libpromises/cmdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
9 changes: 2 additions & 7 deletions libpromises/evalfunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion libpromises/generic_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion tests/static-check/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/static-check/run_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down