cisco/joy

Potential uninitialized variable

QiAnXinCodeSafe opened this issue · 1 comments

variable 'output_dir' declared here, without initialization:

joy/src/joy.c

Line 928 in 5dd5b71

char output_dir[MAX_FILENAME_LEN];

the value of 'output_dir' is set in if block;

joy/src/joy.c

Lines 941 to 957 in 5dd5b71

if (glb_config->filename) {
strncpy_s(output_dir, MAX_FILENAME_LEN, glb_config->filename, (MAX_FILENAME_LEN-1));
/* create a directory to place all of the output files into */
memset_s(&st, sizeof(struct stat), 0x00, sizeof(struct stat));
if (stat(output_dir, &st) == -1) {
#ifdef WIN32
mkdir(output_dir);
#else
tmp_ret = mkdir(output_dir, 0700);
if (tmp_ret < 0) {
joy_log_err("Error creating directory: %s\n", output_dir);
return tmp_ret;
}
#endif
}
}

while using this variable such as in line 994, may a potential uninitialized variable is used:

joy/src/joy.c

Line 994 in 5dd5b71

sprintf(full_path_output, "%s/%s_%d_json%s", output_dir, ent->d_name, fc_cnt, zsuffix);

usage occurs inside the same condition check that occurs when setting the variable. Therefore, the variable will be initialized if it is going to be used.