Switching to strncpy, fixing potential buffer overflow in palette as well

This commit is contained in:
wiredfool 2013-03-14 16:47:40 -07:00
parent 66965b6bb4
commit b5335c0cf3
3 changed files with 3 additions and 3 deletions

View File

@ -41,7 +41,7 @@ ImagingHistogramNew(Imaging im)
/* Create histogram descriptor */ /* Create histogram descriptor */
h = calloc(1, sizeof(struct ImagingHistogramInstance)); h = calloc(1, sizeof(struct ImagingHistogramInstance));
strcpy(h->mode, im->mode); strncpy(h->mode, im->mode, IMAGING_MODE_LENGTH);
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

@ -141,7 +141,7 @@ struct ImagingHistogramInstance {
struct ImagingPaletteInstance { struct ImagingPaletteInstance {
/* Format */ /* Format */
char mode[4+1]; /* Band names */ char mode[IMAGING_MODE_LENGTH]; /* Band names */
/* Data */ /* Data */
UINT8 palette[1024];/* Palette data (same format as image data) */ UINT8 palette[1024];/* Palette data (same format as image data) */

View File

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