1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
--- cscope-15.3.orig/src/main.c
+++ cscope-15.3/src/main.c
@@ -336,9 +336,32 @@
}
/* create the temporary file names */
- pid = getpid();
- (void) sprintf(temp1, "%s/cscope%d.1", tmpdir, pid);
- (void) sprintf(temp2, "%s/cscope%d.2", tmpdir, pid);
+ do {
+ char *tempfile = tempnam(tmpdir, "cscope1");
+ if (!tempfile) {
+ fprintf (stderr, "Can't create tempfile\n");
+ exit(1);
+ }
+ if (strlen(tempfile) >= sizeof(temp1)) {
+ fprintf (stderr, "TMPDIR path is too long\n");
+ exit(1);
+ }
+ strncpy (temp1, tempfile, sizeof (temp1));
+ free (tempfile);
+ } while (open (temp1, O_CREAT|O_EXCL|O_WRONLY, S_IREAD|S_IWRITE) < 0);
+ do {
+ char *tempfile = tempnam(tmpdir, "cscope2");
+ if (!tempfile) {
+ fprintf (stderr, "Can't create tempfile\n");
+ exit(1);
+ }
+ if (strlen(tempfile) >= sizeof(temp2)) {
+ fprintf (stderr, "TMPDIR path is too long\n");
+ exit(1);
+ }
+ strncpy (temp2, tempfile, sizeof (temp2));
+ free (tempfile);
+ } while (open (temp2, O_CREAT|O_EXCL|O_WRONLY, S_IREAD|S_IWRITE) < 0);
/* if running in the foreground */
if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
|