From f304d611a84ecbcf80506b6268c13b96f144721f Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Sat, 21 May 2016 22:05:28 +0200 Subject: [PATCH] [vcom] Buffer overflow protection --- main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 0b74b8b..05edaf9 100644 --- a/main.c +++ b/main.c @@ -105,11 +105,10 @@ int run_ghdl(char *command, ...) { while(42){ ptr = buf - 1; - - do { // TODO: Overflow protection! + do { ptr++; *ptr = fgetc(proc); - } while (*ptr != '\0' && *ptr != '\n' && *ptr != -1); + } while (*ptr != '\0' && *ptr != '\n' && *ptr != -1 && ptr < buf + sizeof(buf)); if (*ptr == -1) break; *ptr = '\0';