Skip to content

Commit

Permalink
Fixing covscan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
zdohnal committed Aug 15, 2018
1 parent 4a1a8e7 commit fc6a67d
Show file tree
Hide file tree
Showing 17 changed files with 161 additions and 32 deletions.
2 changes: 2 additions & 0 deletions backend/beh.c
Expand Up @@ -223,6 +223,8 @@ call_backend(char *uri, /* I - URI of final destination */
*/

strncpy(scheme, uri, sizeof(scheme));
if (strlen(uri) > 1023)
scheme[1023] = '\0';
if ((ptr = strchr(scheme, ':')) != NULL)
*ptr = '\0';

Expand Down
8 changes: 7 additions & 1 deletion cupsfilters/colormanager.c
Expand Up @@ -272,6 +272,9 @@ _get_colord_profile(const char *printer_name, /* Dest name */
free(qualifier);
}

if (icc_profile != NULL)
free(icc_profile);

return is_profile_set;

}
Expand Down Expand Up @@ -325,8 +328,11 @@ _get_ppd_icc_fallback (ppd_file_t *ppd, char **qualifier)
if (attr->value[0] != '/')
snprintf(full_path, sizeof(full_path),
"%s/profiles/%s", CUPSDATA, attr->value);
else
else {
strncpy(full_path, attr->value, sizeof(full_path));
if (strlen(attr->value) > 1023)
full_path[1023] = '\0';
}

/* check the file exists */
if (access(full_path, 0)) {
Expand Down
2 changes: 1 addition & 1 deletion cupsfilters/image-sgilib.c
Expand Up @@ -282,7 +282,7 @@ sgiOpenFile(FILE *file, /* I - File to open */
sgip->mode = SGI_WRITE;

putshort(SGI_MAGIC, sgip->file);
putc((sgip->comp = comp) != 0, sgip->file);
putc(((sgip->comp = comp) != 0) ? '1': '0', sgip->file);
putc(sgip->bpp = bpp, sgip->file);
putshort(3, sgip->file); /* Dimensions */
putshort(sgip->xsize = xsize, sgip->file);
Expand Down
1 change: 1 addition & 0 deletions cupsfilters/image-sun.c
Expand Up @@ -114,6 +114,7 @@ _cupsImageReadSunRaster(
ras_depth == 0 || ras_depth > 32)
{
fputs("DEBUG: Raster image cannot be loaded!\n", stderr);
fclose(fp);
return (1);
}

Expand Down
4 changes: 4 additions & 0 deletions cupsfilters/ppdgenerator.c
Expand Up @@ -930,6 +930,10 @@ load_opt_strings_catalog(const char *location, cups_array_t *options)
}
}
cupsFileClose(fp);
if (choice_name != NULL)
free(choice_name);
if (opt_name != NULL)
free(opt_name);
if (filename == tmpfile)
unlink(filename);
}
Expand Down
14 changes: 12 additions & 2 deletions cupsfilters/raster.c
Expand Up @@ -151,11 +151,14 @@ cupsRasterParseIPPOptions(cups_page_header2_t *h, /* I - Raster header */
strcasestr(s, "right") ||
strcasestr(s, "side") ||
strcasestr(s, "main"))
media_source = strdup(s);
{
if (media_source == NULL)
media_source = strdup(s);
}
else
media_type = strdup(s);
}
if (size_found)
if (page_size == NULL && size_found)
page_size = strdup(size_found->pwg);
}
}
Expand Down Expand Up @@ -1079,6 +1082,13 @@ cupsRasterParseIPPOptions(cups_page_header2_t *h, /* I - Raster header */
h->cupsRenderingIntent[0] = '\0';
#endif /* HAVE_CUPS_1_7 */

if (media_source != NULL)
free(media_source);
if (media_type != NULL)
free(media_type);
if (page_size != NULL)
free(page_size);

return (0);
}

