c7d8832
#! /bin/sh -e
c7d8832
## 17_security-sprintf.dpatch
c7d8832
##
c7d8832
## DP: Description: Fix unsafe sprintf usage.  (#332524)
c7d8832
## DP: Author: James Troup <james@nocrew.org>
c7d8832
## DP: Upstream status: Not submitted
c7d8832
## DP: URL: http://msgs.securepoint.com/cgi-bin/get/bugtraq0510/57.html
c7d8832
## DP: Date: 2005-10-07
c7d8832
c7d8832
if [ $# -ne 1 ]; then
c7d8832
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
c7d8832
    exit 1
c7d8832
fi
c7d8832
case "$1" in
c7d8832
       -patch) patch -f --no-backup-if-mismatch -p1 < $0;;
c7d8832
       -unpatch) patch -f --no-backup-if-mismatch -R -p1 < $0;;
c7d8832
	*)
c7d8832
		echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
c7d8832
		exit 1;;
c7d8832
esac
c7d8832
c7d8832
exit 0
c7d8832
c7d8832
@DPATCH@
c7d8832
diff -urNad --exclude=CVS --exclude=.svn ./mcidas.c /tmp/dpep-work.5qsW5w/xloadimage-4.1/mcidas.c
c7d8832
--- ./mcidas.c	2005-10-08 04:15:18.000000000 +0100
c7d8832
+++ /tmp/dpep-work.5qsW5w/xloadimage-4.1/mcidas.c	2005-10-08 04:15:19.000000000 +0100
c7d8832
@@ -63,7 +63,7 @@
c7d8832
   minute = (time % 10000) / 100;
c7d8832
   second = (time % 100);
c7d8832
 
