]>
Commit | Line | Data |
---|---|---|
f88be581 | 1 | Greg Kroah-Hartman's patch, dated 8 Jan 2001. |
2 | diff -aur apache_1.3.14/src/support/htdigest.c apache_1.3.14-mkstemp/src/support/htdigest.c | |
3 | --- apache_1.3.14/src/support/htdigest.c Tue Jan 25 23:36:53 2000 | |
4 | +++ apache_1.3.14-mkstemp/src/support/htdigest.c Tue Jan 9 20:42:42 2001 | |
5 | @@ -93,7 +93,7 @@ | |
6 | ||
7 | #define MAX_STRING_LEN 256 | |
8 | ||
9 | -char *tn; | |
10 | +char tn[MAX_STRING_LEN]; | |
11 | ||
12 | ||
13 | static void getword(char *word, char *line, char stop) | |
14 | @@ -156,7 +156,7 @@ | |
15 | ap_getpass("Re-type new password: ", pwv, sizeof(pwv)); | |
16 | if (strcmp(pwin, pwv) != 0) { | |
17 | fprintf(stderr, "They don't match, sorry.\n"); | |
18 | - if (tn) { | |
19 | + if (strlen(tn)) { | |
20 | unlink(tn); | |
21 | } | |
22 | exit(1); | |
23 | @@ -187,7 +187,7 @@ | |
24 | static void interrupted(void) | |
25 | { | |
26 | fprintf(stderr, "Interrupted.\n"); | |
27 | - if (tn) | |
28 | + if (strlen(tn)) | |
29 | unlink(tn); | |
30 | exit(1); | |
31 | } | |
32 | @@ -215,8 +215,9 @@ | |
33 | char x[MAX_STRING_LEN]; | |
34 | char command[MAX_STRING_LEN]; | |
35 | int found; | |
36 | + int tfd; | |
37 | ||
38 | - tn = NULL; | |
39 | + strcpy (tn, "/tmp/htdigest-XXXXXX"); | |
40 | signal(SIGINT, (void (*)(int)) interrupted); | |
41 | if (argc == 5) { | |
42 | if (strcmp(argv[1], "-c")) | |
43 | @@ -235,8 +236,12 @@ | |
44 | else if (argc != 4) | |
45 | usage(); | |
46 | ||
47 | - tn = tmpnam(NULL); | |
48 | - if (!(tfp = fopen(tn, "w"))) { | |
49 | + tfd = mkstemp (tn); | |
50 | + if (tfd == -1) { | |
51 | + fprintf(stderr, "Could not open temp file.\n"); | |
52 | + exit(1); | |
53 | + } | |
54 | + if (!(tfp = fdopen(tfd, "w"))) { | |
55 | fprintf(stderr, "Could not open temp file.\n"); | |
56 | exit(1); | |
57 | } | |
58 | diff -aur apache_1.3.14/src/support/htpasswd.c apache_1.3.14-mkstemp/src/support/htpasswd.c | |
59 | --- apache_1.3.14/src/support/htpasswd.c Thu Jun 1 19:42:33 2000 | |
60 | +++ apache_1.3.14-mkstemp/src/support/htpasswd.c Tue Jan 9 20:41:36 2001 | |
61 | @@ -125,7 +125,7 @@ | |
62 | * This needs to be declared statically so the signal handler can | |
63 | * access it. | |
64 | */ | |
65 | -static char *tempfilename; | |
66 | +static char tempfilename[MAX_STRING_LEN]; | |
67 | /* | |
68 | * If our platform knows about the tmpnam() external buffer size, create | |
69 | * a buffer to pass in. This is needed in a threaded environment, or | |
70 | @@ -285,7 +285,7 @@ | |
71 | static void interrupted(void) | |
72 | { | |
73 | fprintf(stderr, "Interrupted.\n"); | |
74 | - if (tempfilename != NULL) { | |
75 | + if (strlen(tempfilename) > 0) { | |
76 | unlink(tempfilename); | |
77 | } | |
78 | exit(ERR_INTERRUPTED); | |
79 | @@ -377,8 +377,10 @@ | |
80 | int noninteractive = 0; | |
81 | int i; | |
82 | int args_left = 2; | |
83 | + int tfd; | |
84 | + | |
85 | + memset (tempfilename, 0x00, sizeof(tempfilename)); | |
86 | ||
87 | - tempfilename = NULL; | |
88 | signal(SIGINT, (void (*)(int)) interrupted); | |
89 | ||
90 | /* | |
91 | @@ -560,8 +562,9 @@ | |
92 | * to add or update. Let's do it.. | |
93 | */ | |
94 | errno = 0; | |
95 | - tempfilename = tmpnam(tname_buf); | |
96 | - if ((tempfilename == NULL) || (*tempfilename == '\0')) { | |
97 | + strcpy(tempfilename, "/tmp/htpasswd-XXXXXX"); | |
98 | + tfd = mkstemp(tempfilename); | |
99 | + if (tfd == -1) { | |
100 | fprintf(stderr, "%s: unable to generate temporary filename\n", | |
101 | argv[0]); | |
102 | if (errno == 0) { | |
103 | @@ -570,7 +573,7 @@ | |
104 | perror("tmpnam"); | |
105 | exit(ERR_FILEPERM); | |
106 | } | |
107 | - ftemp = fopen(tempfilename, "w+"); | |
108 | + ftemp = fdopen(tfd, "w+"); | |
109 | if (ftemp == NULL) { | |
110 | fprintf(stderr, "%s: unable to create temporary file '%s'\n", argv[0], | |
111 | tempfilename); |