Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 68544 | Differences between
and this patch

Collapse All | Expand All

(-)xc/extras/Xpm/lib/Attrib.c (-5 / +7 lines)
Lines 32-44 Link Here
32
*  Developed by Arnaud Le Hors                                                *
32
*  Developed by Arnaud Le Hors                                                *
33
\*****************************************************************************/
33
\*****************************************************************************/
34
34
35
/* October 2004, source code review by Thomas Biege <thomas@suse.de> */
36
35
#include "XpmI.h"
37
#include "XpmI.h"
36
38
37
/* 3.2 backward compatibility code */
39
/* 3.2 backward compatibility code */
38
LFUNC(CreateOldColorTable, int, (XpmColor *ct, unsigned int ncolors,
40
LFUNC(CreateOldColorTable, int, (XpmColor *ct, unsigned int ncolors,
39
				 XpmColor ***oldct));
41
				 XpmColor ***oldct));
40
42
41
LFUNC(FreeOldColorTable, void, (XpmColor **colorTable, int ncolors));
43
LFUNC(FreeOldColorTable, void, (XpmColor **colorTable, unsigned int ncolors));
42
44
43
/*
45
/*
44
 * Create a colortable compatible with the old style colortable
46
 * Create a colortable compatible with the old style colortable
Lines 50-56 CreateOldColorTable(ct, ncolors, oldct) Link Here
50
    XpmColor ***oldct;
52
    XpmColor ***oldct;
51
{
53
{
52
    XpmColor **colorTable, **color;
54
    XpmColor **colorTable, **color;
53
    int a;
55
    unsigned int a;
54
56
55
    if (ncolors >= UINT_MAX / sizeof(XpmColor *)) 
57
    if (ncolors >= UINT_MAX / sizeof(XpmColor *)) 
56
	return XpmNoMemory;
58
	return XpmNoMemory;
Lines 69-77 CreateOldColorTable(ct, ncolors, oldct) Link Here
69
static void
71
static void
70
FreeOldColorTable(colorTable, ncolors)
72
FreeOldColorTable(colorTable, ncolors)
71
    XpmColor **colorTable;
73
    XpmColor **colorTable;
72
    int ncolors;
74
    unsigned int ncolors;
73
{
75
{
74
    int a, b;
76
    unsigned int a, b;
75
    XpmColor **color;
77
    XpmColor **color;
76
    char **sptr;
78
    char **sptr;
77
79
Lines 116-122 xpmFreeColorTable(colorTable, ncolors) Link Here
116
void
118
void
117
XpmFreeExtensions(extensions, nextensions)
119
XpmFreeExtensions(extensions, nextensions)
118
    XpmExtension *extensions;
120
    XpmExtension *extensions;
119
    int nextensions;
121
    unsigned int nextensions;
120
{
122
{
121
    unsigned int i, j, nlines;
123
    unsigned int i, j, nlines;
122
    XpmExtension *ext;
124
    XpmExtension *ext;
(-)xc/extras/Xpm/lib/CrBufFrI.c (-24 / +69 lines)
Lines 39-53 LFUNC(WriteColors, int, (char **dataptr, Link Here
39
			 unsigned int *used_size, XpmColor *colors,
42
			 unsigned int *used_size, XpmColor *colors,
40
			 unsigned int ncolors, unsigned int cpp));
43
			 unsigned int ncolors, unsigned int cpp));
41
44
42
LFUNC(WritePixels, void, (char *dataptr, unsigned int *used_size,
45
LFUNC(WritePixels, void, (char *dataptr, unsigned int data_size,
46
			  unsigned int *used_size,
43
			  unsigned int width, unsigned int height,
47
			  unsigned int width, unsigned int height,
44
			  unsigned int cpp, unsigned int *pixels,
48
			  unsigned int cpp, unsigned int *pixels,
45
			  XpmColor *colors));
49
			  XpmColor *colors));
46
50
47
LFUNC(WriteExtensions, void, (char *dataptr, unsigned int *used_size,
51
LFUNC(WriteExtensions, void, (char *dataptr, unsigned int data_size,
52
			      unsigned int *used_size,
48
			      XpmExtension *ext, unsigned int num));
53
			      XpmExtension *ext, unsigned int num));
49
54
50
LFUNC(ExtensionsSize, int, (XpmExtension *ext, unsigned int num));
55
LFUNC(ExtensionsSize, unsigned int, (XpmExtension *ext, unsigned int num));
51
LFUNC(CommentsSize, int, (XpmInfo *info));
56
LFUNC(CommentsSize, int, (XpmInfo *info));
52
57
53
int
58
int
Lines 90-99 XpmCreateBufferFromImage(display, buffer Link Here
90
95
91
#undef RETURN
96
#undef RETURN
92
#define RETURN(status) \
97
#define RETURN(status) \
98
do \
93
{ \
99
{ \
94
      ErrorStatus = status; \
100
      ErrorStatus = status; \
95
      goto error; \
101
      goto error; \
96
}
102
}while(0)
97
103
98
int
104
int
99
XpmCreateBufferFromXpmImage(buffer_return, image, info)
105
XpmCreateBufferFromXpmImage(buffer_return, image, info)
Lines 107-113 XpmCreateBufferFromXpmImage(buffer_retur Link Here
107
    unsigned int cmts, extensions, ext_size = 0;
113
    unsigned int cmts, extensions, ext_size = 0;
108
    unsigned int l, cmt_size = 0;
114
    unsigned int l, cmt_size = 0;
109
    char *ptr = NULL, *p;
115
    char *ptr = NULL, *p;
110
    unsigned int ptr_size, used_size;
116
    unsigned int ptr_size, used_size, tmp;
111
117
112
    *buffer_return = NULL;
118
    *buffer_return = NULL;
113
119
Lines 129-135 XpmCreateBufferFromXpmImage(buffer_retur Link Here
129
#ifdef VOID_SPRINTF
135
#ifdef VOID_SPRINTF
130
    used_size = strlen(buf);
136
    used_size = strlen(buf);
131
#endif
137
#endif
132
    ptr_size = used_size + ext_size + cmt_size + 1;
138
    ptr_size = used_size + ext_size + cmt_size + 1; /* ptr_size can't be 0 */
139
    if(ptr_size <= used_size ||
140
       ptr_size <= ext_size  ||
141
       ptr_size <= cmt_size)
142
    {
143
        return XpmNoMemory;
144
    }
133
    ptr = (char *) XpmMalloc(ptr_size);
145
    ptr = (char *) XpmMalloc(ptr_size);
134
    if (!ptr)
146
    if (!ptr)
135
	return XpmNoMemory;
147
	return XpmNoMemory;
