From 1a0594c62f94c782f81476f28bb1543b7303fe20 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Thu, 2 Feb 2017 07:22:59 +0000 Subject: [PATCH] Fix reading stdin buffers larger than 1000. Patch by https://github.com/ChliHug. --- CHANGELOG.md | 4 ++++ src/espeak-ng.c | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7eb1fd4..7d8f2f96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ The espeak-ng project is a fork of the espeak project. * Removed support for phoneme equivalence tables. These were disabled in the French and German language files. +bug fixes: + +* Fix reading stdin buffers larger than 1000. + updated languages: * af (Afrikaans) -- Christo de Klerk diff --git a/src/espeak-ng.c b/src/espeak-ng.c index a657aff5..94c62513 100644 --- a/src/espeak-ng.c +++ b/src/espeak-ng.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -674,7 +675,7 @@ int main(int argc, char **argv) size = strlen(p_text); espeak_Synth(p_text, size+1, 0, POS_CHARACTER, 0, synth_flags, NULL, NULL); } else if (flag_stdin) { - int max = 1000; + size_t max = 1000; if ((p_text = (char *)malloc(max)) == NULL) { espeak_ng_PrintStatusCodeMessage(ENOMEM, stderr, NULL); exit(EXIT_FAILURE); @@ -697,13 +698,17 @@ int main(int argc, char **argv) break; p_text[ix++] = (char)c; if (ix >= (max-1)) { - max += 1000; - char *new_text = (char *)realloc(p_text, max); + char *new_text = NULL; + if (max <= SIZE_MAX - 1000) { + max += 1000; + new_text = (char *)realloc(p_text, max); + } if (new_text == NULL) { free(p_text); espeak_ng_PrintStatusCodeMessage(ENOMEM, stderr, NULL); exit(EXIT_FAILURE); } + p_text = new_text; } } if (ix > 0) {