Expand Down
9 changes: 9 additions & 0 deletions filter/bannertopdf.c
Expand Up @@ -514,6 +514,15 @@ static int generate_banner_pdf(banner_t *banner,
pdf_duplicate_page(doc, 1, copies);

pdf_write(doc, stdout);

opt_t * opt_current = known_opts;
opt_t * opt_next = NULL;
while (opt_current != NULL)
{
opt_next = opt_current->next;
free(opt_current);
opt_current = opt_next;
}
free(buf);
pdf_free(doc);
return 0;
Expand Down
22 changes: 19 additions & 3 deletions filter/foomatic-rip/foomaticrip.c
Expand Up @@ -666,6 +666,11 @@ int print_file(const char *filename, int convert)
ret = print_file("<STDIN>", 0);

wait_for_process(renderer_pid);
if (in != NULL)
fclose(in);
if (out != NULL)
fclose(out);

return ret;
}

Expand All @@ -683,6 +688,8 @@ int print_file(const char *filename, int convert)

case UNKNOWN_FILE:
_log("Cannot process \"%s\": Unknown filetype.\n", filename);
if (file != NULL)
fclose(file);
return 0;
}

Expand Down Expand Up @@ -811,10 +818,14 @@ int main(int argc, char** argv)

if (getenv("PPD")) {
strncpy(job->ppdfile, getenv("PPD"), 2048);
if (strlen(getenv("PPD")) > 2047)
job->ppdfile[2047] = '\0';
spooler = SPOOLER_CUPS;
if (getenv("CUPS_SERVERBIN"))
strncpy(cupsfilterpath, getenv("CUPS_SERVERBIN"),
sizeof(cupsfilterpath));
if (getenv("CUPS_SERVERBIN")) {
strncpy(cupsfilterpath, getenv("CUPS_SERVERBIN"), sizeof(cupsfilterpath));
if (strlen(getenv("CUPS_SERVERBIN")) > PATH_MAX-1)
cupsfilterpath[PATH_MAX-1] = '\0';
}
}

/* Check status of printer color management from the color manager */
Expand All @@ -834,10 +845,14 @@ int main(int argc, char** argv)
allow duplicates, and use the last specified one */
while ((str = arglist_get_value(arglist, "-p"))) {
strncpy(job->ppdfile, str, 2048);
if (strlen(str) > 2047)
job->ppdfile[2047] = '\0';
arglist_remove(arglist, "-p");
}
while ((str = arglist_get_value(arglist, "--ppd"))) {
strncpy(job->ppdfile, str, 2048);
if (strlen(str) > 2047)
job->ppdfile[2047] = '\0';
arglist_remove(arglist, "--ppd");
}

Expand Down Expand Up @@ -1020,6 +1035,7 @@ int main(int argc, char** argv)
cmd[0] = '\0';

snprintf(gstoraster, sizeof(gstoraster), "gs -dQUIET -dDEBUG -dPARANOIDSAFER -dNOPAUSE -dBATCH -dNOINTERPOLATE -dNOMEDIAATTRS -sDEVICE=cups -dShowAcroForm %s -sOutputFile=- -", cmd);
free(icc_profile);
}

/* build Ghostscript/CUPS driver command line */
Expand Down
3 changes: 3 additions & 0 deletions filter/foomatic-rip/options.c
Expand Up @@ -1044,6 +1044,7 @@ int option_set_value(option_t *opt, int optionset, const char *value)
if (choice && !isempty(choice->command))
composite_set_values(opt, optionset, choice->command);
}
free(newvalue);
return 1;
}

Expand Down Expand Up @@ -1914,6 +1915,8 @@ int ppd_supports_pdf()
if (startswith(cmd, "gs"))
{
strncpy(cmd_pdf, cmd, 4096);
if (strlen(cmd) > 4095)
cmd_pdf[4095] = '\0';
return 1;
}

Expand Down
2 changes: 2 additions & 0 deletions filter/foomatic-rip/spooler.c
Expand Up @@ -94,6 +94,8 @@ void init_cups(list_t *arglist, dstr_t *filelist, jobparams_t *job)
CUPS puts the print queue name into the PRINTER environment variable
when calling filters. */
strncpy(job->printer, getenv("PRINTER"), 256);
if (strlen(getenv("PRINTER")) > 255)
job->printer[255] = '\0';