Lines 140-146 XpmCreateBufferFromXpmImage(buffer_retur Link Here
140
#ifndef VOID_SPRINTF
152
#ifndef VOID_SPRINTF
141
	used_size +=
153
	used_size +=
142
#endif
154
#endif
143
	sprintf(ptr + used_size, "/*%s*/\n", info->hints_cmt);
155
	snprintf(ptr + used_size, ptr_size-used_size, "/*%s*/\n", info->hints_cmt);
144
#ifdef VOID_SPRINTF
156
#ifdef VOID_SPRINTF
145
	used_size += strlen(info->hints_cmt) + 5;
157
	used_size += strlen(info->hints_cmt) + 5;
146
#endif
158
#endif
Lines 158-164 XpmCreateBufferFromXpmImage(buffer_retur Link Here
158
#ifndef VOID_SPRINTF
170
#ifndef VOID_SPRINTF
159
	l +=
171
	l +=
160
#endif
172
#endif
161
	sprintf(buf + l, " %d %d", info->x_hotspot, info->y_hotspot);
173
	snprintf(buf + l, sizeof(buf)-l, " %d %d", info->x_hotspot, info->y_hotspot);
162
#ifdef VOID_SPRINTF
174
#ifdef VOID_SPRINTF
163
	l = strlen(buf);
175
	l = strlen(buf);
164
#endif
176
#endif
Lines 180-185 XpmCreateBufferFromXpmImage(buffer_retur Link Here
180
    l = strlen(buf);
192
    l = strlen(buf);
181
#endif
193
#endif
182
    ptr_size += l;
194
    ptr_size += l;
195
    if(ptr_size <= l)
196
        RETURN(XpmNoMemory);
183
    p = (char *) XpmRealloc(ptr, ptr_size);
197
    p = (char *) XpmRealloc(ptr, ptr_size);
184
    if (!p)
198
    if (!p)
185
	RETURN(XpmNoMemory);
199
	RETURN(XpmNoMemory);
Lines 192-198 XpmCreateBufferFromXpmImage(buffer_retur Link Here
192
#ifndef VOID_SPRINTF
206
#ifndef VOID_SPRINTF
193
	used_size +=
207
	used_size +=
194
#endif
208
#endif
195
	sprintf(ptr + used_size, "/*%s*/\n", info->colors_cmt);
209
	snprintf(ptr + used_size, ptr_size-used_size, "/*%s*/\n", info->colors_cmt);
196
#ifdef VOID_SPRINTF
210
#ifdef VOID_SPRINTF
197
	used_size += strlen(info->colors_cmt) + 5;
211
	used_size += strlen(info->colors_cmt) + 5;
198
#endif
212
#endif
Lines 208-214 XpmCreateBufferFromXpmImage(buffer_retur Link Here
208
     * 4 = 1 (for '"') + 3 (for '",\n')
222
     * 4 = 1 (for '"') + 3 (for '",\n')
209
     * 1 = - 2 (because the last line does not end with ',\n') + 3 (for '};\n')
223
     * 1 = - 2 (because the last line does not end with ',\n') + 3 (for '};\n')
210
     */
224
     */
211
    ptr_size += image->height * (image->width * image->cpp + 4) + 1;
225
     if(image->width  > UINT_MAX / image->cpp ||
226
       (tmp = image->width * image->cpp + 4) <= 4 ||
227
        image->height > UINT_MAX / tmp ||
228
       (tmp = image->height * tmp + 1) <= 1 ||
229
       (ptr_size += tmp) <= tmp)
230
	RETURN(XpmNoMemory);
212
231
213
    p = (char *) XpmRealloc(ptr, ptr_size);
232
    p = (char *) XpmRealloc(ptr, ptr_size);
214
    if (!p)
233
    if (!p)
Lines 220-236 XpmCreateBufferFromXpmImage(buffer_retur Link Here
220
#ifndef VOID_SPRINTF
239
#ifndef VOID_SPRINTF
221
	used_size +=
240
	used_size +=
222
#endif
241
#endif
223
	sprintf(ptr + used_size, "/*%s*/\n", info->pixels_cmt);
242
	snprintf(ptr + used_size, ptr_size-used_size, "/*%s*/\n", info->pixels_cmt);
224
#ifdef VOID_SPRINTF
243
#ifdef VOID_SPRINTF
225
	used_size += strlen(info->pixels_cmt) + 5;
244
	used_size += strlen(info->pixels_cmt) + 5;
226
#endif
245
#endif
227
    }
246
    }
228
    WritePixels(ptr + used_size, &used_size, image->width, image->height,
247
    WritePixels(ptr + used_size, ptr_size - used_size, &used_size, image->width, image->height,
229
		image->cpp, image->data, image->colorTable);
248
		image->cpp, image->data, image->colorTable);
230
249
231
    /* print extensions */
250
    /* print extensions */
232
    if (extensions)
251
    if (extensions)
233
	WriteExtensions(ptr + used_size, &used_size,
252
	WriteExtensions(ptr + used_size, ptr_size-used_size, &used_size,
234
			info->extensions, info->nextensions);
253
			info->extensions, info->nextensions);
235
254
236
    /* close the array */
255
    /* close the array */
Lines 247-252 error: Link Here
247
    return (ErrorStatus);
266
    return (ErrorStatus);
248
}
267
}
249
268
269
250
static int
270
static int
251
WriteColors(dataptr, data_size, used_size, colors, ncolors, cpp)
271
WriteColors(dataptr, data_size, used_size, colors, ncolors, cpp)
252
    char **dataptr;
272
    char **dataptr;
Lines 256-262 WriteColors(dataptr, data_size, used_siz Link Here
256
    unsigned int ncolors;
276
    unsigned int ncolors;
257
    unsigned int cpp;
277
    unsigned int cpp;
258
{
278
{
259
    char buf[BUFSIZ];
279
    char buf[BUFSIZ] = {0};
260
    unsigned int a, key, l;
280
    unsigned int a, key, l;
261
    char *s, *s2;
281
    char *s, *s2;
262
    char **defaults;
282
    char **defaults;
Lines 266-271 WriteColors(dataptr, data_size, used_siz Link Here
266
286
267
	defaults = (char **) colors;
287
	defaults = (char **) colors;
268
	s = buf + 1;
288
	s = buf + 1;
289
	if(cpp > (sizeof(buf) - (s-buf)))
290
		return(XpmNoMemory);
269
	strncpy(s, *defaults++, cpp);
291
	strncpy(s, *defaults++, cpp);
270
	s += cpp;
292
	s += cpp;
271
293
Lines 274-287 WriteColors(dataptr, data_size, used_siz Link Here
274
#ifndef VOID_SPRINTF
296
#ifndef VOID_SPRINTF
275
		s +=
297
		s +=
276
#endif
298
#endif
277
		sprintf(s, "\t%s %s", xpmColorKeys[key - 1], s2);
299
		/* assume C99 compliance */
300
		snprintf(s, sizeof(buf) - (s-buf), "\t%s %s", xpmColorKeys[key - 1], s2);
278
#ifdef VOID_SPRINTF
301
#ifdef VOID_SPRINTF
279
		s += strlen(s);
302
		s += strlen(s);
280
#endif
303
#endif
304
		/* now let's check if s points out-of-bounds */
305
		if((s-buf) > sizeof(buf))
306
			return(XpmNoMemory);
281
	    }
307
	    }
282
	}
308
	}
309
	if(sizeof(buf) - (s-buf) < 4)
310
		return(XpmNoMemory);
283
	strcpy(s, "\",\n");
311
	strcpy(s, "\",\n");
284
	l = s + 3 - buf;
312
	l = s + 3 - buf;
313
	if( *data_size                   >= UINT_MAX-l ||
314
	    *data_size + l               <= *used_size ||
315
	   (*data_size + l - *used_size) <= sizeof(buf))
316
		return(XpmNoMemory);
285
	s = (char *) XpmRealloc(*dataptr, *data_size + l);
317
	s = (char *) XpmRealloc(*dataptr, *data_size + l);
286
	if (!s)
318
	if (!s)
287
	    return (XpmNoMemory);
319
	    return (XpmNoMemory);
Lines 294-301 WriteColors(dataptr, data_size, used_siz Link Here
294
}
326
}
295
327
296
static void
328
static void
297
WritePixels(dataptr, used_size, width, height, cpp, pixels, colors)
329
WritePixels(dataptr, data_size, used_size, width, height, cpp, pixels, colors)
298
    char *dataptr;
330
    char *dataptr;
331
    unsigned int data_size;
299
    unsigned int *used_size;
332
    unsigned int *used_size;
300
    unsigned int width;
333
    unsigned int width;
301
    unsigned int height;
334
    unsigned int height;
Lines 306-332 WritePixels(dataptr, used_size, width, h Link Here
306
    char *s = dataptr;
339
    char *s = dataptr;
307
    unsigned int x, y, h;
340
    unsigned int x, y, h;
308
341
342
    if(height <= 1)
343
    	return;
344
309
    h = height - 1;
345
    h = height - 1;
310
    for (y = 0; y < h; y++) {
346
    for (y = 0; y < h; y++) {
311
	*s++ = '"';
347
	*s++ = '"';
312
	for (x = 0; x < width; x++, pixels++) {
348
	for (x = 0; x < width; x++, pixels++) {
313
	    strncpy(s, colors[*pixels].string, cpp);
349
	    if(cpp >= (data_size - (s-dataptr)))
350
		return;
351
	    strncpy(s, colors[*pixels].string, cpp); /* how can we trust *pixels? :-\ */
314
	    s += cpp;
352
	    s += cpp;
315
	}
353
	}
354
	if((data_size - (s-dataptr)) < 4)
355
		return;
316
	strcpy(s, "\",\n");
356
	strcpy(s, "\",\n");
317
	s += 3;
357
	s += 3;
318
    }
358
    }
319
    /* duplicate some code to avoid a test in the loop */
359
    /* duplicate some code to avoid a test in the loop */
320
    *s++ = '"';
360
    *s++ = '"';
321
    for (x = 0; x < width; x++, pixels++) {
361
    for (x = 0; x < width; x++, pixels++) {
322
	strncpy(s, colors[*pixels].string, cpp);
362
	if(cpp >= (data_size - (s-dataptr)))
363
	    return;
364
	strncpy(s, colors[*pixels].string, cpp); /* how can we trust *pixels? */
323
	s += cpp;
365
	s += cpp;
324
    }
366
    }
325
    *s++ = '"';
367
    *s++ = '"';
326
    *used_size += s - dataptr;
368
    *used_size += s - dataptr;
327
}
369
}
328
370
329
static int
371
static unsigned int
330
ExtensionsSize(ext, num)
372
ExtensionsSize(ext, num)
331
    XpmExtension *ext;
373
    XpmExtension *ext;
332
    unsigned int num;
374
    unsigned int num;
Lines 335-355 ExtensionsSize(ext, num) Link Here
335
    char **line;
377
    char **line;
336
378
337
    size = 0;
379
    size = 0;
380
    if(num == 0)
381
    	return(0); /* ok? */
338
    for (x = 0; x < num; x++, ext++) {
382
    for (x = 0; x < num; x++, ext++) {
339
	/* 11 = 10 (for ',\n"XPMEXT ') + 1 (for '"') */
383
	/* 11 = 10 (for ',\n"XPMEXT ') + 1 (for '"') */
340
	size += strlen(ext->name) + 11;
384
	size += strlen(ext->name) + 11;
341
	a = ext->nlines;
385
	a = ext->nlines; /* how can we trust ext->nlines to be not out-of-bounds? */
342
	for (y = 0, line = ext->lines; y < a; y++, line++)
386
	for (y = 0, line = ext->lines; y < a; y++, line++)
343
	    /* 4 = 3 (for ',\n"') + 1 (for '"') */
387
	    /* 4 = 3 (for ',\n"') + 1 (for '"') */
344
	    size += strlen(*line) + 4;
388
	    size += strlen(*line) + 4;
345
    }
389
    }
346
    /* 13 is for ',\n"XPMENDEXT"' */
390
    /* 13 is for ',\n"XPMENDEXT"' */
391
    if(size > UINT_MAX - 13) /* unlikely */
392
    	return(0);
347
    return size + 13;
393
    return size + 13;
348
}
394
}
349
395
350
static void
396
static void
351
WriteExtensions(dataptr, used_size, ext, num)
397
WriteExtensions(dataptr, data_size, used_size, ext, num)
352
    char *dataptr;
398
    char *dataptr;
399
    unsigned int data_size;
353
    unsigned int *used_size;
400
    unsigned int *used_size;
354
    XpmExtension *ext;
401
    XpmExtension *ext;
355
    unsigned int num;
402
    unsigned int num;
Lines 362-368 WriteExtensions(dataptr, used_size, ext, Link Here
362
#ifndef VOID_SPRINTF
409
#ifndef VOID_SPRINTF
363
	s +=
410
	s +=
364
#endif
411
#endif
365
	sprintf(s, ",\n\"XPMEXT %s\"", ext->name);
412
	snprintf(s, data_size - (s-dataptr), ",\n\"XPMEXT %s\"", ext->name);
366
#ifdef VOID_SPRINTF
413
#ifdef VOID_SPRINTF
367
	s += strlen(ext->name) + 11;
414
	s += strlen(ext->name) + 11;
368
#endif
415
#endif
Lines 371-383 WriteExtensions(dataptr, used_size, ext, Link Here
371
#ifndef VOID_SPRINTF
418
#ifndef VOID_SPRINTF
372
	    s +=
419
	    s +=
373
#endif
420
#endif
374
	    sprintf(s, ",\n\"%s\"", *line);
421
	    snprintf(s, data_size - (s-dataptr), ",\n\"%s\"", *line);
375
#ifdef VOID_SPRINTF
422
#ifdef VOID_SPRINTF
376
	    s += strlen(*line) + 4;
423
	    s += strlen(*line) + 4;
377
#endif
424
#endif
378
	}
425
	}
379
    }
426
    }
380
    strcpy(s, ",\n\"XPMENDEXT\"");
427
    strncpy(s, ",\n\"XPMENDEXT\"", data_size - (s-dataptr)-1);
381
    *used_size += s - dataptr + 13;
428
    *used_size += s - dataptr + 13;
382
}
429
}
383
430
Lines 388-393 CommentsSize(info) Link Here
388
    int size = 0;
435
    int size = 0;
389
436
390
    /* 5 = 2 (for "/_*") + 3 (for "*_/\n") */
437
    /* 5 = 2 (for "/_*") + 3 (for "*_/\n") */
438
    /* wrap possible but *very* unlikely */
391
    if (info->hints_cmt)
439
    if (info->hints_cmt)
392
	size += 5 + strlen(info->hints_cmt);
440
	size += 5 + strlen(info->hints_cmt);
393
441
(-)xc/extras/Xpm/lib/CrDatFrI.c (-17 / +75 lines)
Lines 33-45 Link Here
33
\*****************************************************************************/
33
\*****************************************************************************/
34
/* $XFree86: xc/extras/Xpm/lib/CrDatFrI.c,v 1.2 2001/10/28 03:32:09 tsi Exp $ */
34
/* $XFree86: xc/extras/Xpm/lib/CrDatFrI.c,v 1.2 2001/10/28 03:32:09 tsi Exp $ */
35
35
36
/* October 2004, source code review by Thomas Biege <thomas@suse.de> */
37
36
#include "XpmI.h"
38
#include "XpmI.h"
37
39
38
LFUNC(CreateColors, int, (char **dataptr, unsigned int *data_size,
40
LFUNC(CreateColors, int, (char **dataptr, unsigned int *data_size,
39
			  XpmColor *colors, unsigned int ncolors,
41
			  XpmColor *colors, unsigned int ncolors,
40
			  unsigned int cpp));
42
			  unsigned int cpp));
41
43
42
LFUNC(CreatePixels, void, (char **dataptr, unsigned int width,
44
LFUNC(CreatePixels, void, (char **dataptr, unsigned int data_size,
45
			   unsigned int width,
43
			   unsigned int height, unsigned int cpp,
46
			   unsigned int height, unsigned int cpp,
44
			   unsigned int *pixels, XpmColor *colors));
47
			   unsigned int *pixels, XpmColor *colors));
45
48
Lines 47-53 LFUNC(CountExtensions, void, (XpmExtensi Link Here
47
			      unsigned int *ext_size,
50
			      unsigned int *ext_size,
48
			      unsigned int *ext_nlines));
51
			      unsigned int *ext_nlines));
49
52
50
LFUNC(CreateExtensions, void, (char **dataptr, unsigned int offset,
53
LFUNC(CreateExtensions, void, (char **dataptr, unsigned int data_size,
54
			       unsigned int offset,
51
			       XpmExtension *ext, unsigned int num,
55
			       XpmExtension *ext, unsigned int num,
52
			       unsigned int ext_nlines));
56
			       unsigned int ext_nlines));
