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

gcc-8.2.0 warnings: possible buffer overflow #1171

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/bin/jp2/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ int imagetopgx(opj_image_t * image, const char *outfile)
goto fin;
}
}
strncpy(name, outfile, dotpos);
memcpy(name, outfile, dotpos);
sprintf(name + dotpos, "_%u.pgx", compno);
fdest = fopen(name, "wb");
/* don't need name anymore */
Expand Down Expand Up @@ -2212,7 +2212,7 @@ int imagetopnm(opj_image_t * image, const char *outfile, int force_split)
const size_t olen = strlen(outfile);
const size_t dotpos = olen - 4;

strncpy(destname, outfile, dotpos);
memcpy(destname, outfile, dotpos);
sprintf(destname + dotpos, "_%u.pgm", compno);
} else {
sprintf(destname, "%s", outfile);
Expand Down
20 changes: 11 additions & 9 deletions src/bin/jp2/opj_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,31 +530,33 @@ static char * get_file_name(char *name)
static char get_next_file(int imageno, dircnt_t *dirptr, img_fol_t *img_fol,
opj_cparameters_t *parameters)
{
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],
outfilename[OPJ_PATH_LEN], temp_ofname[OPJ_PATH_LEN];
char *temp_p, temp1[OPJ_PATH_LEN] = "";
char image_filename[OPJ_PATH_LEN + 2], infilename[OPJ_PATH_LEN * 2],
outfilename[OPJ_PATH_LEN * 2], temp_ofname[OPJ_PATH_LEN + 2];
char *temp_p, temp1[OPJ_PATH_LEN + 2] = "";

strcpy(image_filename, dirptr->filename[imageno]);
strncpy(image_filename, dirptr->filename[imageno], OPJ_PATH_LEN);
fprintf(stderr, "File Number %d \"%s\"\n", imageno, image_filename);
parameters->decod_format = get_file_format(image_filename);
if (parameters->decod_format == -1) {
return 1;
}
sprintf(infilename, "%s/%s", img_fol->imgdirpath, image_filename);
snprintf(infilename, OPJ_PATH_LEN * 2, "%s/%s", img_fol->imgdirpath,
image_filename);
if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile),
infilename) != 0) {
return 1;
}

/*Set output file*/
strcpy(temp_ofname, get_file_name(image_filename));
strncpy(temp_ofname, get_file_name(image_filename), OPJ_PATH_LEN);
while ((temp_p = strtok(NULL, ".")) != NULL) {
strcat(temp_ofname, temp1);
sprintf(temp1, ".%s", temp_p);
}
if (img_fol->set_out_format == 1) {
sprintf(outfilename, "%s/%s.%s", img_fol->imgdirpath, temp_ofname,
img_fol->out_format);
snprintf(outfilename, OPJ_PATH_LEN * 2, "%s/%s.%s", img_fol->imgdirpath,
temp_ofname,
img_fol->out_format);
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile),
outfilename) != 0) {
return 1;
Expand Down Expand Up @@ -940,7 +942,7 @@ static int parse_cmdline_encoder(int argc, char **argv,
case 'p': { /* progression order */
char progression[4];

strncpy(progression, opj_optarg, 4);
memcpy(progression, opj_optarg, 4);
parameters->prog_order = give_progression(progression);
if (parameters->prog_order == -1) {
fprintf(stderr, "Unrecognized progression order "
Expand Down
2 changes: 1 addition & 1 deletion src/bin/jp2/opj_decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ char get_next_file(int imageno, dircnt_t *dirptr, img_fol_t *img_fol,
opj_decompress_parameters *parameters)
{
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],
outfilename[OPJ_PATH_LEN], temp_ofname[OPJ_PATH_LEN];
outfilename[OPJ_PATH_LEN * 2], temp_ofname[OPJ_PATH_LEN];
char *temp_p, temp1[OPJ_PATH_LEN] = "";

strcpy(image_filename, dirptr->filename[imageno]);
Expand Down
7 changes: 4 additions & 3 deletions src/bin/jp2/opj_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ static int get_file_format(const char *filename)
static char get_next_file(int imageno, dircnt_t *dirptr, img_fol_t *img_fol,
opj_dparameters_t *parameters)
{
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],
outfilename[OPJ_PATH_LEN], temp_ofname[OPJ_PATH_LEN];
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN * 2],
outfilename[OPJ_PATH_LEN * 2], temp_ofname[OPJ_PATH_LEN];
char *temp_p, temp1[OPJ_PATH_LEN] = "";

strcpy(image_filename, dirptr->filename[imageno]);
Expand All @@ -211,7 +211,8 @@ static char get_next_file(int imageno, dircnt_t *dirptr, img_fol_t *img_fol,
if (parameters->decod_format == -1) {
return 1;
}
sprintf(infilename, "%s/%s", img_fol->imgdirpath, image_filename);
snprintf(infilename, OPJ_PATH_LEN * 2, "%s/%s", img_fol->imgdirpath,
image_filename);
if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile),
infilename) != 0) {
return 1;
Expand Down