Lines 1-227
Link Here
|
1 |
--- ../../work-old/sxsame-3.02/hiscore.c Mon Nov 1 01:17:43 1999 |
|
|
2 |
+++ hiscore.c Mon Nov 1 00:24:36 1999 |
3 |
@@ -8,8 +8,7 @@ |
4 |
#include <stdlib.h> |
5 |
#include <string.h> |
6 |
#include <unistd.h> |
7 |
-#include <sys/types.h> |
8 |
-#include <sys/stat.h> |
9 |
+#include <sys/param.h> |
10 |
#include "config.h" |
11 |
#include "hiscore.h" |
12 |
|
13 |
@@ -33,12 +32,15 @@ |
14 |
FILE *fp; |
15 |
int i, j; |
16 |
char *myname; |
17 |
- char tmpf[256]; |
18 |
+ char tmpf[MAXPATHLEN]; |
19 |
int new = 0; |
20 |
|
21 |
myname = (char *)getenv("LOGNAME"); |
22 |
- sprintf(tmpf, "%s/%s", same_dir, hiscoref); |
23 |
- umask(0); |
24 |
+ if (MAXPATHLEN <= snprintf(tmpf, MAXPATHLEN ,"%s/%s", same_dir, hiscoref) ) { |
25 |
+ fprintf(stderr,"Error: hiscore file name too long.\n"); |
26 |
+ return -1; |
27 |
+ } |
28 |
+ umask(002); |
29 |
fp = fopen(tmpf,"rb"); |
30 |
if(fp != NULL) |
31 |
{ |
32 |
@@ -82,7 +84,7 @@ |
33 |
{ |
34 |
if(lock_file(0) != 0) |
35 |
return(-1); |
36 |
- umask(0); |
37 |
+ umask(002); |
38 |
fp = fopen(tmpf, "wb"); |
39 |
fwrite(hiscore, sizeof(hiscore), 1, fp); |
40 |
fclose(fp); |
41 |
@@ -98,10 +100,13 @@ |
42 |
int cmd; |
43 |
{ |
44 |
FILE *fp; |
45 |
- char lkf[256]; |
46 |
+ char lkf[MAXPATHLEN]; |
47 |
int i; |
48 |
|
49 |
- sprintf(lkf,"%s/%s", same_dir, lockfn); |
50 |
+ if (MAXPATHLEN <= snprintf(lkf, MAXPATHLEN, "%s/%s", same_dir, lockfn)) { |
51 |
+ fprintf(stderr,"Error: lock file name too long.\n"); |
52 |
+ return -1; |
53 |
+ } |
54 |
if(cmd == 1) |
55 |
{ |
56 |
if(remove(lkf) != 0) |
57 |
@@ -137,9 +142,12 @@ |
58 |
struct Hiscore *hi; |
59 |
{ |
60 |
FILE *fp; |
61 |
- char tmpf[256]; |
62 |
+ char tmpf[MAXPATHLEN]; |
63 |
|
64 |
- sprintf(tmpf, "%s/%s", same_dir, hiscoref); |
65 |
+ if (MAXPATHLEN <= snprintf(tmpf, MAXPATHLEN, "%s/%s", same_dir, hiscoref)) { |
66 |
+ fprintf(stderr,"Error: hiscore file name too long.\n"); |
67 |
+ return -1; |
68 |
+ } |
69 |
fp = fopen(tmpf,"rb"); |
70 |
if(fp == NULL) |
71 |
return(-1); |
72 |
--- ../../work-old/sxsame-3.02/loadbmp.c Mon Nov 1 01:17:43 1999 |
73 |
+++ loadbmp.c Mon Nov 1 01:38:08 1999 |
74 |
@@ -7,6 +7,7 @@ |
75 |
#include <stdio.h> |
76 |
#include <stdlib.h> |
77 |
#include <string.h> |
78 |
+#include <sys/param.h> |
79 |
#include <X11/Xlib.h> |
80 |
#include "sxsame.h" |
81 |
|
82 |
@@ -39,17 +40,24 @@ |
83 |
int c, c1,c2; |
84 |
int width, height, planes, ncol; |
85 |
int *col; |
86 |
- char fname[256]; |
87 |
+ char fname[MAXPATHLEN]; |
88 |
|
89 |
Pixmap w; |
90 |
GC gc; |
91 |
int i, j, k; |
92 |
|
93 |
+ if (MAXPATHLEN <= strlen(bmpname) ) { |
94 |
+ fprintf(stderr,"Error: BMP file name too long.\n"); |
95 |
+ return -1; |
96 |
+ } |
97 |
strcpy(fname,bmpname); |
98 |
fp = fopen(fname,"rb"); |
99 |
if(fp == NULL) |
100 |
{ |
101 |
- sprintf(fname, "%s/%s", SAME_DIR, bmpname); |
102 |
+ if (MAXPATHLEN <= snprintf(fname, MAXPATHLEN, "%s/%s", SAME_DIR, bmpname)) { |
103 |
+ fprintf(stderr,"Error: BMP file name too long.\n"); |
104 |
+ return -1; |
105 |
+ } |
106 |
fp = fopen(fname, "r"); |
107 |
if(fp == NULL) |
108 |
{ |
109 |
--- ../../work-old/sxsame-3.02/loaddata.c Mon Nov 1 01:17:43 1999 |
110 |
+++ loaddata.c Mon Nov 1 01:35:49 1999 |
111 |
@@ -7,6 +7,7 @@ |
112 |
#include <stdio.h> |
113 |
#include <stdlib.h> |
114 |
#include <string.h> |
115 |
+#include <sys/param.h> |
116 |
#include "config.h" |
117 |
#include "sxsame.h" |
118 |
|
119 |
@@ -27,7 +28,7 @@ |
120 |
DataFile ***data; |
121 |
{ |
122 |
FILE *fp; |
123 |
- char fname[256]; |
124 |
+ char fname[MAXPATHLEN]; |
125 |
char buf[256]; |
126 |
char str1[256]; |
127 |
char str2[256]; |
128 |
@@ -36,11 +37,18 @@ |
129 |
char *p; |
130 |
int i; |
131 |
|
132 |
+ if (MAXPATHLEN <= strlen(entry_name)) { |
133 |
+ fprintf(stderr,"Error: data file name too long.\n"); |
134 |
+ return 0; |
135 |
+ } |
136 |
strcpy(fname,entry_name); |
137 |
fp = fopen(fname, "r"); |
138 |
if(fp == NULL) |
139 |
{ |
140 |
- sprintf(fname, "%s/%s", SAME_DIR, entry_name); |
141 |
+ if (MAXPATHLEN <= snprintf(fname, MAXPATHLEN ,"%s/%s", SAME_DIR, entry_name)) { |
142 |
+ fprintf(stderr,"Error: data file name too long.\n"); |
143 |
+ return 0; |
144 |
+ } |
145 |
fp = fopen(fname, "r"); |
146 |
if(fp == NULL) |
147 |
return(0); |
148 |
@@ -83,7 +91,7 @@ |
149 |
char *fname; |
150 |
{ |
151 |
FILE *fp; |
152 |
- char tmpfname[256]; |
153 |
+ char tmpfname[MAXPATHLEN]; |
154 |
char buf[256]; |
155 |
char str1[256],str2[256]; |
156 |
int val, i, j; |
157 |
@@ -105,7 +113,10 @@ |
158 |
fp = fopen(fname,"r"); |
159 |
if(fp == NULL) |
160 |
{ |
161 |
- sprintf(tmpfname, "%s/%s", SAME_DIR, fname); |
162 |
+ if (MAXPATHLEN <= snprintf(tmpfname, MAXPATHLEN, "%s/%s", SAME_DIR, fname)) { |
163 |
+ fprintf(stderr,"Error: data file name too long.\n", fname); |
164 |
+ return -1; |
165 |
+ } |
166 |
fp = fopen(tmpfname, "r"); |
167 |
if(fp == NULL) |
168 |
{ |
169 |
--- ../../work-old/sxsame-3.02/sxsame.c Mon Nov 1 01:17:44 1999 |
170 |
+++ sxsame.c Mon Nov 1 01:32:18 1999 |
171 |
@@ -16,6 +16,7 @@ |
172 |
#include <unistd.h> |
173 |
#include <time.h> |
174 |
#include <string.h> |
175 |
+#include <sys/param.h> |
176 |
#include <X11/Xlib.h> |
177 |
#include <X11/Xutil.h> |
178 |
#ifndef LOCAL_XPM_H |
179 |
@@ -740,7 +741,7 @@ |
180 |
{ |
181 |
ImportSameData data; |
182 |
int i, j, val, ncol; |
183 |
- char tmpfname[256]; |
184 |
+ char tmpfname[MAXPATHLEN]; |
185 |
|
186 |
if(strlen(fname)>4) /* check Windows data file... */ |
187 |
{ |
188 |
@@ -798,9 +799,13 @@ |
189 |
{ |
190 |
if(!access(data.xpm_data[i][j])) |
191 |
strcpy(tmpfname,data.xpm_data[i][j]); |
192 |
- else |
193 |
- sprintf(tmpfname,"%s/%s",same_dir, |
194 |
- data.xpm_data[i][j]); |
195 |
+ else { |
196 |
+ if (MAXPATHLEN <= |
197 |
+ snprintf(tmpfname, MAXPATHLEN, "%s/%s",same_dir, |
198 |
+ data.xpm_data[i][j])) { |
199 |
+ goto xpm_error; |
200 |
+ } |
201 |
+ } |
202 |
val = XpmReadFileToPixmap(dpy, root, |
203 |
tmpfname, &game.bits_xpm[i][j], |
204 |
NULL, &xpm_attr); |
205 |
@@ -818,7 +823,9 @@ |
206 |
if(!access(data.bg_data)) |
207 |
strcpy(tmpfname,data.bg_data); |
208 |
else |
209 |
- sprintf(tmpfname,"%s/%s",same_dir, data.bg_data); |
210 |
+ if (MAXPATHLEN <= snprintf(tmpfname, MAXPATHLEN, "%s/%s",same_dir, data.bg_data)) { |
211 |
+ goto xpm_error; |
212 |
+ } |
213 |
val = XpmReadFileToPixmap(dpy, root, tmpfname, |
214 |
&game.bg_xpm, NULL, &xpm_attr); |
215 |
free(data.bg_data); |
216 |
@@ -828,7 +835,10 @@ |
217 |
if(!access(data.frame_data)) |
218 |
strcpy(tmpfname,data.frame_data); |
219 |
else |
220 |
- sprintf(tmpfname,"%s/%s",same_dir, data.frame_data); |
221 |
+ if (MAXPATHLEN <= snprintf(tmpfname, MAXPATHLEN, "%s/%s",same_dir, data.frame_data)) { |
222 |
+ |
223 |
+ goto xpm_error; |
224 |
+ } |
225 |
val = XpmReadFileToPixmap(dpy, root, tmpfname, |
226 |
&game.frame_xpm, NULL, &xpm_attr); |
227 |
free(data.frame_data); |