From a64e048c5170ca6be0527d47cd8718125d11344d Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Tue, 12 Jan 2016 07:27:43 +0000 Subject: [PATCH] Check malloc/realloc in the flag_stdin codepath of espeak-ng.c. --- src/espeak-ng.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/espeak-ng.c b/src/espeak-ng.c index 57c9f5b5..5f1b17a7 100644 --- a/src/espeak-ng.c +++ b/src/espeak-ng.c @@ -721,7 +721,10 @@ int main(int argc, char **argv) espeak_Synth(p_text, size+1, 0, POS_CHARACTER, 0, synth_flags, NULL, NULL); } else if (flag_stdin) { int max = 1000; - p_text = (char *)malloc(max); + if ((p_text = (char *)malloc(max)) == NULL) { + espeak_ng_PrintStatusCodeMessage(ENOMEM, stderr, NULL); + exit(EXIT_FAILURE); + } if (flag_stdin == 2) { // line by line input on stdin @@ -737,7 +740,12 @@ int main(int argc, char **argv) p_text[ix++] = fgetc(stdin); if (ix >= (max-1)) { max += 1000; - p_text = (char *)realloc(p_text, max); + char *new_text = (char *)realloc(p_text, max); + if (new_text == NULL) { + free(p_text); + espeak_ng_PrintStatusCodeMessage(ENOMEM, stderr, NULL); + exit(EXIT_FAILURE); + } } } if (ix > 0) {