head 1.3; access; symbols pkgsrc-2013Q2:1.3.0.10 pkgsrc-2013Q2-base:1.3 pkgsrc-2012Q4:1.3.0.8 pkgsrc-2012Q4-base:1.3 pkgsrc-2011Q4:1.3.0.6 pkgsrc-2011Q4-base:1.3 pkgsrc-2011Q2:1.3.0.4 pkgsrc-2011Q2-base:1.3 pkgsrc-2009Q4:1.3.0.2 pkgsrc-2009Q4-base:1.3 pkgsrc-2009Q3:1.2.0.40 pkgsrc-2009Q3-base:1.2 pkgsrc-2009Q2:1.2.0.38 pkgsrc-2009Q2-base:1.2 pkgsrc-2009Q1:1.2.0.36 pkgsrc-2009Q1-base:1.2 pkgsrc-2008Q4:1.2.0.34 pkgsrc-2008Q4-base:1.2 pkgsrc-2008Q3:1.2.0.32 pkgsrc-2008Q3-base:1.2 cube-native-xorg:1.2.0.30 cube-native-xorg-base:1.2 pkgsrc-2008Q2:1.2.0.28 pkgsrc-2008Q2-base:1.2 cwrapper:1.2.0.26 pkgsrc-2008Q1:1.2.0.24 pkgsrc-2008Q1-base:1.2 pkgsrc-2007Q4:1.2.0.22 pkgsrc-2007Q4-base:1.2 pkgsrc-2007Q3:1.2.0.20 pkgsrc-2007Q3-base:1.2 pkgsrc-2007Q2:1.2.0.18 pkgsrc-2007Q2-base:1.2 pkgsrc-2007Q1:1.2.0.16 pkgsrc-2007Q1-base:1.2 pkgsrc-2006Q4:1.2.0.14 pkgsrc-2006Q4-base:1.2 pkgsrc-2006Q3:1.2.0.12 pkgsrc-2006Q3-base:1.2 pkgsrc-2006Q2:1.2.0.10 pkgsrc-2006Q2-base:1.2 pkgsrc-2006Q1:1.2.0.8 pkgsrc-2006Q1-base:1.2 pkgsrc-2005Q4:1.2.0.6 pkgsrc-2005Q4-base:1.2 pkgsrc-2005Q3:1.2.0.4 pkgsrc-2005Q3-base:1.2 pkgsrc-2005Q2:1.2.0.2 pkgsrc-2005Q2-base:1.2 pkgsrc-2005Q1:1.1.0.6 pkgsrc-2005Q1-base:1.1 pkgsrc-2004Q4:1.1.0.4 pkgsrc-2004Q4-base:1.1 pkgsrc-2004Q3:1.1.0.2 pkgsrc-2004Q3-base:1.1; locks; strict; comment @# @; 1.3 date 2009.12.16.20.07.32; author joerg; state dead; branches; next 1.2; 1.2 date 2005.06.14.18.10.37; author jlam; state Exp; branches; next 1.1; 1.1 date 2004.09.16.15.09.01; author minskim; state Exp; branches; next ; desc @@ 1.3 log @Retire old xpm package. Replaced by x11/libXpm. @ text @$NetBSD: patch-aj,v 1.2 2005/06/14 18:10:37 jlam Exp $ --- lib/parse.c.orig 1998-03-19 14:51:00.000000000 -0500 +++ lib/parse.c @@@@ -38,8 +38,29 @@@@ * HeDu (hedu@@cul-ipn.uni-kiel.de) 4/94 */ +/* October 2004, source code review by Thomas Biege */ + #include "XpmI.h" #include +#include + +#ifdef HAS_STRLCAT +# define STRLCAT(dst, src, dstsize) do { \ + if (strlcat(dst, src, dstsize) >= (dstsize)) \ + return (XpmFileInvalid); } while(0) +# define STRLCPY(dst, src, dstsize) do { \ + if (strlcpy(dst, src, dstsize) >= (dstsize)) \ + return (XpmFileInvalid); } while(0) +#else +# define STRLCAT(dst, src, dstsize) do { \ + if ((strlen(dst) + strlen(src)) < (dstsize)) \ + strcat(dst, src); \ + else return (XpmFileInvalid); } while(0) +# define STRLCPY(dst, src, dstsize) do { \ + if (strlen(src) < (dstsize)) \ + strcpy(dst, src); \ + else return (XpmFileInvalid); } while(0) +#endif LFUNC(ParsePixels, int, (xpmData *data, unsigned int width, unsigned int height, unsigned int ncolors, @@@@ -63,7 +84,7 @@@@ xpmParseValues(data, width, height, ncol unsigned int *extensions; { unsigned int l; - char buf[BUFSIZ]; + char buf[BUFSIZ + 1]; if (!data->format) { /* XPM 2 or 3 */ @@@@ -172,10 +193,10 @@@@ xpmParseColors(data, ncolors, cpp, color XpmColor **colorTablePtr; xpmHashTable *hashtable; { - unsigned int key, l, a, b; + unsigned int key = 0, l, a, b, len; unsigned int curkey; /* current color key */ unsigned int lastwaskey; /* key read */ - char buf[BUFSIZ]; + char buf[BUFSIZ+1]; char curbuf[BUFSIZ]; /* current buffer */ char **sptr, *s; XpmColor *color; @@@@ -183,6 +204,8 @@@@ xpmParseColors(data, ncolors, cpp, color char **defaults; int ErrorStatus; + if (ncolors >= UINT_MAX / sizeof(XpmColor)) + return (XpmNoMemory); colorTable = (XpmColor *) XpmCalloc(ncolors, sizeof(XpmColor)); if (!colorTable) return (XpmNoMemory); @@@@ -194,6 +217,10 @@@@ xpmParseColors(data, ncolors, cpp, color /* * read pixel value */ + if (cpp >= UINT_MAX - 1) { + xpmFreeColorTable(colorTable, ncolors); + return (XpmNoMemory); + } color->string = (char *) XpmMalloc(cpp + 1); if (!color->string) { xpmFreeColorTable(colorTable, ncolors); @@@@ -231,13 +258,14 @@@@ xpmParseColors(data, ncolors, cpp, color } if (!lastwaskey && key < NKEYS) { /* open new key */ if (curkey) { /* flush string */ - s = (char *) XpmMalloc(strlen(curbuf) + 1); + len = strlen(curbuf) + 1; + s = (char *) XpmMalloc(len); if (!s) { xpmFreeColorTable(colorTable, ncolors); return (XpmNoMemory); } defaults[curkey] = s; - strcpy(s, curbuf); + memcpy(s, curbuf, len); } curkey = key + 1; /* set new key */ *curbuf = '\0'; /* reset curbuf */ @@@@ -248,9 +276,9 @@@@ xpmParseColors(data, ncolors, cpp, color return (XpmFileInvalid); } if (!lastwaskey) - strcat(curbuf, " "); /* append space */ + STRLCAT(curbuf, " ", sizeof(curbuf)); /* append space */ buf[l] = '\0'; - strcat(curbuf, buf);/* append buf */ + STRLCAT(curbuf, buf, sizeof(curbuf));/* append buf */ lastwaskey = 0; } } @@@@ -258,12 +286,13 @@@@ xpmParseColors(data, ncolors, cpp, color xpmFreeColorTable(colorTable, ncolors); return (XpmFileInvalid); } - s = defaults[curkey] = (char *) XpmMalloc(strlen(curbuf) + 1); + len = strlen(curbuf) + 1; + s = defaults[curkey] = (char *) XpmMalloc(len); if (!s) { xpmFreeColorTable(colorTable, ncolors); return (XpmNoMemory); } - strcpy(s, curbuf); + memcpy(s, curbuf, len); } } else { /* XPM 1 */ /* get to the beginning of the first string */ @@@@ -276,6 +305,10 @@@@ xpmParseColors(data, ncolors, cpp, color /* * read pixel value */ + if (cpp >= UINT_MAX - 1) { + xpmFreeColorTable(colorTable, ncolors); + return (XpmNoMemory); + } color->string = (char *) XpmMalloc(cpp + 1); if (!color->string) { xpmFreeColorTable(colorTable, ncolors); @@@@ -304,19 +337,20 @@@@ xpmParseColors(data, ncolors, cpp, color *curbuf = '\0'; /* init curbuf */ while (l = xpmNextWord(data, buf, BUFSIZ)) { if (*curbuf != '\0') - strcat(curbuf, " ");/* append space */ + STRLCAT(curbuf, " ", sizeof(curbuf));/* append space */ buf[l] = '\0'; - strcat(curbuf, buf); /* append buf */ + STRLCAT(curbuf, buf, sizeof(curbuf)); /* append buf */ } - s = (char *) XpmMalloc(strlen(curbuf) + 1); + len = strlen(curbuf) + 1; + s = (char *) XpmMalloc(len); if (!s) { xpmFreeColorTable(colorTable, ncolors); return (XpmNoMemory); } - strcpy(s, curbuf); + memcpy(s, curbuf, len); color->c_color = s; *curbuf = '\0'; /* reset curbuf */ - if (a < ncolors - 1) + if (a < ncolors - 1) /* can we trust ncolors -> leave data's bounds */ xpmNextString(data); /* get to the next string */ } } @@@@ -335,9 +369,12 @@@@ ParsePixels(data, width, height, ncolors xpmHashTable *hashtable; unsigned int **pixels; { - unsigned int *iptr, *iptr2; + unsigned int *iptr, *iptr2 = NULL; /* found by Egbert Eich */ unsigned int a, x, y; + if ((height > 0 && width >= UINT_MAX / height) || + width * height >= UINT_MAX / sizeof(unsigned int)) + return XpmNoMemory; #ifndef FOR_MSW iptr2 = (unsigned int *) XpmMalloc(sizeof(unsigned int) * width * height); #else @@@@ -361,6 +398,11 @@@@ ParsePixels(data, width, height, ncolors { unsigned short colidx[256]; + if (ncolors > 256) { + XpmFree(iptr2); /* found by Egbert Eich */ + return (XpmFileInvalid); + } + bzero((char *)colidx, 256 * sizeof(short)); for (a = 0; a < ncolors; a++) colidx[(unsigned char)colorTable[a].string[0]] = a + 1; @@@@ -386,16 +428,20 @@@@ ParsePixels(data, width, height, ncolors { /* free all allocated pointers at all exits */ -#define FREE_CIDX {int f; for (f = 0; f < 256; f++) \ -if (cidx[f]) XpmFree(cidx[f]);} +#define FREE_CIDX \ +do \ +{ \ + int f; for (f = 0; f < 256; f++) \ + if (cidx[f]) XpmFree(cidx[f]); \ +} while(0) /* array of pointers malloced by need */ unsigned short *cidx[256]; - int char1; + unsigned int char1; bzero((char *)cidx, 256 * sizeof(unsigned short *)); /* init */ for (a = 0; a < ncolors; a++) { - char1 = colorTable[a].string[0]; + char1 = (unsigned char) colorTable[a].string[0]; if (cidx[char1] == NULL) { /* get new memory */ cidx[char1] = (unsigned short *) XpmCalloc(256, sizeof(unsigned short)); @@@@ -439,6 +485,11 @@@@ if (cidx[f]) XpmFree(cidx[f]);} char *s; char buf[BUFSIZ]; + if (cpp >= sizeof(buf)) { + XpmFree(iptr2); /* found by Egbert Eich */ + return (XpmFileInvalid); + } + buf[cpp] = '\0'; if (USE_HASHTABLE) { xpmHashAtom *slot; @@@@ -447,7 +498,7 @@@@ if (cidx[f]) XpmFree(cidx[f]);} xpmNextString(data); for (x = 0; x < width; x++, iptr++) { for (a = 0, s = buf; a < cpp; a++, s++) - *s = xpmGetC(data); + *s = xpmGetC(data); /* int assigned to char, not a problem here */ slot = xpmHashSlot(hashtable, buf); if (!*slot) { /* no color matches */ XpmFree(iptr2); @@@@ -461,7 +512,7 @@@@ if (cidx[f]) XpmFree(cidx[f]);} xpmNextString(data); for (x = 0; x < width; x++, iptr++) { for (a = 0, s = buf; a < cpp; a++, s++) - *s = xpmGetC(data); + *s = xpmGetC(data); /* int assigned to char, not a problem here */ for (a = 0; a < ncolors; a++) if (!strcmp(colorTable[a].string, buf)) break; @@@@ -516,7 +567,7 @@@@ xpmParseExtensions(data, extensions, nex while (!notstart && notend) { /* there starts an extension */ ext = (XpmExtension *) - XpmRealloc(exts, (num + 1) * sizeof(XpmExtension)); + XpmRealloc(exts, (num + 1) * sizeof(XpmExtension)); /* can the loop be forced to iterate often enough to make "(num + 1) * sizeof(XpmExtension)" wrapping? */ if (!ext) { XpmFree(string); XpmFreeExtensions(exts, num); @@@@ -553,7 +604,7 @@@@ xpmParseExtensions(data, extensions, nex while ((notstart = strncmp("XPMEXT", string, 6)) && (notend = strncmp("XPMENDEXT", string, 9))) { sp = (char **) - XpmRealloc(ext->lines, (nlines + 1) * sizeof(char *)); + XpmRealloc(ext->lines, (nlines + 1) * sizeof(char *)); /* can we iterate enough for a wrapping? */ if (!sp) { XpmFree(string); ext->nlines = nlines; @@@@ -593,9 +644,9 @@@@ xpmParseExtensions(data, extensions, nex /* function call in case of error */ #undef RETURN #define RETURN(status) \ -{ \ +do { \ goto error; \ -} +} while(0) /* * This function parses an Xpm file or data and store the found informations @ 1.2 log @Apply fixes derived from the HEAD branch of X.Org (6.8.99) to address problems noted in CAN-2004-0914: Multiple vulnerabilities in libXpm for 6.8.1 and earlier, as used in XFree86 and other packages, include (1) multiple integer overflows, (2) out-of-bounds memory accesses, (3) directory traversal, (4) shell metacharacter, (5) endless loops, and (6) memory leaks, which could allow remote attackers to obtain sensitive information, cause a denial of service (application crash), or execute arbitary code via a certain XPM image file. Bump PKGREVISION to 4. Since this is a security-related fix, also bump the BUILDLINK_RECOMMENDED version for this package. @ text @d1 1 a1 1 $NetBSD$ @ 1.1 log @Incorporate security fixes of X.Org X11R6.8.1. Bump PKGREVISION. @ text @d3 1 a3 1 --- lib/parse.c.orig Thu Mar 19 13:51:00 1998 d5 6 a10 1 @@@@ -41,6 +41,24 @@@@ d13 2 a14 1 d16 6 a21 6 +# define STRLCAT(dst, src, dstsize) { \ + if (strlcat(dst, src, dstsize) >= (dstsize)) \ + return (XpmFileInvalid); } +# define STRLCPY(dst, src, dstsize) { \ + if (strlcpy(dst, src, dstsize) >= (dstsize)) \ + return (XpmFileInvalid); } d23 1 a23 1 +# define STRLCAT(dst, src, dstsize) { \ d25 3 a27 3 + strcat(dst, src); \ + else return (XpmFileInvalid); } +# define STRLCPY(dst, src, dstsize) { \ d29 2 a30 2 + strcpy(dst, src); \ + else return (XpmFileInvalid); } d32 1 a32 1 + d35 1 a35 2 unsigned int cpp, XpmColor *colorTable, @@@@ -63,7 +81,7 @@@@ xpmParseValues(data, width, height, ncol d44 1 a44 1 @@@@ -172,10 +190,10 @@@@ xpmParseColors(data, ncolors, cpp, color d49 1 a49 1 + unsigned int key, l, a, b, len; d57 1 a57 1 @@@@ -183,6 +201,8 @@@@ xpmParseColors(data, ncolors, cpp, color d61 1 a61 1 + if (ncolors >= SIZE_MAX / sizeof(XpmColor)) d66 1 a66 1 @@@@ -194,6 +214,10 @@@@ xpmParseColors(data, ncolors, cpp, color d70 1 a70 1 + if (cpp >= SIZE_MAX - 1) { d77 1 a77 1 @@@@ -231,13 +255,14 @@@@ xpmParseColors(data, ncolors, cpp, color d94 1 a94 1 @@@@ -248,9 +273,9 @@@@ xpmParseColors(data, ncolors, cpp, color d106 1 a106 1 @@@@ -258,12 +283,13 @@@@ xpmParseColors(data, ncolors, cpp, color d122 1 a122 1 @@@@ -276,6 +302,10 @@@@ xpmParseColors(data, ncolors, cpp, color d126 1 a126 1 + if (cpp >= SIZE_MAX - 1) { d133 1 a133 1 @@@@ -304,16 +334,17 @@@@ xpmParseColors(data, ncolors, cpp, color d141 1 a141 1 + STRLCAT(curbuf, buf, sizeof(curbuf)); /* append buf */ d154 11 a164 3 if (a < ncolors - 1) @@@@ -338,6 +369,9 @@@@ ParsePixels(data, width, height, ncolors unsigned int *iptr, *iptr2; d167 2 a168 2 + if ((height > 0 && width >= SIZE_MAX / height) || + width * height >= SIZE_MAX / sizeof(unsigned int)) d173 1 a173 1 @@@@ -361,6 +395,9 @@@@ ParsePixels(data, width, height, ncolors d177 2 a178 1 + if (ncolors > 256) d180 1 d185 1 a185 1 @@@@ -438,6 +475,9 @@@@ if (cidx[f]) XpmFree(cidx[f]);} d187 24 d213 5 a218 3 + if (cpp >= sizeof(buf)) + return (XpmFileInvalid); d221 49 @