initial commit: 1.5.0
[systemrescuecd.git] / portage-overlay / www-servers / thttpd / files / thttpd-2.25 / additional-input-validation-httpd.c.diff
1 --- thttpd-2.25b/extras/htpasswd.c.orig 2006-03-31 04:12:42.281317000 +0000
2 +++ thttpd-2.25b/extras/htpasswd.c      2006-03-31 05:21:37.741632392 +0000
3 @@ -151,6 +151,7 @@ void interrupted(int signo) {
4  int main(int argc, char *argv[]) {
5      FILE *tfp,*f;
6      char user[MAX_STRING_LEN];
7 +    char pwfilename[MAX_STRING_LEN];
8      char line[MAX_STRING_LEN];
9      char l[MAX_STRING_LEN];
10      char w[MAX_STRING_LEN];
11 @@ -168,6 +169,25 @@ int main(int argc, char *argv[]) {
12              perror("fopen");
13              exit(1);
14          }
15 +        if (strlen(argv[2]) > (sizeof(pwfilename) - 1)) {
16 +            fprintf(stderr, "%s: filename is too long\n", argv[0]);
17 +           exit(1);
18 +        }
19 +        if (((strchr(argv[2], ';')) != NULL) || ((strchr(argv[2], '>')) != NULL)) {
20 +           fprintf(stderr, "%s: filename contains an illegal character\n",
21 +               argv[0]);
22 +           exit(1);
23 +        }
24 +        if (strlen(argv[3]) > (sizeof(user) - 1)) {
25 +           fprintf(stderr, "%s: username is too long\n", argv[0],
26 +               sizeof(user) - 1);
27 +           exit(1);
28 +        }
29 +        if ((strchr(argv[3], ':')) != NULL) {
30 +            fprintf(stderr, "%s: username contains an illegal character\n",
31 +                argv[0]);
32 +            exit(1);
33 +        }
34          printf("Adding password for %s.\n",argv[3]);
35          add_password(argv[3],tfp);
36          fclose(tfp);
37 @@ -180,6 +200,25 @@ int main(int argc, char *argv[]) {
38          exit(1);
39      }
40  
41 +    if (strlen(argv[1]) > (sizeof(pwfilename) - 1)) {
42 +        fprintf(stderr, "%s: filename is too long\n", argv[0]);
43 +        exit(1);
44 +    }
45 +    if (((strchr(argv[1], ';')) != NULL) || ((strchr(argv[1], '>')) != NULL)) {
46 +        fprintf(stderr, "%s: filename contains an illegal character\n",
47 +                argv[0]);
48 +        exit(1);
49 +    }
50 +    if (strlen(argv[2]) > (sizeof(user) - 1)) {
51 +        fprintf(stderr, "%s: username is too long\n", argv[0],
52 +                sizeof(user) - 1);
53 +        exit(1);
54 +    }
55 +    if ((strchr(argv[2], ':')) != NULL) {
56 +        fprintf(stderr, "%s: username contains an illegal character\n",
57 +                argv[0]);
58 +        exit(1);
59 +    }
60      if(!(f = fopen(argv[1],"r"))) {
61          fprintf(stderr,
62                  "Could not open passwd file %s for reading.\n",argv[1]);