diff options
author | Daiki Ueno <ueno@gnu.org> | 2016-06-01 15:54:42 +0900 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2016-06-01 15:56:40 +0900 |
commit | 0fd6d55c8dad45900405861b792647a839d1ccd6 (patch) | |
tree | b3ad3af4de6360e6b48d28f2c240115ca297c277 | |
parent | 37eaf300e55c077aa4ad427b2f9d5c66923526dd (diff) | |
download | external_gettext-0fd6d55c8dad45900405861b792647a839d1ccd6.zip external_gettext-0fd6d55c8dad45900405861b792647a839d1ccd6.tar.gz external_gettext-0fd6d55c8dad45900405861b792647a839d1ccd6.tar.bz2 |
tests: Check invalid input in sentence-1-prg
* gettext-tools/tests/sentence-1-prg.c (main): Check input buffer
overflow, while it is not possible with the current test case.
-rw-r--r-- | gettext-tools/tests/sentence-1-prg.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/gettext-tools/tests/sentence-1-prg.c b/gettext-tools/tests/sentence-1-prg.c index e3d3360..84675e0 100644 --- a/gettext-tools/tests/sentence-1-prg.c +++ b/gettext-tools/tests/sentence-1-prg.c @@ -28,35 +28,49 @@ int main (int argc, char **argv) { - char buffer[1024]; - while (1) { + char buffer[1024]; const char *result; ucs4_t ending_char; - char *p; + char *p, *newline; + + memset (buffer, 0, sizeof buffer); - if (!fgets (buffer, sizeof buffer, stdin)) + /* Read REQUIRED_SPACES parameter. */ + if (!fgets (buffer, sizeof (buffer) - 1, stdin)) break; + newline = strchr (buffer, '\n'); + if (!newline) + return 1; + *newline = '\0'; + sentence_end_required_spaces = atoi (buffer); - memset (buffer, 0, sizeof buffer); + /* Collect lines until an empty line is read. */ p = buffer; while (1) { - p = fgets (p, sizeof buffer - (buffer - p), stdin); - if (p == NULL) + p = fgets (p, sizeof (buffer) - (p - buffer) - 1, stdin); + if (!p) break; + if (*p == '\n') break; - p = strchr (p, '\n') + 1; + + newline = strchr (p, '\n'); + if (!newline) + return 1; + + p = newline + 1; + *p = '\0'; } + if (p == NULL) break; - *(p - 1) = '\0'; - + *newline = '\0'; result = sentence_end (buffer, &ending_char); printf ("%X\n%s\n\n", ending_char, result); } |