free(cups_options);
}
Expand Down
2 changes: 2 additions & 0 deletions filter/pdftops.c
Expand Up @@ -427,6 +427,8 @@ main(int argc, /* I - Number of command-line args */
if ((val = cupsGetOption("make-and-model", num_options, options)) != NULL)
{
strncpy(make_model, val, sizeof(make_model));
if (strlen(val) > 127)
make_model[127] = '\0';
for (ptr = make_model; *ptr; ptr ++)
if (*ptr == '-') *ptr = ' ';
}
Expand Down
6 changes: 4 additions & 2 deletions filter/pdftoraster.cxx
Expand Up @@ -558,8 +558,10 @@ static void parseOpts(int argc, char **argv)
if (!cm_disabled)
cmGetPrinterIccProfile(getenv("PRINTER"), &profile, ppd);

if (profile != NULL)
colorProfile = cmsOpenProfileFromFile(profile,"r");
if (profile != NULL) {
colorProfile = cmsOpenProfileFromFile(profile,"r");
free(profile);
}

#ifdef HAVE_CUPS_1_7
if ((attr = ppdFindAttr(ppd,"PWGRaster",0)) != 0 &&
Expand Down
11 changes: 9 additions & 2 deletions filter/rastertoescpx.c
Expand Up @@ -1141,7 +1141,10 @@ EndPage(ppd_file_t *ppd, /* I - PPD file */
}
}
else
{
free(DotBuffers[0]);
DotBuffers[0] = NULL;
}

/*
* Output a page eject sequence...
Expand Down Expand Up @@ -1440,7 +1443,7 @@ CompressData(ppd_file_t *ppd, /* I - PPD file information */

printf("\033i");
putchar(ctable[PrinterPlanes - 1][plane]);
putchar(type != 0);
putchar((type != 0) ? '1': '0');
putchar(BitPlanes);
putchar(bytes & 255);
putchar(bytes >> 8);
Expand Down Expand Up @@ -1470,7 +1473,7 @@ CompressData(ppd_file_t *ppd, /* I - PPD file information */
bytes *= 8;

printf("\033.");
putchar(type != 0);
putchar((type != 0) ? '1': '0');
putchar(ystep);
putchar(xstep);
putchar(rows);
Expand Down Expand Up @@ -1906,6 +1909,10 @@ main(int argc, /* I - Number of command-line arguments */

if (fd != 0)
close(fd);

for (int i = 0; i < 7; i++)
if (DotBuffers[i] != NULL)
free(DotBuffers[i]);

return (page == 0);
}
Expand Down
2 changes: 2 additions & 0 deletions filter/rastertops.c
Expand Up @@ -282,6 +282,8 @@ write_flate(cups_raster_t *ras, /* I - Image data */
if (fwrite(out, 1, have, stdout) != have)
{
(void)deflateEnd(&strm);
if (convertedpix != NULL)
free(convertedpix);
return Z_ERRNO;
}
} while (strm.avail_out == 0);
Expand Down
11 changes: 10 additions & 1 deletion filter/sys5ippprinter.c
Expand Up @@ -570,6 +570,8 @@ exec_filter(const char *filter, /* I - Filter to execute */
dup2(fd, 2);
close(fd);
}
else
close(fd);
fcntl(2, F_SETFL, O_NDELAY);
}

Expand All @@ -578,13 +580,17 @@ exec_filter(const char *filter, /* I - Filter to execute */
dup2(fd, 3);
close(fd);
}
else
close(fd);
fcntl(3, F_SETFL, O_NDELAY);

if ((fd = open("/dev/null", O_RDWR)) > 4)
{
dup2(fd, 4);
close(fd);
}
else
close(fd);
fcntl(4, F_SETFL, O_NDELAY);

/*
Expand Down Expand Up @@ -654,8 +660,11 @@ exec_filters(cups_array_t *filters, /* I - Array of filters to run */
{
next = (char *)cupsArrayNext(filters);

if (filter[0] == '/')
if (filter[0] == '/') {
strncpy(program, filter, sizeof(program));
if (strlen(filter) > 1023)
program[1023] = '\0';
}
else
{
if ((cups_serverbin = getenv("CUPS_SERVERBIN")) == NULL)
Expand Down

0 comments on commit fc6a67d

Please sign in to comment.