]>
Commit | Line | Data |
---|---|---|
e076d216 AM |
1 | diff -urN xfig.3.2.5-alpha4.org/f_readeps.c xfig.3.2.5-alpha4/f_readeps.c |
2 | --- xfig.3.2.5-alpha4.org/f_readeps.c 2004-04-22 00:49:19.369846072 +0200 | |
3 | +++ xfig.3.2.5-alpha4/f_readeps.c 2004-04-22 00:52:30.621771360 +0200 | |
4 | @@ -258,7 +258,7 @@ | |
ce6c6d46 | 5 | char buf[300]; |
6 | FILE *tmpfp, *pixfile, *gsfile; | |
7 | char *psnam, *driver; | |
8 | - int status, wid, ht, nbitmap; | |
9 | + int status, wid, ht, nbitmap, fd; | |
10 | char tmpfile[PATH_MAX], | |
11 | pixnam[PATH_MAX], | |
12 | errnam[PATH_MAX], | |
e076d216 | 13 | @@ -284,9 +284,21 @@ |
ce6c6d46 | 14 | fclose(tmpfp); |
15 | } | |
16 | /* make name /TMPDIR/xfig-pic.pix */ | |
17 | - sprintf(pixnam, "%s/%s%06d.pix", TMPDIR, "xfig-pic", getpid()); | |
18 | + snprintf(pixnam, sizeof(pixnam), "%s/xfig-pic.XXXXXX", TMPDIR); | |
19 | + if ((fd = mkstemp(pixnam)) == -1) { | |
20 | + file_msg("Couldn't open tmp file %s, %s", pixnam, strerror(errno)); | |
21 | + return False; | |
22 | + } | |
23 | + close(fd); | |
24 | + | |
25 | /* and file name for any error messages from gs */ | |
26 | - sprintf(errnam, "%s/%s%06d.err", TMPDIR, "xfig-pic", getpid()); | |
27 | + snprintf(errnam, sizeof(errnam), "%s/xfig-picerr.XXXXXX", TMPDIR); | |
28 | + if ((fd = mkstemp(errnam)) == -1) { | |
29 | + file_msg("Couldn't open tmp file %s, %s", errnam, strerror(errno)); | |
30 | + return False; | |
31 | + } | |
32 | + close(fd); | |
33 | + | |
34 | /* generate gs command line */ | |
35 | /* for monochrome, use pbm */ | |
36 | if (tool_cells <= 2 || appres.monochrome) { | |
e076d216 AM |
37 | diff -urN xfig.3.2.5-alpha4.org/f_readgif.c xfig.3.2.5-alpha4/f_readgif.c |
38 | --- xfig.3.2.5-alpha4.org/f_readgif.c 2004-04-22 00:49:19.369846072 +0200 | |
39 | +++ xfig.3.2.5-alpha4/f_readgif.c 2004-04-22 00:52:30.625770752 +0200 | |
ce6c6d46 | 40 | @@ -75,7 +75,7 @@ |
41 | char buf[BUFLEN],pcxname[PATH_MAX]; | |
42 | FILE *giftopcx; | |
43 | struct Cmap localColorMap[MAX_COLORMAP_SIZE]; | |
44 | - int i, stat, size; | |
45 | + int i, stat, size, fd; | |
46 | int useGlobalColormap; | |
47 | unsigned int bitPixel, red, green, blue; | |
48 | unsigned char c; | |
49 | @@ -172,7 +172,13 @@ | |
50 | /* now call giftopnm and ppmtopcx */ | |
51 | ||
52 | /* make name for temp output file */ | |
53 | - sprintf(pcxname, "%s/%s%06d.pix", TMPDIR, "xfig-pcx", getpid()); | |
54 | + snprintf(pcxname, sizeof(pcxname), "%s/xfig-pcx.XXXXXX", TMPDIR); | |
55 | + if ((fd = mkstemp(pcxname)) == -1) { | |
56 | + file_msg("Cannot create temporary file\n"); | |
57 | + return FileInvalid; | |
58 | + } | |
59 | + close(fd); | |
60 | + | |
61 | /* make command to convert gif to pcx into temp file */ | |
62 | sprintf(buf, "giftopnm | ppmtopcx > %s 2> /dev/null", pcxname); | |
63 | if ((giftopcx = popen(buf,"w" )) == 0) { | |
e076d216 AM |
64 | diff -urN xfig.3.2.5-alpha4.org/f_readppm.c xfig.3.2.5-alpha4/f_readppm.c |
65 | --- xfig.3.2.5-alpha4.org/f_readppm.c 2004-04-22 00:49:19.372845616 +0200 | |
66 | +++ xfig.3.2.5-alpha4/f_readppm.c 2004-04-22 00:52:30.628770296 +0200 | |
67 | @@ -33,10 +33,16 @@ | |
ce6c6d46 | 68 | { |
69 | char buf[BUFLEN],pcxname[PATH_MAX]; | |
70 | FILE *giftopcx; | |
71 | - int stat, size; | |
72 | + int stat, size, fd; | |
73 | ||
74 | /* make name for temp output file */ | |
75 | - sprintf(pcxname, "%s/%s%06d.pix", TMPDIR, "xfig-pcx", getpid()); | |
76 | + snprintf(pcxname, sizeof(pcxname), "%s/xfig-pcx.XXXXXX", TMPDIR); | |
77 | + if ((fd = mkstemp(pcxname)) == -1) { | |
78 | + file_msg("Cannot open temp file %s: %s\n", pcxname, strerror(errno)); | |
79 | + return FileInvalid; | |
80 | + } | |
81 | + close(fd); | |
82 | + | |
83 | /* make command to convert gif to pcx into temp file */ | |
84 | sprintf(buf, "ppmtopcx > %s 2> /dev/null", pcxname); | |
85 | if ((giftopcx = popen(buf,"w" )) == 0) { | |
e076d216 AM |
86 | diff -urN xfig.3.2.5-alpha4.org/f_readtif.c xfig.3.2.5-alpha4/f_readtif.c |
87 | --- xfig.3.2.5-alpha4.org/f_readtif.c 2004-04-22 00:49:19.372845616 +0200 | |
88 | +++ xfig.3.2.5-alpha4/f_readtif.c 2004-04-22 00:52:30.630769992 +0200 | |
ce6c6d46 | 89 | @@ -32,11 +32,16 @@ |
90 | { | |
91 | char buf[2*PATH_MAX+40],pcxname[PATH_MAX]; | |
92 | FILE *tiftopcx; | |
93 | - int stat; | |
94 | + int stat, fd; | |
95 | ||
96 | /* make name for temp output file */ | |
97 | - sprintf(pcxname, "%s/%s%06d.pix", TMPDIR, "xfig-pcx", getpid()); | |
98 | - | |
99 | + snprintf(pcxname, sizeof(pcxname), "%s/xfig-pcx.XXXXXX", TMPDIR); | |
100 | + if ((fd = mkstemp(pcxname)) == -1) { | |
101 | + file_msg("Cannot open temp file %s: %s\n", pcxname, strerror(errno)); | |
102 | + return FileInvalid; | |
103 | + } | |
104 | + close(fd); | |
105 | + | |
106 | /* make command to convert tif to pnm then to pcx into temp file */ | |
107 | /* for some reason, tifftopnm requires a file and can't work in a pipe */ | |
108 | sprintf(buf, "tifftopnm %s 2> /dev/null | ppmtopcx > %s 2> /dev/null", | |
e076d216 AM |
109 | diff -urN xfig.3.2.5-alpha4.org/f_util.c xfig.3.2.5-alpha4/f_util.c |
110 | --- xfig.3.2.5-alpha4.org/f_util.c 2004-04-22 00:49:19.375845160 +0200 | |
111 | +++ xfig.3.2.5-alpha4/f_util.c 2004-04-22 00:52:30.633769536 +0200 | |
112 | @@ -910,14 +910,20 @@ | |
ce6c6d46 | 113 | char *name; |
114 | { | |
a45c09fa | 115 | char line[RC_BUFSIZ+1], *tok; |
ce6c6d46 | 116 | + int fd; |
117 | ||
118 | /* make a temp filename in the user's home directory so we | |
119 | can just rename it to .xfigrc after creating it */ | |
120 | - sprintf(tmpname, "%s/%s%06d", userhome, "xfig-xfigrc", getpid()); | |
121 | - tmpf = fopen(tmpname,"wb"); | |
122 | - if (tmpf == 0) { | |
123 | - file_msg("Can't make temporary file for .xfigrc - error: %s",strerror(errno)); | |
124 | - return -1; | |
125 | + snprintf(tmpname, sizeof(tmpname), "%s/xfig-xfigrc.XXXXXX", userhome); | |
126 | + | |
127 | + if ((fd = mkstemp(tmpname)) == -1 || (tmpf = fdopen(fd, "wb")) == NULL) { | |
128 | + file_msg("Can't make temporary file for .xfigrc - error: %s", | |
129 | + strerror(errno)); | |
130 | + if (fd != -1) { | |
131 | + unlink(tmpname); | |
132 | + close(fd); | |
133 | + } | |
134 | + return -1; | |
135 | } | |
136 | /* read the .xfigrc file and write all to temp file except file names */ | |
137 | xfigrc = fopen(xfigrc_name,"r"); | |
e076d216 AM |
138 | diff -urN xfig.3.2.5-alpha4.org/main.c xfig.3.2.5-alpha4/main.c |
139 | --- xfig.3.2.5-alpha4.org/main.c 2004-04-22 00:49:19.377844856 +0200 | |
140 | +++ xfig.3.2.5-alpha4/main.c 2004-04-22 00:52:30.639768624 +0200 | |
141 | @@ -630,8 +630,10 @@ | |
142 | update_figs = False; | |
ce6c6d46 | 143 | |
144 | /* get the TMPDIR environment variable for temporary files */ | |
145 | - if ((TMPDIR = getenv("XFIGTMPDIR"))==NULL) | |
146 | - TMPDIR = "/tmp"; | |
147 | + if ((TMPDIR = getenv("XFIGTMPDIR"))==NULL) { | |
148 | + if ((TMPDIR = getenv("TMPDIR")) == NULL) | |
149 | + TMPDIR = "/tmp"; | |
150 | + } | |
151 | ||
e076d216 AM |
152 | /* first check args to see if user wants to scale the figure as it is |
153 | read in and make sure it is a resonable (positive) number */ | |
154 | @@ -1643,7 +1645,14 @@ | |
ce6c6d46 | 155 | if (userhome != NULL && *strcpy(cut_buf_name, userhome) != '\0') { |
156 | strcat(cut_buf_name, "/.xfig"); | |
157 | } else { | |
158 | - sprintf(cut_buf_name, "%s/xfig%06d", TMPDIR, getpid()); | |
159 | + int fd; | |
160 | + sprintf(cut_buf_name, "%s/xfig.XXXXXX", TMPDIR); | |
161 | + if ((fd = mkstemp(cut_buf_name)) == -1) { | |
162 | + fprintf(stderr, "Can't create temporary file for cut_buff: %s\n", | |
163 | + strerror(errno)); | |
164 | + exit(0); | |
165 | + } | |
166 | + close(fd); | |
167 | } | |
e076d216 | 168 | } |
ce6c6d46 | 169 | |
e076d216 AM |
170 | diff -urN xfig.3.2.5-alpha4.org/mode.c xfig.3.2.5-alpha4/mode.c |
171 | --- xfig.3.2.5-alpha4.org/mode.c 2004-04-22 00:49:19.378844704 +0200 | |
172 | +++ xfig.3.2.5-alpha4/mode.c 2004-04-22 00:52:30.641768320 +0200 | |
173 | @@ -86,7 +86,7 @@ | |
ce6c6d46 | 174 | |
175 | int cur_exp_lang; /* gets initialized in main.c */ | |
176 | Boolean batch_exists = False; | |
177 | -char batch_file[32]; | |
178 | +char batch_file[PATH_MAX]; | |
179 | ||
e076d216 AM |
180 | /*******************************************************************/ |
181 | /* If you change the order of the lang_items[] you must change the */ | |
182 | diff -urN xfig.3.2.5-alpha4.org/u_print.c xfig.3.2.5-alpha4/u_print.c | |
183 | --- xfig.3.2.5-alpha4.org/u_print.c 2004-04-22 00:49:19.389843032 +0200 | |
184 | +++ xfig.3.2.5-alpha4/u_print.c 2004-04-22 00:55:17.923337656 +0200 | |
185 | @@ -88,9 +88,16 @@ | |
ce6c6d46 | 186 | char syspr[2*PATH_MAX+200]; |
187 | char tmpfile[PATH_MAX]; | |
a45c09fa | 188 | char *name; |
ce6c6d46 | 189 | + int fd; |
190 | ||
191 | - sprintf(tmpfile, "%s/%s%06d", TMPDIR, "xfig-print", getpid()); | |
192 | + snprintf(tmpfile, sizeof(tmpfile), "%s/xfig-print.XXXXXX", TMPDIR); | |
193 | warnexist = False; | |
194 | + if ((fd = mkstemp(tmpfile)) == -1) { | |
195 | + file_msg("Can't open temp file %s: %s\n", tmpfile, strerror(errno)); | |
196 | + return; | |
197 | + } | |
198 | + close(fd); | |
199 | + | |
200 | init_write_tmpfile(); | |
201 | if (write_file(tmpfile, False)) { | |
202 | end_write_tmpfile(); | |
e076d216 | 203 | @@ -170,14 +177,20 @@ |
ce6c6d46 | 204 | char tmp_fig_file[PATH_MAX]; |
a45c09fa | 205 | char *outfile, *name, *real_lang; |
e076d216 AM |
206 | char *suf; |
207 | + int fd; | |
ce6c6d46 | 208 | |
209 | /* if file exists, ask if ok */ | |
210 | if (!ok_to_write(file, "EXPORT")) | |
211 | return (1); | |
212 | ||
213 | - sprintf(tmp_fig_file, "%s/%s%06d", TMPDIR, "xfig-fig", getpid()); | |
214 | - /* write the fig objects to a temporary file */ | |
215 | + snprintf(tmp_fig_file, sizeof(tmp_fig_file), "%s/xfig-fig.XXXXXX", TMPDIR); | |
216 | warnexist = False; | |
e076d216 AM |
217 | + if ((fd = mkstemp(tmp_fig_file)) == -1) { |
218 | + file_msg("Can't open temp file %s: %s\n", tmp_fig_file, | |
219 | + strerror(errno)); | |
220 | + return 1; | |
221 | + } | |
222 | + close(fd); | |
ce6c6d46 | 223 | init_write_tmpfile(); |
224 | if (write_file(tmp_fig_file, False)) { | |
225 | end_write_tmpfile(); | |
e076d216 | 226 | @@ -574,10 +587,16 @@ |
ce6c6d46 | 227 | char errfname[PATH_MAX]; |
228 | FILE *errfile; | |
229 | char str[400]; | |
230 | - int status; | |
231 | + int status, fd; | |
232 | ||
233 | /* make temp filename for any errors */ | |
234 | - sprintf(errfname, "%s/xfig-export%06d.err", TMPDIR, getpid()); | |
235 | + snprintf(errfname, sizeof(errfname), "%s/xfig-export.XXXXXX", TMPDIR); | |
236 | + if ((fd = mkstemp(errfname)) == -1) { | |
237 | + file_msg("Can't open temp file %s: %s\n", errfname, strerror(errno)); | |
238 | + return 1; | |
239 | + } | |
240 | + close(fd); | |
241 | + | |
242 | /* direct any output from fig2dev to this file */ | |
243 | strcat(command, " 2> "); | |
244 | strcat(command, errfname); | |
e076d216 AM |
245 | diff -urN xfig.3.2.5-alpha4.org/w_print.c xfig.3.2.5-alpha4/w_print.c |
246 | --- xfig.3.2.5-alpha4.org/w_print.c 2004-04-22 00:49:19.445834520 +0200 | |
247 | +++ xfig.3.2.5-alpha4/w_print.c 2004-04-22 00:52:30.651766800 +0200 | |
248 | @@ -289,10 +289,10 @@ | |
ce6c6d46 | 249 | Widget w; |
250 | { | |
251 | FILE *infp,*outfp; | |
252 | - char tmp_exp_file[32]; | |
253 | + char tmp_exp_file[PATH_MAX]; | |
254 | char str[255]; | |
a45c09fa | 255 | char backgrnd[10], grid[80]; |
ce6c6d46 | 256 | - |
257 | + int fd; | |
258 | if (writing_batch || emptyfigure_msg(print_msg)) | |
259 | return; | |
260 | ||
e076d216 | 261 | @@ -300,11 +300,20 @@ |
ce6c6d46 | 262 | /* this could happen if the user presses the button too fast */ |
263 | writing_batch = True; | |
264 | ||
265 | - /* make a temporary name to write the batch stuff to */ | |
266 | - sprintf(batch_file, "%s/%s%06d", TMPDIR, "xfig-batch", getpid()); | |
267 | /* make a temporary name to write this figure to */ | |
268 | - sprintf(tmp_exp_file, "%s/%s%06d", TMPDIR, "xfig-exp", getpid()); | |
269 | - batch_exists = True; | |
270 | + snprintf(tmp_exp_file, sizeof(tmp_exp_file), "%s/xfig-exp.XXXXXX", | |
271 | + TMPDIR); | |
272 | + | |
273 | + if (batch_exists != True) { | |
274 | + /* make a temporary name to write the batch stuff to */ | |
275 | + sprintf(batch_file, "%s/xfig-batch.XXXXXX", TMPDIR); | |
276 | + if ((fd = mkstemp(batch_file)) == -1) { | |
277 | + file_msg("Error creating temporary file"); | |
278 | + return; | |
279 | + } | |
280 | + close(fd); | |
281 | + batch_exists = True; | |
282 | + } | |
283 | if (!print_popup) | |
284 | create_print_panel(w); | |
285 | ||
e076d216 | 286 | @@ -317,6 +326,12 @@ |
ce6c6d46 | 287 | /* make a #rrggbb string from the background color */ |
288 | make_rgb_string(export_background_color, backgrnd); | |
e076d216 | 289 | |
ce6c6d46 | 290 | + if ((fd = mkstemp(tmp_exp_file)) == -1) { |
291 | + file_msg("Error creating temporary file"); | |
292 | + return; | |
293 | + } | |
294 | + close(fd); | |
e076d216 AM |
295 | + |
296 | /* get grid params and assemble into fig2dev parm */ | |
297 | get_grid_spec(grid, print_grid_minor_text, print_grid_major_text); | |
ce6c6d46 | 298 | |
e076d216 AM |
299 | diff -urN xfig.3.2.5-alpha4.org/w_srchrepl.c xfig.3.2.5-alpha4/w_srchrepl.c |
300 | --- xfig.3.2.5-alpha4.org/w_srchrepl.c 2004-04-22 00:49:19.460832240 +0200 | |
301 | +++ xfig.3.2.5-alpha4/w_srchrepl.c 2004-04-22 00:52:30.654766344 +0200 | |
302 | @@ -805,7 +805,7 @@ | |
ce6c6d46 | 303 | char *cmd; |
304 | char str[300]; | |
305 | FILE *fp; | |
306 | - int len, i; | |
307 | + int len, i, fd; | |
308 | Boolean done = FALSE; | |
309 | static int lines = 0; | |
310 | ||
e076d216 | 311 | @@ -821,9 +821,12 @@ |
ce6c6d46 | 312 | } |
313 | lines = 0; | |
314 | ||
315 | - sprintf(filename, "%s/xfig-spell.%d", TMPDIR, (int)getpid()); | |
316 | - fp = fopen(filename, "w"); | |
317 | - if (fp == NULL) { | |
318 | + snprintf(filename, sizeof(filename), "%s/xfig-spell.XXXXXX", TMPDIR); | |
319 | + if ((fd = mkstemp(filename)) == -1 || (fp = fdopen(fd, "w")) == NULL) { | |
320 | + if (fd != -1) { | |
321 | + unlink(filename); | |
322 | + close(fd); | |
323 | + } | |
324 | file_msg("Can't open temporary file: %s: %s\n", filename, strerror(errno)); | |
325 | } else { | |
326 | /* locate all text objects and write them to file fp */ |