Mercurial > trustbridge
comparison cinst/main.c @ 126:898446d9d23e
Normalize input if neccessary
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Mon, 24 Mar 2014 10:13:55 +0000 |
parents | 24fb90ef8f6a |
children | 4904fe01055d |
comparison
equal
deleted
inserted
replaced
125:24fb90ef8f6a | 126:898446d9d23e |
---|---|
83 char ***to_remove) | 83 char ***to_remove) |
84 { | 84 { |
85 int lines_read = 0; | 85 int lines_read = 0; |
86 int readingList = 0; | 86 int readingList = 0; |
87 size_t list_size = 0; | 87 size_t list_size = 0; |
88 char buf[MAX_LINE_LENGTH + 1]; | 88 char buf[MAX_LINE_LENGTH + 2]; |
89 | 89 |
90 if (*certificate_list || *to_install || *to_remove) { | 90 if (*certificate_list || *to_install || *to_remove) { |
91 printf("Error invalid parameters\n"); | 91 printf("Error invalid parameters\n"); |
92 return -1; | 92 return -1; |
93 } | 93 } |
94 | 94 |
95 while (fgets(buf, MAX_LINE_LENGTH + 1, stdin)) { | 95 while (fgets(buf, MAX_LINE_LENGTH + 1, stdin)) { |
96 size_t len = strlen(buf); /* fgets ensures buf is terminated */ | 96 size_t len = strlen(buf); /* fgets ensures buf is terminated */ |
97 if (len < 2) { | 97 if (len <= 3) { |
98 printf("Line to short.\n"); | 98 printf("Line too short.\n"); |
99 return ERR_INVALID_INPUT; | 99 return ERR_INVALID_INPUT; |
100 } | 100 } |
101 if (lines_read ++ > MAX_LINES) { | 101 if (lines_read ++ > MAX_LINES) { |
102 printf("Too many lines\n"); | 102 printf("Too many lines\n"); |
103 return ERR_TOO_MUCH_INPUT; | 103 return ERR_TOO_MUCH_INPUT; |
104 } | 104 } |
105 | |
106 if (buf[len-2] != '\r') { | |
107 if (buf[len-1] != '\n') { | |
108 printf("Line too long.\n"); | |
109 return ERR_INVALID_INPUT; | |
110 } | |
111 buf[len-1] = '\r'; | |
112 buf[len] = '\n'; | |
113 buf[len+1] = '\0'; | |
114 len++; | |
115 } | |
116 | |
105 if (strcmp("-----BEGIN CERTIFICATE LIST-----\r\n", buf) == 0){ | 117 if (strcmp("-----BEGIN CERTIFICATE LIST-----\r\n", buf) == 0){ |
106 readingList = 1; | 118 readingList = 1; |
107 continue; | 119 continue; |
108 } | 120 } |
109 if (strcmp("-----END CERTIFICATE LIST-----\r\n", buf) == 0){ | 121 if (strcmp("-----END CERTIFICATE LIST-----\r\n", buf) == 0){ |