c7d8832
-  sprintf(buf, "%d:%2.2d:%2.2d %s %d, %d (day %d)",
c7d8832
+  snprintf(buf, 29, "%d:%2.2d:%2.2d %s %d, %d (day %d)",
c7d8832
 	  hour, minute, second, month_info[month].name, day, year,
c7d8832
 	  (date % 1000));
c7d8832
   return(buf);
c7d8832
diff -urNad --exclude=CVS --exclude=.svn ./reduce.c /tmp/dpep-work.5qsW5w/xloadimage-4.1/reduce.c
c7d8832
--- ./reduce.c	2005-10-08 04:15:18.000000000 +0100
c7d8832
+++ /tmp/dpep-work.5qsW5w/xloadimage-4.1/reduce.c	2005-10-08 04:15:19.000000000 +0100
c7d8832
@@ -501,7 +501,7 @@
c7d8832
 
c7d8832
   depth= colorsToDepth(n);
c7d8832
   new_image= newRGBImage(image->width, image->height, depth);
c7d8832
-  sprintf(buf, "%s (%d colors)", image->title, n);
c7d8832
+  snprintf(buf, BUFSIZ - 1, "%s (%d colors)", image->title, n);
c7d8832
   new_image->title= dupString(buf);
c7d8832
 
c7d8832
   /* calculate RGB table from each color area.  this should really calculate
c7d8832
diff -urNad --exclude=CVS --exclude=.svn ./rotate.c /tmp/dpep-work.5qsW5w/xloadimage-4.1/rotate.c
c7d8832
--- ./rotate.c	2005-10-08 04:15:18.000000000 +0100
c7d8832
+++ /tmp/dpep-work.5qsW5w/xloadimage-4.1/rotate.c	2005-10-08 04:15:19.000000000 +0100
c7d8832
@@ -70,7 +70,7 @@
c7d8832
     { printf("  Rotating image by %d degrees...", degrees);
c7d8832
       fflush(stdout);
c7d8832
     }
c7d8832
-  sprintf(buf, "%s (rotated by %d degrees)", simage->title, degrees);
c7d8832
+  snprintf(buf, BUFSIZ - 1, "%s (rotated by %d degrees)", simage->title, degrees);
c7d8832
 
c7d8832
   image1 = simage;
c7d8832
   image2 = NULL;
c7d8832
diff -urNad --exclude=CVS --exclude=.svn ./tiff.c /tmp/dpep-work.5qsW5w/xloadimage-4.1/tiff.c
c7d8832
--- ./tiff.c	2005-10-08 04:15:18.000000000 +0100
c7d8832
+++ /tmp/dpep-work.5qsW5w/xloadimage-4.1/tiff.c	2005-10-08 04:15:19.000000000 +0100
c7d8832
@@ -125,14 +125,14 @@
c7d8832
   switch (info->photometric) {
c7d8832
   case PHOTOMETRIC_MINISBLACK:
c7d8832
     if (info->bitspersample > 1) {
c7d8832
-      sprintf(buf, "%d-bit greyscale ", info->bitspersample);
c7d8832
+      snprintf(buf, 31, "%d-bit greyscale ", info->bitspersample);
c7d8832
       return(buf);
c7d8832
     }
c7d8832
     else
c7d8832
       return "white-on-black ";
c7d8832
   case PHOTOMETRIC_MINISWHITE:
c7d8832
     if (info->bitspersample > 1) {
c7d8832
-      sprintf(buf, "%d-bit greyscale ", info->bitspersample);
c7d8832
+      snprintf(buf, 31, "%d-bit greyscale ", info->bitspersample);
c7d8832
       return(buf);
c7d8832
     }
c7d8832
     else
c7d8832
diff -urNad --exclude=CVS --exclude=.svn ./window.c /tmp/dpep-work.5qsW5w/xloadimage-4.1/window.c
c7d8832
--- ./window.c	2005-10-08 04:15:18.000000000 +0100
c7d8832
+++ /tmp/dpep-work.5qsW5w/xloadimage-4.1/window.c	2005-10-08 04:15:19.000000000 +0100
c7d8832
@@ -602,7 +602,7 @@
c7d8832
   else {
c7d8832
     char def_geom[30];
c7d8832
 
c7d8832
-    sprintf(def_geom, "%ux%u+0+0", image->width, image->height);
c7d8832
+    snprintf(def_geom, 29, "%ux%u+0+0", image->width, image->height);
c7d8832
     XGeometry(disp, scrn, opt->info.geometry.string, def_geom, 0, 1, 1, 0, 0,
c7d8832
 	      (int *)&winx, (int *)&winy, (int *)&winwidth, (int *)&winheight);
c7d8832
   }
c7d8832
diff -urNad --exclude=CVS --exclude=.svn ./zio.c /tmp/dpep-work.5qsW5w/xloadimage-4.1/zio.c
c7d8832
--- ./zio.c	2005-10-08 04:15:18.000000000 +0100
c7d8832
+++ /tmp/dpep-work.5qsW5w/xloadimage-4.1/zio.c	2005-10-08 04:15:28.000000000 +0100
c7d8832
@@ -232,7 +232,7 @@
c7d8832
             strcpy (s, "'");
c7d8832
             debug(("Filtering image through '%s'\n", filter->filter));
c7d8832
             zf->type= ZPIPE;
c7d8832
-            sprintf(buf, "%s %s", filter->filter, fname);
c7d8832
+            snprintf(buf, BUFSIZ - 1, "%s %s", filter->filter, fname);
c7d8832
             lfree (fname);
c7d8832
       if (! (zf->stream= popen(buf, "r"))) {
c7d8832
 	lfree((byte *)zf->filename);
c7d8832
diff -urNad --exclude=CVS --exclude=.svn ./zoom.c /tmp/dpep-work.5qsW5w/xloadimage-4.1/zoom.c
c7d8832
--- ./zoom.c	2005-10-08 04:15:18.000000000 +0100
c7d8832
+++ /tmp/dpep-work.5qsW5w/xloadimage-4.1/zoom.c	2005-10-08 04:15:19.000000000 +0100
c7d8832
@@ -63,23 +63,23 @@
c7d8832
   if (!xzoom) {
c7d8832
     if (verbose)
c7d8832
       printf("  Zooming image Y axis by %d%%...", yzoom);
c7d8832
-      sprintf(buf, "%s (Y zoom %d%%)", oimage->title, yzoom);
c7d8832
+      snprintf(buf, BUFSIZ - 1, "%s (Y zoom %d%%)", oimage->title, yzoom);
c7d8832
   }
c7d8832
   else if (!yzoom) {
c7d8832
     if (verbose)
c7d8832
       printf("  Zooming image X axis by %d%%...", xzoom);
c7d8832
-    sprintf(buf, "%s (X zoom %d%%)", oimage->title, xzoom);
c7d8832
+    snprintf(buf, BUFSIZ - 1, "%s (X zoom %d%%)", oimage->title, xzoom);
c7d8832
   }
c7d8832
   else if (xzoom == yzoom) {
c7d8832
     if (verbose)
c7d8832
       printf("  Zooming image by %d%%...", xzoom);
c7d8832
-    sprintf(buf, "%s (%d%% zoom)", oimage->title, xzoom);
c7d8832
+    snprintf(buf, BUFSIZ - 1, "%s (%d%% zoom)", oimage->title, xzoom);
c7d8832
   }
c7d8832
   else {
c7d8832
     if (verbose)
c7d8832
       printf("  Zooming image X axis by %d%% and Y axis by %d%%...",
c7d8832
 	     xzoom, yzoom);
c7d8832
-    sprintf(buf, "%s (X zoom %d%% Y zoom %d%%)", oimage->title,
c7d8832
+    snprintf(buf, BUFSIZ - 1, "%s (X zoom %d%% Y zoom %d%%)", oimage->title,
c7d8832
 	    xzoom, yzoom);
c7d8832
   }
c7d8832
   if (verbose)