Fix potential un-terminated buffer problem (CWE-120)

This commit is contained in:
Lumir Balhar 2018-09-11 15:58:31 +02:00
parent 3437d5fcb4
commit 2e288e74ab
2 changed files with 5 additions and 2 deletions

View File

@ -41,7 +41,9 @@ ImagingHistogramNew(Imaging im)
/* Create histogram descriptor */ /* Create histogram descriptor */
h = calloc(1, sizeof(struct ImagingHistogramInstance)); h = calloc(1, sizeof(struct ImagingHistogramInstance));
strncpy(h->mode, im->mode, IMAGING_MODE_LENGTH); strncpy(h->mode, im->mode, IMAGING_MODE_LENGTH-1);
h->mode[IMAGING_MODE_LENGTH-1] = 0;
h->bands = im->bands; h->bands = im->bands;
h->histogram = calloc(im->pixelsize, 256 * sizeof(long)); h->histogram = calloc(im->pixelsize, 256 * sizeof(long));

View File

@ -37,7 +37,8 @@ ImagingPaletteNew(const char* mode)
if (!palette) if (!palette)
return (ImagingPalette) ImagingError_MemoryError(); return (ImagingPalette) ImagingError_MemoryError();
strncpy(palette->mode, mode, IMAGING_MODE_LENGTH); strncpy(palette->mode, mode, IMAGING_MODE_LENGTH-1);
palette->mode[IMAGING_MODE_LENGTH-1] = 0;
/* Initialize to ramp */ /* Initialize to ramp */
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {