Mercurial > trustbridge
comparison cinst/main.c @ 91:80ab2168760f
Also add output size handling to str_append_str
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 21 Mar 2014 09:47:05 +0000 |
parents | 899fcddb92d0 |
children | c602d8cfa619 |
comparison
equal
deleted
inserted
replaced
90:899fcddb92d0 | 91:80ab2168760f |
---|---|
58 int readInput(char **certificate_list, char ***to_install, | 58 int readInput(char **certificate_list, char ***to_install, |
59 char ***to_remove) | 59 char ***to_remove) |
60 { | 60 { |
61 int lines_read = 0; | 61 int lines_read = 0; |
62 int readingList = 0; | 62 int readingList = 0; |
63 size_t list_size = 0; | |
63 char buf[MAX_LINE_LENGTH + 1]; | 64 char buf[MAX_LINE_LENGTH + 1]; |
64 | 65 |
65 if (*certificate_list || *to_install || *to_remove) { | 66 if (*certificate_list || *to_install || *to_remove) { |
66 printf("Error invalid parameters\n"); | 67 printf("Error invalid parameters\n"); |
67 return -1; | 68 return -1; |
68 } | 69 } |
69 | 70 |
70 while (fgets(buf, MAX_LINE_LENGTH + 1, stdin)) { | 71 while (fgets(buf, MAX_LINE_LENGTH + 1, stdin)) { |
71 size_t len = strlen(buf); /* fgets ensures buf is terminated */ | 72 size_t len = strlen(buf); /* fgets ensures buf is terminated */ |
73 if (len < 2) { | |
74 printf("Line to short.\n"); | |
75 return ERR_INVALID_INPUT; | |
76 } | |
72 if (lines_read ++ > MAX_LINES) { | 77 if (lines_read ++ > MAX_LINES) { |
73 printf("Too many lines\n"); | 78 printf("Too many lines\n"); |
74 return ERR_TOO_MUCH_INPUT; | 79 return ERR_TOO_MUCH_INPUT; |
75 } | 80 } |
76 if (strcmp("-----BEGIN CERTIFICATE LIST-----\r\n", buf) == 0){ | 81 if (strcmp("-----BEGIN CERTIFICATE LIST-----\r\n", buf) == 0){ |
80 if (strcmp("-----END CERTIFICATE LIST-----\r\n", buf) == 0){ | 85 if (strcmp("-----END CERTIFICATE LIST-----\r\n", buf) == 0){ |
81 readingList = 0; | 86 readingList = 0; |
82 continue; | 87 continue; |
83 } | 88 } |
84 if (readingList) { | 89 if (readingList) { |
85 str_append_str(certificate_list, buf, len); | 90 str_append_str(certificate_list, &list_size, buf, len); |
86 continue; | 91 continue; |
87 } | 92 } |
88 if (*buf == 'I') { | 93 if (*buf == 'I') { |
89 /* Remove leading I: and trailing \r\n */ | 94 /* Remove leading I: and trailing \r\n */ |
90 array_append_str(to_install, buf+2, len - 4); | 95 array_append_str(to_install, buf+2, len - 4); |