Lines 42-47
Link Here
|
42 |
#include "XpmI.h" |
42 |
#include "XpmI.h" |
43 |
#include <ctype.h> |
43 |
#include <ctype.h> |
44 |
|
44 |
|
|
|
45 |
#ifdef HAS_STRLCAT |
46 |
# define STRLCAT(dst, src, dstsize) { \ |
47 |
if (strlcat(dst, src, dstsize) >= (dstsize)) \ |
48 |
return (XpmFileInvalid); } |
49 |
# define STRLCPY(dst, src, dstsize) { \ |
50 |
if (strlcpy(dst, src, dstsize) >= (dstsize)) \ |
51 |
return (XpmFileInvalid); } |
52 |
#else |
53 |
# define STRLCAT(dst, src, dstsize) { \ |
54 |
if ((strlen(dst) + strlen(src)) < (dstsize)) \ |
55 |
strcat(dst, src); \ |
56 |
else return (XpmFileInvalid); } |
57 |
# define STRLCPY(dst, src, dstsize) { \ |
58 |
if (strlen(src) < (dstsize)) \ |
59 |
strcpy(dst, src); \ |
60 |
else return (XpmFileInvalid); } |
61 |
#endif |
62 |
|
45 |
LFUNC(ParsePixels, int, (xpmData *data, unsigned int width, |
63 |
LFUNC(ParsePixels, int, (xpmData *data, unsigned int width, |
46 |
unsigned int height, unsigned int ncolors, |
64 |
unsigned int height, unsigned int ncolors, |
47 |
unsigned int cpp, XpmColor *colorTable, |
65 |
unsigned int cpp, XpmColor *colorTable, |
Lines 209-215
Link Here
|
209 |
unsigned int *extensions; |
227 |
unsigned int *extensions; |
210 |
{ |
228 |
{ |
211 |
unsigned int l; |
229 |
unsigned int l; |
212 |
char buf[BUFSIZ]; |
230 |
char buf[BUFSIZ + 1]; |
213 |
|
231 |
|
214 |
if (!data->format) { /* XPM 2 or 3 */ |
232 |
if (!data->format) { /* XPM 2 or 3 */ |
215 |
|
233 |
|
Lines 318-327
Link Here
|
318 |
XpmColor **colorTablePtr; |
336 |
XpmColor **colorTablePtr; |
319 |
xpmHashTable *hashtable; |
337 |
xpmHashTable *hashtable; |
320 |
{ |
338 |
{ |
321 |
unsigned int key, l, a, b; |
339 |
unsigned int key = 0, l, a, b, len; |
322 |
unsigned int curkey; /* current color key */ |
340 |
unsigned int curkey; /* current color key */ |
323 |
unsigned int lastwaskey; /* key read */ |
341 |
unsigned int lastwaskey; /* key read */ |
324 |
char buf[BUFSIZ]; |
342 |
char buf[BUFSIZ+1]; |
325 |
char curbuf[BUFSIZ]; /* current buffer */ |
343 |
char curbuf[BUFSIZ]; /* current buffer */ |
326 |
char **sptr, *s; |
344 |
char **sptr, *s; |
327 |
XpmColor *color; |
345 |
XpmColor *color; |
Lines 329-334
Link Here
|
329 |
char **defaults; |
347 |
char **defaults; |
330 |
int ErrorStatus; |
348 |
int ErrorStatus; |
331 |
|
349 |
|
|
|
350 |
if (ncolors >= SIZE_MAX / sizeof(XpmColor)) |
351 |
return (XpmNoMemory); |
332 |
colorTable = (XpmColor *) XpmCalloc(ncolors, sizeof(XpmColor)); |
352 |
colorTable = (XpmColor *) XpmCalloc(ncolors, sizeof(XpmColor)); |
333 |
if (!colorTable) |
353 |
if (!colorTable) |
334 |
return (XpmNoMemory); |
354 |
return (XpmNoMemory); |
Lines 340-345
Link Here
|
340 |
/* |
360 |
/* |
341 |
* read pixel value |
361 |
* read pixel value |
342 |
*/ |
362 |
*/ |
|
|
363 |
if (cpp >= SIZE_MAX - 1) { |
364 |
xpmFreeColorTable(colorTable, ncolors); |
365 |
return (XpmNoMemory); |
366 |
} |
343 |
color->string = (char *) XpmMalloc(cpp + 1); |
367 |
color->string = (char *) XpmMalloc(cpp + 1); |
344 |
if (!color->string) { |
368 |
if (!color->string) { |
345 |
xpmFreeColorTable(colorTable, ncolors); |
369 |
xpmFreeColorTable(colorTable, ncolors); |
Lines 377-389
Link Here
|
377 |
} |
401 |
} |
378 |
if (!lastwaskey && key < NKEYS) { /* open new key */ |
402 |
if (!lastwaskey && key < NKEYS) { /* open new key */ |
379 |
if (curkey) { /* flush string */ |
403 |
if (curkey) { /* flush string */ |
380 |
s = (char *) XpmMalloc(strlen(curbuf) + 1); |
404 |
len = strlen(curbuf) + 1; |
|
|
405 |
s = (char *) XpmMalloc(len); |
381 |
if (!s) { |
406 |
if (!s) { |
382 |
xpmFreeColorTable(colorTable, ncolors); |
407 |
xpmFreeColorTable(colorTable, ncolors); |
383 |
return (XpmNoMemory); |
408 |
return (XpmNoMemory); |
384 |
} |
409 |
} |
385 |
defaults[curkey] = s; |
410 |
defaults[curkey] = s; |
386 |
strcpy(s, curbuf); |
411 |
memcpy(s, curbuf, len); |
387 |
} |
412 |
} |
388 |
curkey = key + 1; /* set new key */ |
413 |
curkey = key + 1; /* set new key */ |
389 |
*curbuf = '\0'; /* reset curbuf */ |
414 |
*curbuf = '\0'; /* reset curbuf */ |
Lines 394-402
Link Here
|
394 |
return (XpmFileInvalid); |
419 |
return (XpmFileInvalid); |
395 |
} |
420 |
} |
396 |
if (!lastwaskey) |
421 |
if (!lastwaskey) |
397 |
strcat(curbuf, " "); /* append space */ |
422 |
STRLCAT(curbuf, " ", sizeof(curbuf)); /* append space */ |
398 |
buf[l] = '\0'; |
423 |
buf[l] = '\0'; |
399 |
strcat(curbuf, buf);/* append buf */ |
424 |
STRLCAT(curbuf, buf, sizeof(curbuf));/* append buf */ |
400 |
lastwaskey = 0; |
425 |
lastwaskey = 0; |
401 |
} |
426 |
} |
402 |
} |
427 |
} |
Lines 404-415
Link Here
|
404 |
xpmFreeColorTable(colorTable, ncolors); |
429 |
xpmFreeColorTable(colorTable, ncolors); |
405 |
return (XpmFileInvalid); |
430 |
return (XpmFileInvalid); |
406 |
} |
431 |
} |
407 |
s = defaults[curkey] = (char *) XpmMalloc(strlen(curbuf) + 1); |
432 |
len = strlen(curbuf) + 1; |
|
|
433 |
s = defaults[curkey] = (char *) XpmMalloc(len); |
408 |
if (!s) { |
434 |
if (!s) { |
409 |
xpmFreeColorTable(colorTable, ncolors); |
435 |
xpmFreeColorTable(colorTable, ncolors); |
410 |
return (XpmNoMemory); |
436 |
return (XpmNoMemory); |
411 |
} |
437 |
} |
412 |
strcpy(s, curbuf); |
438 |
memcpy(s, curbuf, len); |
413 |
} |
439 |
} |
414 |
} else { /* XPM 1 */ |
440 |
} else { /* XPM 1 */ |
415 |
/* get to the beginning of the first string */ |
441 |
/* get to the beginning of the first string */ |
Lines 422-427
Link Here
|
422 |
/* |
448 |
/* |
423 |
* read pixel value |
449 |
* read pixel value |
424 |
*/ |
450 |
*/ |
|
|
451 |
if (cpp >= SIZE_MAX - 1) { |
452 |
xpmFreeColorTable(colorTable, ncolors); |
453 |
return (XpmNoMemory); |
454 |
} |
425 |
color->string = (char *) XpmMalloc(cpp + 1); |
455 |
color->string = (char *) XpmMalloc(cpp + 1); |
426 |
if (!color->string) { |
456 |
if (!color->string) { |
427 |
xpmFreeColorTable(colorTable, ncolors); |
457 |
xpmFreeColorTable(colorTable, ncolors); |
Lines 450-465
Link Here
|
450 |
*curbuf = '\0'; /* init curbuf */ |
480 |
*curbuf = '\0'; /* init curbuf */ |
451 |
while (l = xpmNextWord(data, buf, BUFSIZ)) { |
481 |
while (l = xpmNextWord(data, buf, BUFSIZ)) { |
452 |
if (*curbuf != '\0') |
482 |
if (*curbuf != '\0') |
453 |
strcat(curbuf, " ");/* append space */ |
483 |
STRLCAT(curbuf, " ", sizeof(curbuf));/* append space */ |
454 |
buf[l] = '\0'; |
484 |
buf[l] = '\0'; |
455 |
strcat(curbuf, buf); /* append buf */ |
485 |
STRLCAT(curbuf, buf, sizeof(curbuf)); /* append buf */ |
456 |
} |
486 |
} |
457 |
s = (char *) XpmMalloc(strlen(curbuf) + 1); |
487 |
len = strlen(curbuf) + 1; |
|
|
488 |
s = (char *) XpmMalloc(len); |
458 |
if (!s) { |
489 |
if (!s) { |
459 |
xpmFreeColorTable(colorTable, ncolors); |
490 |
xpmFreeColorTable(colorTable, ncolors); |
460 |
return (XpmNoMemory); |
491 |
return (XpmNoMemory); |
461 |
} |
492 |
} |
462 |
strcpy(s, curbuf); |
493 |
memcpy(s, curbuf, len); |
463 |
color->c_color = s; |
494 |
color->c_color = s; |
464 |
*curbuf = '\0'; /* reset curbuf */ |
495 |
*curbuf = '\0'; /* reset curbuf */ |
465 |
if (a < ncolors - 1) |
496 |
if (a < ncolors - 1) |
Lines 484-489
Link Here
|
484 |
unsigned int *iptr, *iptr2; |
515 |
unsigned int *iptr, *iptr2; |
485 |
unsigned int a, x, y; |
516 |
unsigned int a, x, y; |
486 |
|
517 |
|
|
|
518 |
if ((height > 0 && width >= SIZE_MAX / height) || |
519 |
width * height >= SIZE_MAX / sizeof(unsigned int)) |
520 |
return XpmNoMemory; |
487 |
#ifndef FOR_MSW |
521 |
#ifndef FOR_MSW |
488 |
iptr2 = (unsigned int *) XpmMalloc(sizeof(unsigned int) * width * height); |
522 |
iptr2 = (unsigned int *) XpmMalloc(sizeof(unsigned int) * width * height); |
489 |
#else |
523 |
#else |
Lines 507-512
Link Here
|
507 |
{ |
541 |
{ |
508 |
unsigned short colidx[256]; |
542 |
unsigned short colidx[256]; |
509 |
|
543 |
|
|
|
544 |
if (ncolors > 256) |
545 |
return (XpmFileInvalid); |
546 |
|
510 |
bzero((char *)colidx, 256 * sizeof(short)); |
547 |
bzero((char *)colidx, 256 * sizeof(short)); |
511 |
for (a = 0; a < ncolors; a++) |
548 |
for (a = 0; a < ncolors; a++) |
512 |
colidx[(unsigned char)colorTable[a].string[0]] = a + 1; |
549 |
colidx[(unsigned char)colorTable[a].string[0]] = a + 1; |
Lines 584-589
Link Here
|
584 |
char *s; |
621 |
char *s; |
585 |
char buf[BUFSIZ]; |
622 |
char buf[BUFSIZ]; |
586 |
|
623 |
|
|
|
624 |
if (cpp >= sizeof(buf)) |
625 |
return (XpmFileInvalid); |
626 |
|
587 |
buf[cpp] = '\0'; |
627 |
buf[cpp] = '\0'; |
588 |
if (USE_HASHTABLE) { |
628 |
if (USE_HASHTABLE) { |
589 |
xpmHashAtom *slot; |
629 |
xpmHashAtom *slot; |