53
57
Lines 88-97 XpmCreateDataFromImage(display, data_ret Link Here
88
92
89
#undef RETURN
93
#undef RETURN
90
#define RETURN(status) \
94
#define RETURN(status) \
95
do \
91
{ \
96
{ \
92
      ErrorStatus = status; \
97
      ErrorStatus = status; \
93
      goto exit; \
98
      goto exit; \
94
}
99
} while(0)
95
100
96
int
101
int
97
XpmCreateDataFromXpmImage(data_return, image, info)
102
XpmCreateDataFromXpmImage(data_return, image, info)
Lines 122-132 XpmCreateDataFromXpmImage(data_return, i Link Here
122
     * alloc a temporary array of char pointer for the header section which
127
     * alloc a temporary array of char pointer for the header section which
123
     * is the hints line + the color table lines
128
     * is the hints line + the color table lines
124
     */
129
     */
125
    header_nlines = 1 + image->ncolors;
130
    header_nlines = 1 + image->ncolors; /* this may wrap and/or become 0 */
131
132
    /* 2nd check superfluous if we do not need header_nlines any further */
133
    if(header_nlines <= image->ncolors ||
134
       header_nlines >= UINT_MAX / sizeof(char *))
135
    	return(XpmNoMemory);
136
126
    header_size = sizeof(char *) * header_nlines;
137
    header_size = sizeof(char *) * header_nlines;
127
    if (header_size >= UINT_MAX / sizeof(char *))
138
    if (header_size >= UINT_MAX / sizeof(char *))
128
	return (XpmNoMemory);
139
	return (XpmNoMemory);
129
    header = (char **) XpmCalloc(header_size, sizeof(char *));
140
    header = (char **) XpmCalloc(header_size, sizeof(char *)); /* can we trust image->ncolors */
130
    if (!header)
141
    if (!header)
131
	return (XpmNoMemory);
142
	return (XpmNoMemory);
132
143
Lines 170-177 XpmCreateDataFromXpmImage(data_return, i Link Here
170
181
171
    /* now we know the size needed, alloc the data and copy the header lines */
182
    /* now we know the size needed, alloc the data and copy the header lines */
172
    offset = image->width * image->cpp + 1;
183
    offset = image->width * image->cpp + 1;
173
    data_size = header_size + (image->height + ext_nlines) * sizeof(char *)
184
174
	+ image->height * offset + ext_size;
185
    if(offset <= image->width || offset <= image->cpp)
186
	RETURN(XpmNoMemory);
187
188
    if( (image->height + ext_nlines) >= UINT_MAX / sizeof(char *))
189
	RETURN(XpmNoMemory);
190
    data_size = (image->height + ext_nlines) * sizeof(char *);
191
192
    if (image->height > UINT_MAX / offset ||
193
        image->height * offset > UINT_MAX - data_size)
194
	RETURN(XpmNoMemory);
195
    data_size += image->height * offset;
196
197
    if( (header_size + ext_size) >= (UINT_MAX - data_size) )
198
	RETURN(XpmNoMemory);
199
    data_size += header_size + ext_size;
175
200
176
    data = (char **) XpmMalloc(data_size);
201
    data = (char **) XpmMalloc(data_size);
177
    if (!data)
202
    if (!data)
Lines 179-186 XpmCreateDataFromXpmImage(data_return, i Link Here
179
204
180
    data_nlines = header_nlines + image->height + ext_nlines;
205
    data_nlines = header_nlines + image->height + ext_nlines;
181
    *data = (char *) (data + data_nlines);
206
    *data = (char *) (data + data_nlines);
207
208
    /* can header have less elements then n suggests? */
182
    n = image->ncolors;
209
    n = image->ncolors;
183
    for (l = 0, sptr = data, sptr2 = header; l <= n; l++, sptr++, sptr2++) {
210
    for (l = 0, sptr = data, sptr2 = header; l <= n && sptr && sptr2; l++, sptr++, sptr2++) {
184
	strcpy(*sptr, *sptr2);
211
	strcpy(*sptr, *sptr2);
185
	*(sptr + 1) = *sptr + strlen(*sptr2) + 1;
212
	*(sptr + 1) = *sptr + strlen(*sptr2) + 1;
186
    }
213
    }
Lines 189-200 XpmCreateDataFromXpmImage(data_return, i Link Here
189
    data[header_nlines] = (char *) data + header_size
216
    data[header_nlines] = (char *) data + header_size
190
	+ (image->height + ext_nlines) * sizeof(char *);
217
	+ (image->height + ext_nlines) * sizeof(char *);
191
218
192
    CreatePixels(data + header_nlines, image->width, image->height,
219
    CreatePixels(data + header_nlines, data_size-header_nlines, image->width, image->height,
193
		 image->cpp, image->data, image->colorTable);
220
		 image->cpp, image->data, image->colorTable);
194
221
195
    /* print extensions */
222
    /* print extensions */
196
    if (extensions)
223
    if (extensions)
197
	CreateExtensions(data + header_nlines + image->height - 1, offset,
224
	CreateExtensions(data + header_nlines + image->height - 1,
225
			 data_size - header_nlines - image->height + 1, offset,
198
			 info->extensions, info->nextensions,
226
			 info->extensions, info->nextensions,
199
			 ext_nlines);
227
			 ext_nlines);
200
228
Lines 225-247 CreateColors(dataptr, data_size, colors, Link Here
225
    char *s, *s2;
253
    char *s, *s2;
226
    char **defaults;
254
    char **defaults;
227
255
256
    /* can ncolors be trusted here? */
228
    for (a = 0; a < ncolors; a++, colors++, dataptr++) {
257
    for (a = 0; a < ncolors; a++, colors++, dataptr++) {
229
258
230
	defaults = (char **) colors;
259
	defaults = (char **) colors;
260
	if(sizeof(buf) <= cpp)
261
	    return(XpmNoMemory);
231
	strncpy(buf, *defaults++, cpp);
262
	strncpy(buf, *defaults++, cpp);
232
	s = buf + cpp;
263
	s = buf + cpp;
233
264
265
	if(sizeof(buf) <= (s-buf))
266
		return XpmNoMemory;
267
234
	for (key = 1; key <= NKEYS; key++, defaults++) {
268
	for (key = 1; key <= NKEYS; key++, defaults++) {
235
	    if ((s2 = *defaults)) {
269
	    if ((s2 = *defaults)) {
236
#ifndef VOID_SPRINTF
270
#ifndef VOID_SPRINTF
237
		s +=
271
		s +=
238
#endif
272
#endif
239
		sprintf(s, "\t%s %s", xpmColorKeys[key - 1], s2);
273
		/* assume C99 compliance */
274
		snprintf(s, s-buf, "\t%s %s", xpmColorKeys[key - 1], s2);
240
#ifdef VOID_SPRINTF
275
#ifdef VOID_SPRINTF
241
		s += strlen(s);
276
		s += strlen(s);
242
#endif
277
#endif
278
		/* does s point out-of-bounds? */
279
		if(sizeof(buf) < (s-buf))
280
			return XpmNoMemory;
243
	    }
281
	    }
244
	}
282
	}
283
	/* what about using strdup()? */
245
	l = s - buf + 1;
284
	l = s - buf + 1;
246
	s = (char *) XpmMalloc(l);
285
	s = (char *) XpmMalloc(l);
247
	if (!s)
286
	if (!s)
Lines 253-260 CreateColors(dataptr, data_size, colors, Link Here
253
}
292
}
254
293
255
static void
294
static void
256
CreatePixels(dataptr, width, height, cpp, pixels, colors)
295
CreatePixels(dataptr, data_size, width, height, cpp, pixels, colors)
257
    char **dataptr;
296
    char **dataptr;
297
    unsigned int data_size;
258
    unsigned int width;
298
    unsigned int width;
259
    unsigned int height;
299
    unsigned int height;
260
    unsigned int cpp;
300
    unsigned int cpp;
Lines 264-284 CreatePixels(dataptr, width, height, cpp Link Here
264
    char *s;
304
    char *s;
265
    unsigned int x, y, h, offset;
305
    unsigned int x, y, h, offset;
266
306
307
    if(height <= 1)
308
    	return;
309
267
    h = height - 1;
310
    h = height - 1;
311
268
    offset = width * cpp + 1;
312
    offset = width * cpp + 1;
313
314
    if(offset <= width || offset <= cpp)
315
    	return;
316
317
    /* why trust h? */
269
    for (y = 0; y < h; y++, dataptr++) {
318
    for (y = 0; y < h; y++, dataptr++) {
270
	s = *dataptr;
319
	s = *dataptr;
320
	/* why trust width? */
271
	for (x = 0; x < width; x++, pixels++) {
321
	for (x = 0; x < width; x++, pixels++) {
272
	    strncpy(s, colors[*pixels].string, cpp);
322
	    if(cpp > (data_size - (s - *dataptr)))
323
	    	return;
324
	    strncpy(s, colors[*pixels].string, cpp); /* why trust pixel? */
273
	    s += cpp;
325
	    s += cpp;
274
	}
326
	}
275
	*s = '\0';
327
	*s = '\0';
328
	if(offset > data_size)
329
		return;
276
	*(dataptr + 1) = *dataptr + offset;
330
	*(dataptr + 1) = *dataptr + offset;
277
    }
331
    }
278
    /* duplicate some code to avoid a test in the loop */
332
    /* duplicate some code to avoid a test in the loop */
279
    s = *dataptr;
333
    s = *dataptr;
334
    /* why trust width? */
280
    for (x = 0; x < width; x++, pixels++) {
335
    for (x = 0; x < width; x++, pixels++) {
281
	strncpy(s, colors[*pixels].string, cpp);
336
	if(cpp > data_size - (s - *dataptr))
337
	    	return;
338
	strncpy(s, colors[*pixels].string, cpp); /* why should we trust *pixel? */
282
	s += cpp;
339
	s += cpp;
283
    }
340
    }
284
    *s = '\0';
341
    *s = '\0';
Lines 311-318 CountExtensions(ext, num, ext_size, ext_ Link Here
311
}
368
}
312
369
313
static void
370
static void
314
CreateExtensions(dataptr, offset, ext, num, ext_nlines)
371
CreateExtensions(dataptr, data_size, offset, ext, num, ext_nlines)
315
    char **dataptr;
372
    char **dataptr;
373
    unsigned int data_size;
316
    unsigned int offset;
374
    unsigned int offset;
317
    XpmExtension *ext;
375
    XpmExtension *ext;
318
    unsigned int num;
376
    unsigned int num;
Lines 325-336 CreateExtensions(dataptr, offset, ext, n Link Here
325
    dataptr++;
383
    dataptr++;
326
    a = 0;
384
    a = 0;
327
    for (x = 0; x < num; x++, ext++) {
385
    for (x = 0; x < num; x++, ext++) {
328
	sprintf(*dataptr, "XPMEXT %s", ext->name);
386
	snprintf(*dataptr, data_size, "XPMEXT %s", ext->name);
329
	a++;
387
	a++;
330
	if (a < ext_nlines)
388
	if (a < ext_nlines)
331
	    *(dataptr + 1) = *dataptr + strlen(ext->name) + 8;
389
	    *(dataptr + 1) = *dataptr + strlen(ext->name) + 8;
332
	dataptr++;
390
	dataptr++;
333
	b = ext->nlines;
391
	b = ext->nlines; /* can we trust these values? */
334
	for (y = 0, line = ext->lines; y < b; y++, line++) {
392
	for (y = 0, line = ext->lines; y < b; y++, line++) {
335
	    strcpy(*dataptr, *line);
393
	    strcpy(*dataptr, *line);
336
	    a++;
394
	    a++;
(-)xc/extras/Xpm/lib/create.c (-23 / +59 lines)
Lines 45-50 Link Here
45
 * Lorens Younes (d93-hyo@nada.kth.se) 4/96
45
 * Lorens Younes (d93-hyo@nada.kth.se) 4/96
46
 */
46
 */
47
47
48
/* October 2004, source code review by Thomas Biege <thomas@suse.de> */
49
48
#include "XpmI.h"
50
#include "XpmI.h"
49
#include <ctype.h>
51
#include <ctype.h>
50
52
Lines 584-590 CreateColors(display, attributes, colors Link Here
584
	     */
586
	     */
585
	} else {
587
	} else {
586
#endif
588
#endif
587
	    int i;
589
	    unsigned int i;
588
590
589
#ifndef AMIGA
591
#ifndef AMIGA
590
	    ncols = visual->map_entries;
592
	    ncols = visual->map_entries;
Lines 744-755 FreeColors(display, colormap, pixels, n, Link Here
744
746
745
747
746
/* function call in case of error */
748
/* function call in case of error */
749
747
#undef RETURN
750
#undef RETURN
748
#define RETURN(status) \
751
#define RETURN(status) \
752
do \
749
{ \
753
{ \
750
      ErrorStatus = status; \
754
      ErrorStatus = status; \
751
      goto error; \
755
      goto error; \
752
}
756
} while(0)
753
757
754
int
758
int
755
XpmCreateImageFromXpmImage(display, image,
759
XpmCreateImageFromXpmImage(display, image,
Lines 995-1005 CreateXImage(display, visual, depth, for Link Here
995
	return (XpmNoMemory);
999
	return (XpmNoMemory);
996
1000
997
#if !defined(FOR_MSW) && !defined(AMIGA)
1001
#if !defined(FOR_MSW) && !defined(AMIGA)
998
    if (height != 0 && (*image_return)->bytes_per_line >= SIZE_MAX / height) {
1002
    if (height != 0 && (*image_return)->bytes_per_line >= INT_MAX / height) {
999
	XDestroyImage(*image_return);
1003
	XDestroyImage(*image_return);
1000
	return XpmNoMemory;
1004
	return XpmNoMemory;
1001
    }
1005
    }
1002
    /* now that bytes_per_line must have been set properly alloc data */
1006
    /* now that bytes_per_line must have been set properly alloc data */
1007
    if((*image_return)->bytes_per_line == 0 ||  height == 0)
1008
    	return XpmNoMemory;
1003
    (*image_return)->data =
1009
    (*image_return)->data =
1004
	(char *) XpmMalloc((*image_return)->bytes_per_line * height);
1010
	(char *) XpmMalloc((*image_return)->bytes_per_line * height);
1005
1011
Lines 1028-1034 CreateXImage(display, visual, depth, for Link Here
1028
LFUNC(_putbits, void, (register char *src, int dstoffset,
1034
LFUNC(_putbits, void, (register char *src, int dstoffset,
1029
		       register int numbits, register char *dst));
1035
		       register int numbits, register char *dst));
1030
1036
1031
LFUNC(_XReverse_Bytes, int, (register unsigned char *bpt, register int nb));
1037
LFUNC(_XReverse_Bytes, int, (register unsigned char *bpt, register unsigned int nb));
1032
1038
1033
static unsigned char Const _reverse_byte[0x100] = {
1039
static unsigned char Const _reverse_byte[0x100] = {
1034
    0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
1040
    0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
Lines 1068-1079 static unsigned char Const _reverse_byte Link Here
1068
static int
1074
static int
1069
_XReverse_Bytes(bpt, nb)
1075
_XReverse_Bytes(bpt, nb)
1070
    register unsigned char *bpt;
1076
    register unsigned char *bpt;
1071
    register int nb;
1077
    register unsigned int nb;
1072
{
1078
{
1073
    do {
1079
    do {
1074
	*bpt = _reverse_byte[*bpt];
1080
	*bpt = _reverse_byte[*bpt];
1075
	bpt++;
1081
	bpt++;
1076
    } while (--nb > 0);
1082
    } while (--nb > 0); /* is nb user-controled? */
1077
    return 0;
1083
    return 0;
1078
}
1084
}
1079
1085
Lines 1212-1218 PutImagePixels(image, width, height, pix Link Here
1212
    register char *src;
1218
    register char *src;
1213
    register char *dst;
1219
    register char *dst;
1214
    register unsigned int *iptr;
1220
    register unsigned int *iptr;
1215
    register int x, y, i;
1221
    register unsigned int x, y, i;
1216
    register char *data;
1222
    register char *data;
1217
    Pixel pixel, px;
1223
    Pixel pixel, px;
1218
    int nbytes, depth, ibu, ibpp;
1224
    int nbytes, depth, ibu, ibpp;
Lines 1222-1229 PutImagePixels(image, width, height, pix Link Here
1222
    depth = image->depth;
1228
    depth = image->depth;
1223
    if (depth == 1) {
1229
    if (depth == 1) {
1224
	ibu = image->bitmap_unit;
1230
	ibu = image->bitmap_unit;
1225
	for (y = 0; y < height; y++)
1231
	for (y = 0; y < height; y++) /* how can we trust height */
1226
	    for (x = 0; x < width; x++, iptr++) {
1232
	    for (x = 0; x < width; x++, iptr++) { /* how can we trust width */
1227
		pixel = pixels[*iptr];
1233
		pixel = pixels[*iptr];
1228
		for (i = 0, px = pixel; i < sizeof(unsigned long);
1234
		for (i = 0, px = pixel; i < sizeof(unsigned long);
1229
		     i++, px >>= 8)
1235
		     i++, px >>= 8)
Lines 1298-1309 PutImagePixels32(image, width, height, p Link Here
1298
{
1304
{
1299
    unsigned char *data;
1305
    unsigned char *data;
1300
    unsigned int *iptr;
1306
    unsigned int *iptr;
1301
    int y;
1307
    unsigned int y;
1302
    Pixel pixel;
1308
    Pixel pixel;
1303
1309
1304
#ifdef WITHOUT_SPEEDUPS
1310
#ifdef WITHOUT_SPEEDUPS
1305
1311
1306
    int x;
1312
    unsigned int x;
1307
    unsigned char *addr;
1313
    unsigned char *addr;
1308
1314
1309
    data = (unsigned char *) image->data;
1315
    data = (unsigned char *) image->data;
Lines 1340-1346 PutImagePixels32(image, width, height, p Link Here
1340
1346
1341
#else  /* WITHOUT_SPEEDUPS */
1347
#else  /* WITHOUT_SPEEDUPS */
1342
1348
1343
    int bpl = image->bytes_per_line;
1349
    unsigned int bpl = image->bytes_per_line;
1344
    unsigned char *data_ptr, *max_data;
1350
    unsigned char *data_ptr, *max_data;
1345
1351
1346
    data = (unsigned char *) image->data;
1352
    data = (unsigned char *) image->data;
Lines 1408-1418 PutImagePixels16(image, width, height, p Link Here
1408
{
1414
{
1409
    unsigned char *data;
1415
    unsigned char *data;
1410
    unsigned int *iptr;
1416
    unsigned int *iptr;
1411
    int y;
1417
    unsigned int y;
1412
1418
1413
#ifdef WITHOUT_SPEEDUPS
1419
#ifdef WITHOUT_SPEEDUPS
1414
1420
1415
    int x;
1421
    unsigned int x;
1416
    unsigned char *addr;
1422
    unsigned char *addr;
1417
1423
1418
    data = (unsigned char *) image->data;
1424
    data = (unsigned char *) image->data;
Lines 1436-1442 PutImagePixels16(image, width, height, p Link Here
1436
1442
1437
    Pixel pixel;
1443
    Pixel pixel;
1438
1444
1439
    int bpl = image->bytes_per_line;
1445
    unsigned int bpl = image->bytes_per_line;
1440
    unsigned char *data_ptr, *max_data;
1446
    unsigned char *data_ptr, *max_data;
1441
1447
1442
    data = (unsigned char *) image->data;
1448
    data = (unsigned char *) image->data;
Lines 1489-1499 PutImagePixels8(image, width, height, pi Link Here
1489
{
1495
{
1490
    char *data;
1496
    char *data;
1491
    unsigned int *iptr;
1497
    unsigned int *iptr;
1492
    int y;
1498
    unsigned int y;
1493
1499
1494
#ifdef WITHOUT_SPEEDUPS
1500
#ifdef WITHOUT_SPEEDUPS
1495
1501
1496
    int x;
1502
    unsigned int x;
1497
1503
1498
    data = image->data;
1504
    data = image->data;
1499
    iptr = pixelindex;
1505
    iptr = pixelindex;
Lines 1503-1509 PutImagePixels8(image, width, height, pi Link Here
1503
1509
1504
#else  /* WITHOUT_SPEEDUPS */
1510
#else  /* WITHOUT_SPEEDUPS */
1505
1511
1506
    int bpl = image->bytes_per_line;
1512
    unsigned int bpl = image->bytes_per_line;
1507
    char *data_ptr, *max_data;
1513
    char *data_ptr, *max_data;
1508
1514
1509
    data = image->data;
1515
    data = image->data;
Lines 1538-1549 PutImagePixels1(image, width, height, pi Link Here
1538
	PutImagePixels(image, width, height, pixelindex, pixels);
1544
	PutImagePixels(image, width, height, pixelindex, pixels);
1539
    else {
1545
    else {
1540
	unsigned int *iptr;
1546
	unsigned int *iptr;
1541
	int y;
1547
	unsigned int y;
1542
	char *data;
1548
	char *data;
1543
1549
1544
#ifdef WITHOUT_SPEEDUPS
1550
#ifdef WITHOUT_SPEEDUPS
1545
1551
1546
	int x;
1552
	unsigned int x;
1547
1553
1548
	data = image->data;
1554
	data = image->data;
1549
	iptr = pixelindex;
1555
	iptr = pixelindex;
Lines 1766-1771 PutPixel1(ximage, x, y, pixel) Link Here
1766
    Pixel px;
1772
    Pixel px;
1767
    int nbytes;
1773
    int nbytes;
1768
1774
1775
    if(x < 0 || y < 0)
1776
    	return 0;
1777
1769
    for (i=0, px=pixel; i<sizeof(unsigned long); i++, px>>=8)
1778
    for (i=0, px=pixel; i<sizeof(unsigned long); i++, px>>=8)
1770
	((unsigned char *)&pixel)[i] = px;
1779
	((unsigned char *)&pixel)[i] = px;
1771
    src = &ximage->data[XYINDEX(x, y, ximage)];
1780
    src = &ximage->data[XYINDEX(x, y, ximage)];
Lines 1796-1802 PutPixel(ximage, x, y, pixel) Link Here
1796
    register char *dst;
1805
    register char *dst;
1797
    register int i;
1806
    register int i;
1798
    Pixel px;
1807
    Pixel px;
1799
    int nbytes, ibpp;
1808
    unsigned int nbytes, ibpp;
1809
1810
    if(x < 0 || y < 0)
1811
    	return 0;
1800
1812
1801
    ibpp = ximage->bits_per_pixel;
1813
    ibpp = ximage->bits_per_pixel;
1802
    if (ximage->depth == 4)
1814
    if (ximage->depth == 4)
Lines 1829-1834 PutPixel32(ximage, x, y, pixel) Link Here
1829
{
1841
{
1830
    unsigned char *addr;
1842
    unsigned char *addr;
1831
1843
1844
    if(x < 0 || y < 0)
1845
    	return 0;
1846
1832
    addr = &((unsigned char *)ximage->data) [ZINDEX32(x, y, ximage)];
1847
    addr = &((unsigned char *)ximage->data) [ZINDEX32(x, y, ximage)];
1833
    *((unsigned long *)addr) = pixel;
1848
    *((unsigned long *)addr) = pixel;
1834
    return 1;
1849
    return 1;
Lines 1843-1848 PutPixel32MSB(ximage, x, y, pixel) Link Here
1843
{
1858
{
1844
    unsigned char *addr;
1859
    unsigned char *addr;
1845
1860
1861
    if(x < 0 || y < 0)
1862
    	return 0;
1863
1846
    addr = &((unsigned char *)ximage->data) [ZINDEX32(x, y, ximage)];
1864
    addr = &((unsigned char *)ximage->data) [ZINDEX32(x, y, ximage)];
1847
    addr[0] = pixel >> 24;
1865
    addr[0] = pixel >> 24;
1848
    addr[1] = pixel >> 16;
1866
    addr[1] = pixel >> 16;
Lines 1860-1865 PutPixel32LSB(ximage, x, y, pixel) Link Here
1860
{
1878
{
1861
    unsigned char *addr;
1879
    unsigned char *addr;
1862
1880
1881
    if(x < 0 || y < 0)
1882
    	return 0;
1883
1863
    addr = &((unsigned char *)ximage->data) [ZINDEX32(x, y, ximage)];
1884
    addr = &((unsigned char *)ximage->data) [ZINDEX32(x, y, ximage)];
1864
    addr[3] = pixel >> 24;
1885
    addr[3] = pixel >> 24;
1865
    addr[2] = pixel >> 16;
1886
    addr[2] = pixel >> 16;
Lines 1877-1882 PutPixel16MSB(ximage, x, y, pixel) Link Here
1877
{
1898
{
1878
    unsigned char *addr;
1899
    unsigned char *addr;
1879
    
1900
    
1901
    if(x < 0 || y < 0)
1902
    	return 0;
1903
1880
    addr = &((unsigned char *)ximage->data) [ZINDEX16(x, y, ximage)];
1904
    addr = &((unsigned char *)ximage->data) [ZINDEX16(x, y, ximage)];
1881
    addr[0] = pixel >> 8;
1905
    addr[0] = pixel >> 8;
1882
    addr[1] = pixel;
1906
    addr[1] = pixel;
Lines 1892-1897 PutPixel16LSB(ximage, x, y, pixel) Link Here
1892
{
1916
{
1893
    unsigned char *addr;
1917
    unsigned char *addr;
1894
    
1918
    
1919
    if(x < 0 || y < 0)
1920
    	return 0;
1921
1895
    addr = &((unsigned char *)ximage->data) [ZINDEX16(x, y, ximage)];
1922
    addr = &((unsigned char *)ximage->data) [ZINDEX16(x, y, ximage)];
1896
    addr[1] = pixel >> 8;
1923
    addr[1] = pixel >> 8;
1897
    addr[0] = pixel;
1924
    addr[0] = pixel;
Lines 1905-1910 PutPixel8(ximage, x, y, pixel) Link Here
1905
    int y;
1932
    int y;
1906
    unsigned long pixel;
1933
    unsigned long pixel;
1907
{
1934
{
1935
    if(x < 0 || y < 0)
1936
    	return 0;
1937
1908
    ximage->data[ZINDEX8(x, y, ximage)] = pixel;
1938
    ximage->data[ZINDEX8(x, y, ximage)] = pixel;
1909
    return 1;
1939
    return 1;
1910
}
1940
}
Lines 1916-1921 PutPixel1MSB(ximage, x, y, pixel) Link Here
1916
    int y;
1946
    int y;
1917
    unsigned long pixel;
1947
    unsigned long pixel;
1918
{
1948
{
1949
    if(x < 0 || y < 0)
1950
    	return 0;
1951
1919
    if (pixel & 1)
1952
    if (pixel & 1)
1920
	ximage->data[ZINDEX1(x, y, ximage)] |= 0x80 >> (x & 7);
1953
	ximage->data[ZINDEX1(x, y, ximage)] |= 0x80 >> (x & 7);
1921
    else
1954
    else
Lines 1930-1935 PutPixel1LSB(ximage, x, y, pixel) Link Here
1930
    int y;
1963
    int y;
1931
    unsigned long pixel;
1964
    unsigned long pixel;
1932
{
1965
{
1966
    if(x < 0 || y < 0)
1967
    	return 0;
1968
1933
    if (pixel & 1)
1969
    if (pixel & 1)
1934
	ximage->data[ZINDEX1(x, y, ximage)] |= 1 << (x & 7);
1970
	ximage->data[ZINDEX1(x, y, ximage)] |= 1 << (x & 7);
1935
    else
1971
    else
Lines 2182-2188 xpmParseDataAndCreate(display, data, ima Link Here
2182
     * free the hastable
2218
     * free the hastable
2183
     */
2219
     */
2184
    if (ErrorStatus != XpmSuccess)
2220
    if (ErrorStatus != XpmSuccess)
2185
	RETURN(ErrorStatus)
2221
	RETURN(ErrorStatus);
2186
    else if (USE_HASHTABLE)
2222
    else if (USE_HASHTABLE)
2187
	xpmHashTableFree(&hashtable);
2223
	xpmHashTableFree(&hashtable);
2188
2224
Lines 2378-2384 if (cidx[f]) XpmFree(cidx[f]);} Link Here
2378
2414
2379
	    bzero((char *)cidx, 256 * sizeof(unsigned short *)); /* init */
2415
	    bzero((char *)cidx, 256 * sizeof(unsigned short *)); /* init */
2380
	    for (a = 0; a < ncolors; a++) {
2416
	    for (a = 0; a < ncolors; a++) {
2381
		char1 = colorTable[a].string[0];
2417
		char1 = (unsigned char) colorTable[a].string[0];
2382
		if (cidx[char1] == NULL) { /* get new memory */
2418
		if (cidx[char1] == NULL) { /* get new memory */
2383
		    cidx[char1] = (unsigned short *)
2419
		    cidx[char1] = (unsigned short *)
2384
			XpmCalloc(256, sizeof(unsigned short));
2420
			XpmCalloc(256, sizeof(unsigned short));
(-)xc/extras/Xpm/lib/data.c (-4 / +7 lines)
Lines 33-38 Link Here
33
\*****************************************************************************/
33
\*****************************************************************************/
34
/* $XFree86: xc/extras/Xpm/lib/data.c,v 1.4 2002/01/07 19:40:49 dawes Exp $ */
34
/* $XFree86: xc/extras/Xpm/lib/data.c,v 1.4 2002/01/07 19:40:49 dawes Exp $ */
35
35
36
/* October 2004, source code review by Thomas Biege <thomas@suse.de> */
37
36
#ifndef CXPMPROG
38
#ifndef CXPMPROG
37
#if 0
39
#if 0
38
/* Official version number */
40
/* Official version number */
Lines 262-268 xpmNextWord(data, buf, buflen) Link Here
262
	}
264
	}
263
	Ungetc(data, c, file);
265
	Ungetc(data, c, file);
264
    }
266
    }
265
    return (n);
267
    return (n); /* this returns bytes read + 1 */
266
}
268
}
267
269
268
/*
270
/*
Lines 375-382 xpmGetCmt(data, cmt) Link Here
375
{
377
{
376
    if (!data->type)
378
    if (!data->type)
377
	*cmt = NULL;
379
	*cmt = NULL;
378
    else if (data->CommentLength != 0 && data->CommentLength < SIZE_MAX - 1) {
380
    else if (data->CommentLength != 0 && data->CommentLength < UINT_MAX - 1) {
379
	*cmt = (char *) XpmMalloc(data->CommentLength + 1);
381
	if( (*cmt = (char *) XpmMalloc(data->CommentLength + 1)) == NULL)
382
		return XpmNoMemory;
380
	strncpy(*cmt, data->Comment, data->CommentLength);
383
	strncpy(*cmt, data->Comment, data->CommentLength);
381
	(*cmt)[data->CommentLength] = '\0';
384
	(*cmt)[data->CommentLength] = '\0';
382
	data->CommentLength = 0;
385
	data->CommentLength = 0;
Lines 400-406 int Link Here
400
xpmParseHeader(data)
403
xpmParseHeader(data)
401
    xpmData *data;
404
    xpmData *data;
402
{
405
{
403
    char buf[BUFSIZ];
406
    char buf[BUFSIZ+1] = {0};
404
    int l, n = 0;
407
    int l, n = 0;
405
408
406
    if (data->type) {
409
    if (data->type) {
(-)xc/extras/Xpm/lib/Imakefile (-2 / +4 lines)
Lines 104-116 HEADERS = xpm.h Link Here
104
	 CrBufFrI.c CrDatFrP.c CrPFrBuf.c RdFToI.c WrFFrI.c \
104
	 CrBufFrI.c CrDatFrP.c CrPFrBuf.c RdFToI.c WrFFrI.c \
105
	 CrBufFrP.c CrIFrBuf.c CrPFrDat.c RdFToP.c WrFFrP.c \
105
	 CrBufFrP.c CrIFrBuf.c CrPFrDat.c RdFToP.c WrFFrP.c \
106
	 CrDatFrI.c CrIFrDat.c RdFToDat.c WrFFrDat.c \
106
	 CrDatFrI.c CrIFrDat.c RdFToDat.c WrFFrDat.c \
107
	 Attrib.c CrIFrP.c CrPFrI.c Image.c Info.c RdFToBuf.c WrFFrBuf.c
107
	 Attrib.c CrIFrP.c CrPFrI.c Image.c Info.c RdFToBuf.c WrFFrBuf.c \
108
	 s_popen.c
108
109
109
  OBJS = data.o create.o misc.o rgb.o scan.o parse.o hashtab.o \
110
  OBJS = data.o create.o misc.o rgb.o scan.o parse.o hashtab.o \
110
	 CrBufFrI.o CrDatFrP.o CrPFrBuf.o RdFToI.o WrFFrI.o \
111
	 CrBufFrI.o CrDatFrP.o CrPFrBuf.o RdFToI.o WrFFrI.o \
111
	 CrBufFrP.o CrIFrBuf.o CrPFrDat.o RdFToP.o WrFFrP.o \
112
	 CrBufFrP.o CrIFrBuf.o CrPFrDat.o RdFToP.o WrFFrP.o \
112
	 CrDatFrI.o CrIFrDat.o RdFToDat.o WrFFrDat.o \
113
	 CrDatFrI.o CrIFrDat.o RdFToDat.o WrFFrDat.o \
113
	 Attrib.o CrIFrP.o CrPFrI.o Image.o Info.o RdFToBuf.o WrFFrBuf.o
114
	 Attrib.o CrIFrP.o CrPFrI.o Image.o Info.o RdFToBuf.o WrFFrBuf.o \
115
	 s_popen.o
114
116
115
       INCLUDES = -I.
117
       INCLUDES = -I.
116
       LINTLIBS = $(LINTXTOLL) $(LINTXLIB) 
118
       LINTLIBS = $(LINTXTOLL) $(LINTXLIB) 
(-)xc/extras/Xpm/lib/misc.c (-1 / +1 lines)
Lines 44-50 xpmstrdup(s1) Link Here
44
    char *s1;
44
    char *s1;
45
{
45
{
46
    char *s2;
46
    char *s2;
47
    int l = strlen(s1) + 1;
47
    size_t l = strlen(s1) + 1;
48
48
49
    if (s2 = (char *) XpmMalloc(l))
49
    if (s2 = (char *) XpmMalloc(l))
50
	strcpy(s2, s1);
50
	strcpy(s2, s1);
(-)xc/extras/Xpm/lib/parse.c (-25 / +35 lines)
Lines 41-66 Link Here
41
 * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
41
 * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
42
 */
42
 */
43
43
44
/* October 2004, source code review by Thomas Biege <thomas@suse.de> */
45
44
#include "XpmI.h"
46
#include "XpmI.h"
45
#include <ctype.h>
47
#include <ctype.h>
46
#include <string.h>
48
#include <string.h>
47
49
48
#ifdef HAS_STRLCAT
50
#ifdef HAS_STRLCAT
49
# define STRLCAT(dst, src, dstsize) { \
51
# define STRLCAT(dst, src, dstsize) do { \
50
  	if (strlcat(dst, src, dstsize) >= (dstsize)) \
52
  	if (strlcat(dst, src, dstsize) >= (dstsize)) \
51
	    return (XpmFileInvalid); }
53
	    return (XpmFileInvalid); } while(0)
52
# define STRLCPY(dst, src, dstsize) { \
54
# define STRLCPY(dst, src, dstsize) do { \
53
  	if (strlcpy(dst, src, dstsize) >= (dstsize)) \
55
  	if (strlcpy(dst, src, dstsize) >= (dstsize)) \
54
	    return (XpmFileInvalid); }
56
	    return (XpmFileInvalid); } while(0)
55
#else
57
#else
56
# define STRLCAT(dst, src, dstsize) { \
58
# define STRLCAT(dst, src, dstsize) do { \
57
	if ((strlen(dst) + strlen(src)) < (dstsize)) \
59
	if ((strlen(dst) + strlen(src)) < (dstsize)) \
58
 	    strcat(dst, src); \
60
 	    strcat(dst, src); \
59
	else return (XpmFileInvalid); }
61
	else return (XpmFileInvalid); } while(0)
60
# define STRLCPY(dst, src, dstsize) { \
62
# define STRLCPY(dst, src, dstsize) do { \
61
	if (strlen(src) < (dstsize)) \
63
	if (strlen(src) < (dstsize)) \
62
 	    strcpy(dst, src); \
64
 	    strcpy(dst, src); \
63
	else return (XpmFileInvalid); }
65
	else return (XpmFileInvalid); } while(0)
64
#endif
66
#endif
65
67
66
LFUNC(ParsePixels, int, (xpmData *data, unsigned int width,
68
LFUNC(ParsePixels, int, (xpmData *data, unsigned int width,
Lines 277-285 xpmParseColors(data, ncolors, cpp, color Link Here
277
			return (XpmFileInvalid);
279
			return (XpmFileInvalid);
278
		    }
280
		    }
279
		    if (!lastwaskey)
281
		    if (!lastwaskey)
280
			STRLCAT(curbuf, " ", sizeof(curbuf)); /* append space */
282
			STRLCAT(curbuf, " ", sizeof(curbuf));/* append space */
281
		    buf[l] = '\0';
283
		    buf[l] = '\0';
282
		    STRLCAT(curbuf, buf, sizeof(curbuf));/* append buf */
284
		    STRLCAT(curbuf, buf, sizeof(curbuf)); /* append buf */
283
		    lastwaskey = 0;
285
		    lastwaskey = 0;
284
		}
286
		}
285
	    }
287
	    }
Lines 287-293 xpmParseColors(data, ncolors, cpp, color Link Here
287
		xpmFreeColorTable(colorTable, ncolors);
289
		xpmFreeColorTable(colorTable, ncolors);
288
		return (XpmFileInvalid);
290
		return (XpmFileInvalid);
289
	    }
291
	    }
290
	    len = strlen(curbuf) + 1;
292
	    len = strlen(curbuf) + 1; /* integer overflow just theoretically possible */
291
	    s = defaults[curkey] = (char *) XpmMalloc(len);
293
	    s = defaults[curkey] = (char *) XpmMalloc(len);
292
	    if (!s) {
294
	    if (!s) {
293
		xpmFreeColorTable(colorTable, ncolors);
295
		xpmFreeColorTable(colorTable, ncolors);
Lines 351-357 xpmParseColors(data, ncolors, cpp, color Link Here
351
	    memcpy(s, curbuf, len);
353
	    memcpy(s, curbuf, len);
352
	    color->c_color = s;
354
	    color->c_color = s;
353
	    *curbuf = '\0';		/* reset curbuf */
355
	    *curbuf = '\0';		/* reset curbuf */
354
	    if (a < ncolors - 1)
356
	    if (a < ncolors - 1)	/* can we trust ncolors -> leave data's bounds */
355
		xpmNextString(data);	/* get to the next string */
357
		xpmNextString(data);	/* get to the next string */
356
	}
358
	}
357
    }
359
    }
Lines 370-379 ParsePixels(data, width, height, ncolors Link Here
370
    xpmHashTable *hashtable;
372
    xpmHashTable *hashtable;
371
    unsigned int **pixels;
373
    unsigned int **pixels;
372
{
374
{
373
    unsigned int *iptr, *iptr2;
375
    unsigned int *iptr, *iptr2 = NULL; /* found by Egbert Eich */
374
    unsigned int a, x, y;
376
    unsigned int a, x, y;
375
377
376
    if ((height > 0 && width >= SIZE_MAX / height) ||
378
    if ((height > 0 && width >= UINT_MAX / height) ||
377
	width * height >= UINT_MAX / sizeof(unsigned int)) 
379
	width * height >= UINT_MAX / sizeof(unsigned int)) 
378
	return XpmNoMemory;
380
	return XpmNoMemory;
379
#ifndef FOR_MSW
381
#ifndef FOR_MSW
Lines 399-406 ParsePixels(data, width, height, ncolors Link Here
399
	{
401
	{
400
	    unsigned short colidx[256];
402
	    unsigned short colidx[256];
401
403
402
	    if (ncolors > 256)
404
	    if (ncolors > 256) {
405
		XpmFree(iptr2); /* found by Egbert Eich */
403
		return (XpmFileInvalid);
406
		return (XpmFileInvalid);
407
	    }
404
408
405
	    bzero((char *)colidx, 256 * sizeof(short));
409
	    bzero((char *)colidx, 256 * sizeof(short));
406
	    for (a = 0; a < ncolors; a++)
410
	    for (a = 0; a < ncolors; a++)
Lines 427-434 ParsePixels(data, width, height, ncolors Link Here
427
	{
431
	{
428
432
429
/* free all allocated pointers at all exits */
433
/* free all allocated pointers at all exits */
430
#define FREE_CIDX {int f; for (f = 0; f < 256; f++) \
434
#define FREE_CIDX \
431
if (cidx[f]) XpmFree(cidx[f]);}
435
do \
436
{ \
437
	int f; for (f = 0; f < 256; f++) \
438
	if (cidx[f]) XpmFree(cidx[f]); \
439
} while(0)
432
440
433
	    /* array of pointers malloced by need */
441
	    /* array of pointers malloced by need */
434
	    unsigned short *cidx[256];
442
	    unsigned short *cidx[256];
Lines 436-442 if (cidx[f]) XpmFree(cidx[f]);} Link Here
436
444
437
	    bzero((char *)cidx, 256 * sizeof(unsigned short *)); /* init */
445
	    bzero((char *)cidx, 256 * sizeof(unsigned short *)); /* init */
438
	    for (a = 0; a < ncolors; a++) {
446
	    for (a = 0; a < ncolors; a++) {
439
		char1 = colorTable[a].string[0];
447
		char1 = (unsigned char) colorTable[a].string[0];
440
		if (cidx[char1] == NULL) { /* get new memory */
448
		if (cidx[char1] == NULL) { /* get new memory */
441
		    cidx[char1] = (unsigned short *)
449
		    cidx[char1] = (unsigned short *)
442
			XpmCalloc(256, sizeof(unsigned short));
450
			XpmCalloc(256, sizeof(unsigned short));
Lines 480-487 if (cidx[f]) XpmFree(cidx[f]);} Link Here
480
	    char *s;
488
	    char *s;
481
	    char buf[BUFSIZ];
489
	    char buf[BUFSIZ];
482
490
483
	    if (cpp >= sizeof(buf))
491
	    if (cpp >= sizeof(buf)) {
492
		XpmFree(iptr2); /* found by Egbert Eich */
484
		return (XpmFileInvalid);
493
		return (XpmFileInvalid);
494
	    }
485
495
486
	    buf[cpp] = '\0';
496
	    buf[cpp] = '\0';
487
	    if (USE_HASHTABLE) {
497
	    if (USE_HASHTABLE) {
Lines 491-497 if (cidx[f]) XpmFree(cidx[f]);} Link Here
491
		    xpmNextString(data);
501
		    xpmNextString(data);
492
		    for (x = 0; x < width; x++, iptr++) {
502
		    for (x = 0; x < width; x++, iptr++) {
493
			for (a = 0, s = buf; a < cpp; a++, s++)
503
			for (a = 0, s = buf; a < cpp; a++, s++)
494
			    *s = xpmGetC(data);
504
			    *s = xpmGetC(data); /* int assigned to char, not a problem here */
495
			slot = xpmHashSlot(hashtable, buf);
505
			slot = xpmHashSlot(hashtable, buf);
496
			if (!*slot) {	/* no color matches */
506
			if (!*slot) {	/* no color matches */
497
			    XpmFree(iptr2);
507
			    XpmFree(iptr2);
Lines 505-511 if (cidx[f]) XpmFree(cidx[f]);} Link Here
505
		    xpmNextString(data);
515
		    xpmNextString(data);
506
		    for (x = 0; x < width; x++, iptr++) {
516
		    for (x = 0; x < width; x++, iptr++) {
507
			for (a = 0, s = buf; a < cpp; a++, s++)
517
			for (a = 0, s = buf; a < cpp; a++, s++)
508
			    *s = xpmGetC(data);
518
			    *s = xpmGetC(data); /* int assigned to char, not a problem here */
509
			for (a = 0; a < ncolors; a++)
519
			for (a = 0; a < ncolors; a++)
510
			    if (!strcmp(colorTable[a].string, buf))
520
			    if (!strcmp(colorTable[a].string, buf))
511
				break;
521
				break;
Lines 560-566 xpmParseExtensions(data, extensions, nex Link Here
560
    while (!notstart && notend) {
570
    while (!notstart && notend) {
561
	/* there starts an extension */
571
	/* there starts an extension */
562
	ext = (XpmExtension *)
572
	ext = (XpmExtension *)
563
	    XpmRealloc(exts, (num + 1) * sizeof(XpmExtension));
573
	    XpmRealloc(exts, (num + 1) * sizeof(XpmExtension)); /* can the loop be forced to iterate often enough to make "(num + 1) * sizeof(XpmExtension)" wrapping? */
564
	if (!ext) {
574
	if (!ext) {
565
	    XpmFree(string);
575
	    XpmFree(string);
566
	    XpmFreeExtensions(exts, num);
576
	    XpmFreeExtensions(exts, num);
Lines 597-603 xpmParseExtensions(data, extensions, nex Link Here
597
	while ((notstart = strncmp("XPMEXT", string, 6))
607
	while ((notstart = strncmp("XPMEXT", string, 6))
598
	       && (notend = strncmp("XPMENDEXT", string, 9))) {
608
	       && (notend = strncmp("XPMENDEXT", string, 9))) {
599
	    sp = (char **)
609
	    sp = (char **)
600
		XpmRealloc(ext->lines, (nlines + 1) * sizeof(char *));
610
		XpmRealloc(ext->lines, (nlines + 1) * sizeof(char *)); /* can we iterate enough for a wrapping? */
601
	    if (!sp) {
611
	    if (!sp) {
602
		XpmFree(string);
612
		XpmFree(string);
603
		ext->nlines = nlines;
613
		ext->nlines = nlines;
Lines 637-645 xpmParseExtensions(data, extensions, nex Link Here
637
/* function call in case of error */
647
/* function call in case of error */
638
#undef RETURN
648
#undef RETURN
639
#define RETURN(status) \
649
#define RETURN(status) \
640
{ \
650
do { \
641
      goto error; \
651
      goto error; \
642
}
652
} while(0)
643
653
644
/*
654
/*
645
 * This function parses an Xpm file or data and store the found informations
655
 * This function parses an Xpm file or data and store the found informations
(-)xc/extras/Xpm/lib/RdFToBuf.c (-2 / +5 lines)
Lines 37-42 Link Here
37
 * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
37
 * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
38
 */
38
 */
39
39
40
/* October 2004, source code review by Thomas Biege <thomas@suse.de> */
41
40
#include "XpmI.h"
42
#include "XpmI.h"
41
#include <sys/stat.h>
43
#include <sys/stat.h>
42
#if !defined(FOR_MSW) && !defined(WIN32)
44
#if !defined(FOR_MSW) && !defined(WIN32)
Lines 58-64 XpmReadFileToBuffer(filename, buffer_ret Link Here
58
    char *filename;
60
    char *filename;
59
    char **buffer_return;
61
    char **buffer_return;
60
{
62
{
61
    int fd, fcheck, len;
63
    int fd, fcheck;
64
    off_t len;
62
    char *ptr;
65
    char *ptr;
63
    struct stat stats;
66
    struct stat stats;
64
    FILE *fp;
67
    FILE *fp;
Lines 82-88 XpmReadFileToBuffer(filename, buffer_ret Link Here
82
	close(fd);
85
	close(fd);
83
	return XpmOpenFailed;
86
	return XpmOpenFailed;
84
    }
87
    }
85
    len = (int) stats.st_size;
88
    len = stats.st_size;
86
    ptr = (char *) XpmMalloc(len + 1);
89
    ptr = (char *) XpmMalloc(len + 1);
87
    if (!ptr) {
90
    if (!ptr) {
88
	fclose(fp);
91
	fclose(fp);
(-)xc/extras/Xpm/lib/RdFToI.c (-12 / +26 lines)
Lines 33-38 Link Here
33
\*****************************************************************************/
33
\*****************************************************************************/
34
/* $XFree86: xc/extras/Xpm/lib/RdFToI.c,v 1.2 2001/10/28 03:32:09 tsi Exp $ */
34
/* $XFree86: xc/extras/Xpm/lib/RdFToI.c,v 1.2 2001/10/28 03:32:09 tsi Exp $ */
35
35
36
/* October 2004, source code review by Thomas Biege <thomas@suse.de> */
37
36
#include "XpmI.h"
38
#include "XpmI.h"
37
#include <sys/stat.h>
39
#include <sys/stat.h>
38
#if !defined(NO_ZPIPE) && defined(WIN32)
40
#if !defined(NO_ZPIPE) && defined(WIN32)
Lines 123-128 XpmReadFileToXpmImage(filename, image, i Link Here
123
/*
125
/*
124
 * open the given file to be read as an xpmData which is returned.
126
 * open the given file to be read as an xpmData which is returned.
125
 */
127
 */
128
#ifndef NO_ZPIPE
129
	FILE *s_popen(char *cmd, const char *type);
130
#else
131
	#define s_popen popen
132
#endif
133
126
static int
134
static int
127
OpenReadFile(filename, mdata)
135
OpenReadFile(filename, mdata)
128
    char *filename;
136
    char *filename;
Lines 141-157 OpenReadFile(filename, mdata) Link Here
141
	mdata->type = XPMFILE;
149
	mdata->type = XPMFILE;
142
    } else {
150
    } else {
143
#ifndef NO_ZPIPE
151
#ifndef NO_ZPIPE
144
	int len = strlen(filename);
152
	size_t len = strlen(filename);
153
154
	if(len == 0                        ||
155
	   filename[0] == '/'              ||
156
	   strstr(filename, "../") != NULL ||
157
	   filename[len-1] == '/')
158
		return(XpmOpenFailed);
145
	if ((len > 2) && !strcmp(".Z", filename + (len - 2))) {
159
	if ((len > 2) && !strcmp(".Z", filename + (len - 2))) {
146
	    mdata->type = XPMPIPE;
160
	    mdata->type = XPMPIPE;
147
	    sprintf(buf, "uncompress -c \"%s\"", filename);
161
	    snprintf(buf, sizeof(buf), "uncompress -c \"%s\"", filename);
148
	    if (!(mdata->stream.file = popen(buf, "r")))
162
	    if (!(mdata->stream.file = s_popen(buf, "r")))
149
		return (XpmOpenFailed);
163
		return (XpmOpenFailed);
150
164
151
	} else if ((len > 3) && !strcmp(".gz", filename + (len - 3))) {
165
	} else if ((len > 3) && !strcmp(".gz", filename + (len - 3))) {
152
	    mdata->type = XPMPIPE;
166
	    mdata->type = XPMPIPE;
153
	    sprintf(buf, "gunzip -qc \"%s\"", filename);
167
	    snprintf(buf, sizeof(buf), "gunzip -qc \"%s\"", filename);
154
	    if (!(mdata->stream.file = popen(buf, "r")))
168
	    if (!(mdata->stream.file = s_popen(buf, "r")))
155
		return (XpmOpenFailed);
169
		return (XpmOpenFailed);
156
170
157
	} else {
171
	} else {
Lines 159-177 OpenReadFile(filename, mdata) Link Here
159
	    if (!(compressfile = (char *) XpmMalloc(len + 4)))
173
	    if (!(compressfile = (char *) XpmMalloc(len + 4)))
160
		return (XpmNoMemory);
174
		return (XpmNoMemory);
161
175
162
	    sprintf(compressfile, "%s.Z", filename);
176
	    snprintf(compressfile, len+4, "%s.Z", filename);
163
	    if (!stat(compressfile, &status)) {
177
	    if (!stat(compressfile, &status)) {
164
		sprintf(buf, "uncompress -c \"%s\"", compressfile);
178
		snprintf(buf, sizeof(buf), "uncompress -c \"%s\"", compressfile);
165
		if (!(mdata->stream.file = popen(buf, "r"))) {
179
		if (!(mdata->stream.file = s_popen(buf, "r"))) {
166
		    XpmFree(compressfile);
180
		    XpmFree(compressfile);
167
		    return (XpmOpenFailed);
181
		    return (XpmOpenFailed);
168
		}
182
		}
169
		mdata->type = XPMPIPE;
183
		mdata->type = XPMPIPE;
170
	    } else {
184
	    } else {
171
		sprintf(compressfile, "%s.gz", filename);
185
		snprintf(compressfile, len+4, "%s.gz", filename);
172
		if (!stat(compressfile, &status)) {
186
		if (!stat(compressfile, &status)) {
173
		    sprintf(buf, "gunzip -c \"%s\"", compressfile);
187
		    snprintf(buf, sizeof(buf), "gunzip -c \"%s\"", compressfile);
174
		    if (!(mdata->stream.file = popen(buf, "r"))) {
188
		    if (!(mdata->stream.file = s_popen(buf, "r"))) {
175
			XpmFree(compressfile);
189
			XpmFree(compressfile);
176
			return (XpmOpenFailed);
190
			return (XpmOpenFailed);
177
		    }
191
		    }
Lines 217-223 xpmDataClose(mdata) Link Here
217
	break;
231
	break;
218
#ifndef NO_ZPIPE
232
#ifndef NO_ZPIPE
219
    case XPMPIPE:
233
    case XPMPIPE:
220
	pclose(mdata->stream.file);
234
	fclose(mdata->stream.file);
221
	break;
235
	break;
222
#endif
236
#endif
223
    }
237
    }
(-)xc/extras/Xpm/lib/scan.c (-13 / +15 lines)
Lines 43-48 Link Here
43
 * Lorens Younes (d93-hyo@nada.kth.se) 4/96
43
 * Lorens Younes (d93-hyo@nada.kth.se) 4/96
44
 */
44
 */
45
45
46
/* October 2004, source code review by Thomas Biege <thomas@suse.de> */
47
46
#include "XpmI.h"
48
#include "XpmI.h"
47
49
48
#define MAXPRINTABLE 92			/* number of printable ascii chars
50
#define MAXPRINTABLE 92			/* number of printable ascii chars
Lines 172-181 storeMaskPixel(pixel, pmap, index_return Link Here
172
/* function call in case of error */
174
/* function call in case of error */
173
#undef RETURN
175
#undef RETURN
174
#define RETURN(status) \
176
#define RETURN(status) \
175
{ \
177
do { \
176
      ErrorStatus = status; \
178
      ErrorStatus = status; \
177
      goto error; \
179
      goto error; \
178
}
180
} while(0)
179
181
180
/*
182
/*
181
 * This function scans the given image and stores the found informations in
183
 * This function scans the given image and stores the found informations in
Lines 233-239 XpmCreateXpmImageFromImage(display, imag Link Here
233
    else
235
    else
234
	cpp = 0;
236
	cpp = 0;
235
237
236
    if ((height > 0 && width >= SIZE_MAX / height) ||
238
    if ((height > 0 && width >= UINT_MAX / height) ||
237
	width * height >= UINT_MAX / sizeof(unsigned int))
239
	width * height >= UINT_MAX / sizeof(unsigned int))
238
	RETURN(XpmNoMemory);
240
	RETURN(XpmNoMemory);
239
    pmap.pixelindex =
241
    pmap.pixelindex =
Lines 619-625 GetImagePixels(image, width, height, pma Link Here
619
    char *dst;
621
    char *dst;
620
    unsigned int *iptr;
622
    unsigned int *iptr;
621
    char *data;
623
    char *data;
622
    int x, y, i;
624
    unsigned int x, y, i;
623
    int bits, depth, ibu, ibpp, offset;
625
    int bits, depth, ibu, ibpp, offset;
624
    unsigned long lbt;
626
    unsigned long lbt;
625
    Pixel pixel, px;
627
    Pixel pixel, px;
Lines 721-727 GetImagePixels32(image, width, height, p Link Here
721
    unsigned char *addr;
723
    unsigned char *addr;
722
    unsigned char *data;
724
    unsigned char *data;
723
    unsigned int *iptr;
725
    unsigned int *iptr;
724
    int x, y;
726
    unsigned int x, y;
725
    unsigned long lbt;
727
    unsigned long lbt;
726
    Pixel pixel;
728
    Pixel pixel;
727
    int depth;
729
    int depth;
Lines 786-792 GetImagePixels16(image, width, height, p Link Here
786
    unsigned char *addr;
788
    unsigned char *addr;
787
    unsigned char *data;
789
    unsigned char *data;
788
    unsigned int *iptr;
790
    unsigned int *iptr;
789
    int x, y;
791
    unsigned int x, y;
790
    unsigned long lbt;
792
    unsigned long lbt;
791
    Pixel pixel;
793
    Pixel pixel;
792
    int depth;
794
    int depth;
Lines 831-837 GetImagePixels8(image, width, height, pm Link Here
831
{
833
{
832
    unsigned int *iptr;
834
    unsigned int *iptr;
833
    unsigned char *data;
835
    unsigned char *data;
834
    int x, y;
836
    unsigned int x, y;
835
    unsigned long lbt;
837
    unsigned long lbt;
836
    Pixel pixel;
838
    Pixel pixel;
837
    int depth;
839
    int depth;
Lines 864-870 GetImagePixels1(image, width, height, pm Link Here
864
    storeFuncPtr storeFunc;
866
    storeFuncPtr storeFunc;
865
{
867
{
866
    unsigned int *iptr;
868
    unsigned int *iptr;
867
    int x, y;
869
    unsigned int x, y;
868
    char *data;
870
    char *data;
869
    Pixel pixel;
871
    Pixel pixel;
870
    int xoff, yoff, offset, bpl;
872
    int xoff, yoff, offset, bpl;
Lines 900-910 GetImagePixels1(image, width, height, pm Link Here
900
# else /* AMIGA */
902
# else /* AMIGA */
901
903
902
#define CLEAN_UP(status) \
904
#define CLEAN_UP(status) \
903
{\
905
do {\
904
    if (pixels) XpmFree (pixels);\
906
    if (pixels) XpmFree (pixels);\
905
    if (tmp_img) FreeXImage (tmp_img);\
907
    if (tmp_img) FreeXImage (tmp_img);\
906
    return (status);\
908
    return (status);\
907
}
909
} while(0)
908
910
909
static int
911
static int
910
AGetImagePixels (
912
AGetImagePixels (
Lines 925-931 AGetImagePixels ( Link Here
925
    
927
    
926
    tmp_img = AllocXImage ((((width+15)>>4)<<4), 1, image->rp->BitMap->Depth);
928
    tmp_img = AllocXImage ((((width+15)>>4)<<4), 1, image->rp->BitMap->Depth);
927
    if (tmp_img == NULL)
929
    if (tmp_img == NULL)
928
	CLEAN_UP (XpmNoMemory)
930
	CLEAN_UP (XpmNoMemory);
929
    
931
    
930
    iptr = pmap->pixelindex;
932
    iptr = pmap->pixelindex;
931
    for (y = 0; y < height; ++y)
933
    for (y = 0; y < height; ++y)
Lines 934-944 AGetImagePixels ( Link Here
934
	for (x = 0; x < width; ++x, ++iptr)
936
	for (x = 0; x < width; ++x, ++iptr)
935
	{
937
	{
936
	    if ((*storeFunc) (pixels[x], pmap, iptr))
938
	    if ((*storeFunc) (pixels[x], pmap, iptr))
937
		CLEAN_UP (XpmNoMemory)
939
		CLEAN_UP (XpmNoMemory);
938
	}
940
	}
939
    }
941
    }
940
    
942
    
941
    CLEAN_UP (XpmSuccess)
943
    CLEAN_UP (XpmSuccess);
942
}
944
}
943
945
944
#undef CLEAN_UP
946
#undef CLEAN_UP
(-)xc/extras/Xpm/lib/s_popen.c (+153 lines)
Line 0 Link Here
1
/*
2
** This is a secure but NOT 100% compatible replacement for popen()
3
** Note:        - don't use pclose() use fclose() for closing the returned
4
**                filedesc.!!!
5
**
6
** Known Bugs:  - unable to use i/o-redirection like > or <
7
** Author:      - Thomas Biege <thomas@suse.de>
8
** Credits:     - Andreas Pfaller <a.pfaller@pop.gun.de> for fixing a SEGV when
9
**                calling strtok()
10
*/
11
12
#include <sys/types.h>
13
#include <sys/wait.h>
14
#include <stdio.h>
15
#include <stdlib.h>
16
#include <unistd.h>
17
#include <string.h>
18
19
#define __SEC_POPEN_TOKEN " "
20
21
FILE *s_popen(char *cmd, const char *type)
22
{
23
  pid_t pid;
24
  int pfd[2];
25
  int rpipe = 0, wpipe = 0, i;
26
  char **argv;
27
  char *ptr;
28
  char *cmdcpy;
29
30
31
  if(cmd == NULL || cmd == "")
32
    return(NULL);
33
34
  if(type[0] != 'r' && type[0] != 'w')
35
    return(NULL);
36
37
  if ((cmdcpy = strdup(cmd)) == NULL)
38
    return(NULL);
39
40
  argv = NULL;
41
  if( (ptr = strtok(cmdcpy, __SEC_POPEN_TOKEN)) == NULL)
42
  {
43
    free(cmdcpy);
44
    return(NULL);
45
  }
46
47
  for(i = 0;; i++)
48
  {
49
    if( ( argv = (char **) realloc(argv, (i+1) * sizeof(char *)) ) == NULL)
50
    {
51
      free(cmdcpy);
52
      return(NULL);
53
    }
54
55
    if( (*(argv+i) = (char *) malloc((strlen(ptr)+1) * sizeof(char))) == NULL)
56
    {
57
      free(cmdcpy);
58
      return(NULL);
59
    }
60
61
    strcpy(argv[i], ptr);
62
63
    if( (ptr = strtok(NULL, __SEC_POPEN_TOKEN)) == NULL)
64
    {
65
      if( ( argv = (char **) realloc(argv, (i+2) * sizeof(char *))) == NULL)
66
      {
67
        free(cmdcpy);
68
        return(NULL);
69
      }
70
      argv[i+1] = NULL;
71
      break;
72
    }
73
  }
74
75
76
  if(type[0] == 'r')
77
    rpipe = 1;
78
  else
79
    wpipe = 1;
80
81
  if (pipe(pfd) < 0)
82
  {
83
    free(cmdcpy);
84
    return(NULL);
85
  }
86
87
	if((pid = fork()) < 0)
88
  {
89
    close(pfd[0]);
90
    close(pfd[1]);
91
    free(cmdcpy);
92
    return(NULL);
93
  }
94
95
	if(pid == 0)    /* child */
96
  {
97
    if((pid = fork()) < 0)
98
    {
99
      close(pfd[0]);
100
      close(pfd[1]);
101
      free(cmdcpy);
102
      return(NULL);
103
    }
104
    if(pid > 0)
105
    {
106
      exit(0);  /* child nr. 1 exits */
107
    }
108
109
    /* child nr. 2 */
110
    if(rpipe)
111
    {
112
      close(pfd[0]);  /* close reading end, we don't need it */
113
      dup2(STDOUT_FILENO, STDERR_FILENO);
114
      if (pfd[1] != STDOUT_FILENO)
115
        dup2(pfd[1], STDOUT_FILENO);  /* redirect stdout to writing end of pipe */
116
    }
117
    else
118
    {
119
      close(pfd[1]);  /* close writing end, we don't need it */
120
      if (pfd[0] != STDIN_FILENO)
121
        dup2(pfd[0], STDIN_FILENO);    /* redirect stdin to reading end of pipe */
122
	  }
123
124
    if(strchr(argv[0], '/') == NULL)
125
      execvp(argv[0], argv);  /* search in $PATH */
126
    else
127
      execv(argv[0], argv);
128
129
    close(pfd[0]);
130
    close(pfd[1]);
131
    free(cmdcpy);
132
    return(NULL);  /* exec failed.. ooops! */
133
  }
134
  else          /* parent */
135
  {
136
    waitpid(pid, NULL, 0); /* wait for child nr. 1 */
137
138
    if(rpipe)
139
    {
140
      close(pfd[1]);
141
      free(cmdcpy);
142
      return(fdopen(pfd[0], "r"));
143
    }
144
    else
145
    {
146
      close(pfd[0]);
147
      free(cmdcpy);
148
      return(fdopen(pfd[1], "w"));
149
    }
150
151
  }
152
}
153
(-)xc/extras/Xpm/lib/WrFFrBuf.c (-1 / +3 lines)
Lines 32-37 Link Here
32
*  Developed by Arnaud Le Hors                                                *
32
*  Developed by Arnaud Le Hors                                                *
33
\*****************************************************************************/
33
\*****************************************************************************/
34
34
35
/* October 2004, source code review by Thomas Biege <thomas@suse.de> */
36
35
#include "XpmI.h"
37
#include "XpmI.h"
36
38
37
int
39
int
Lines 49-55 XpmWriteFileFromBuffer(filename, buffer) Link Here
49
    fcheck = fwrite(buffer, len, 1, fp);
51
    fcheck = fwrite(buffer, len, 1, fp);
50
    fclose(fp);
52
    fclose(fp);
51
    if (fcheck != 1)
53
    if (fcheck != 1)
52
	return XpmOpenFailed;
54
	return XpmOpenFailed; /* maybe use a better return value */
53
55
54
    return XpmSuccess;
56
    return XpmSuccess;
55
}
57
}
(-)xc/extras/Xpm/lib/WrFFrI.c (-9 / +25 lines)
Lines 38-43 Link Here
38
 * Lorens Younes (d93-hyo@nada.kth.se) 4/96
38
 * Lorens Younes (d93-hyo@nada.kth.se) 4/96
39
 */
39
 */
40
40
41
/* October 2004, source code review by Thomas Biege <thomas@suse.de> */
42
41
#include "XpmI.h"
43
#include "XpmI.h"
42
#if !defined(NO_ZPIPE) && defined(WIN32)
44
#if !defined(NO_ZPIPE) && defined(WIN32)
43
# define popen _popen
45
# define popen _popen
Lines 98-104 XpmWriteFileFromXpmImage(filename, image Link Here
98
    XpmInfo *info;
100
    XpmInfo *info;
99
{
101
{
100
    xpmData mdata;
102
    xpmData mdata;
101
    char *name, *dot, *s, new_name[BUFSIZ];
103
    char *name, *dot, *s, new_name[BUFSIZ] = {0};
102
    int ErrorStatus;
104
    int ErrorStatus;
103
105
104
    /* open file to write */
106
    /* open file to write */
Lines 121-127 XpmWriteFileFromXpmImage(filename, image Link Here
121
#endif
123
#endif
122
	/* let's try to make a valid C syntax name */
124
	/* let's try to make a valid C syntax name */
123
	if (index(name, '.')) {
125
	if (index(name, '.')) {
124
	    strcpy(new_name, name);
126
	    strncpy(new_name, name, sizeof(new_name));
127
	    new_name[sizeof(new_name)-1] = 0;
125
	    /* change '.' to '_' */
128
	    /* change '.' to '_' */
126
	    name = s = new_name;
129
	    name = s = new_name;
127
	    while ((dot = index(s, '.'))) {
130
	    while ((dot = index(s, '.'))) {
Lines 131-137 XpmWriteFileFromXpmImage(filename, image Link Here
131
	}
134
	}
132
	if (index(name, '-')) {
135
	if (index(name, '-')) {
133
	    if (name != new_name) {
136
	    if (name != new_name) {
134
		strcpy(new_name, name);
137
		strncpy(new_name, name, sizeof(new_name));
138
		new_name[sizeof(new_name)-1] = 0;
135
		name = new_name;
139
		name = new_name;
136
	    }
140
	    }
137
	    /* change '-' to '_' */
141
	    /* change '-' to '_' */
Lines 248-254 WritePixels(file, width, height, cpp, pi Link Here
248
    unsigned int x, y, h;
252
    unsigned int x, y, h;
249
253
250
    h = height - 1;
254
    h = height - 1;
251
    if (cpp != 0 && width >= (SIZE_MAX - 3)/cpp) 
255
    if (cpp != 0 && width >= (UINT_MAX - 3)/cpp)
252
	return XpmNoMemory;    
256
	return XpmNoMemory;    
253
    p = buf = (char *) XpmMalloc(width * cpp + 3);
257
    p = buf = (char *) XpmMalloc(width * cpp + 3);
254
    if (!buf)
258
    if (!buf)
Lines 300-305 WriteExtensions(file, ext, num) Link Here
300
/*
304
/*
301
 * open the given file to be written as an xpmData which is returned
305
 * open the given file to be written as an xpmData which is returned
302
 */
306
 */
307
#ifndef NO_ZPIPE
308
	FILE *s_popen(char *cmd, const char *type);
309
#else
310
	#define s_popen popen
311
#endif
303
static int
312
static int
304
OpenWriteFile(filename, mdata)
313
OpenWriteFile(filename, mdata)
305
    char *filename;
314
    char *filename;
Lines 315-330 OpenWriteFile(filename, mdata) Link Here
315
	mdata->type = XPMFILE;
324
	mdata->type = XPMFILE;
316
    } else {
325
    } else {
317
#ifndef NO_ZPIPE
326
#ifndef NO_ZPIPE
318
	int len = strlen(filename);
327
	size_t len = strlen(filename);
328
329
	if(len == 0                        ||
330
	   filename[0] == '/'              ||
331
	   strstr(filename, "../") != NULL ||
332
	   filename[len-1] == '/')
333
		return(XpmOpenFailed);
334
319
	if (len > 2 && !strcmp(".Z", filename + (len - 2))) {
335
	if (len > 2 && !strcmp(".Z", filename + (len - 2))) {
320
	    sprintf(buf, "compress > \"%s\"", filename);
336
	    snprintf(buf, sizeof(buf), "compress > \"%s\"", filename);
321
	    if (!(mdata->stream.file = popen(buf, "w")))
337
	    if (!(mdata->stream.file = s_popen(buf, "w")))
322
		return (XpmOpenFailed);
338
		return (XpmOpenFailed);
323
339
324
	    mdata->type = XPMPIPE;
340
	    mdata->type = XPMPIPE;
325
	} else if (len > 3 && !strcmp(".gz", filename + (len - 3))) {
341
	} else if (len > 3 && !strcmp(".gz", filename + (len - 3))) {
326
	    sprintf(buf, "gzip -q > \"%s\"", filename);
342
	    snprintf(buf, sizeof(buf), "gzip -q > \"%s\"", filename);
327
	    if (!(mdata->stream.file = popen(buf, "w")))
343
	    if (!(mdata->stream.file = s_popen(buf, "w")))
328
		return (XpmOpenFailed);
344
		return (XpmOpenFailed);
329
345
330
	    mdata->type = XPMPIPE;
346
	    mdata->type = XPMPIPE;
(-)xc/extras/Xpm/lib/xpm.h (-1 / +1 lines)
Lines 396-402 extern "C" { Link Here
396
    FUNC(XpmAttributesSize, int, (void));
396
    FUNC(XpmAttributesSize, int, (void));
397
    FUNC(XpmFreeAttributes, void, (XpmAttributes *attributes));
397
    FUNC(XpmFreeAttributes, void, (XpmAttributes *attributes));
398
    FUNC(XpmFreeExtensions, void, (XpmExtension *extensions,
398
    FUNC(XpmFreeExtensions, void, (XpmExtension *extensions,
399
				   int nextensions));
399
				   unsigned int nextensions));
400
400
401
    FUNC(XpmFreeXpmImage, void, (XpmImage *image));
401
    FUNC(XpmFreeXpmImage, void, (XpmImage *image));
402
    FUNC(XpmFreeXpmInfo, void, (XpmInfo *info));
402
    FUNC(XpmFreeXpmInfo, void, (XpmInfo *info));
(-)xc/extras/Xpm/lib/XpmI.h (+2 lines)
Lines 49-56 Link Here
49
 * lets try to solve include files
49
 * lets try to solve include files
50
 */
50
 */
51
51
52
#include <sys/types.h>
52
#include <stdio.h>
53
#include <stdio.h>
53
#include <stdlib.h>
54
#include <stdlib.h>
55
#include <limits.h>
54
/* stdio.h doesn't declare popen on a Sequent DYNIX OS */
56
/* stdio.h doesn't declare popen on a Sequent DYNIX OS */
55
#ifdef sequent
57
#ifdef sequent
56
extern FILE *popen();
58
extern FILE *popen();

Return to bug 68544