From a0eeb184e4277b15e4408c2b29db150dcf42f6bb Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Mon, 2 Dec 2024 21:23:30 +0100 Subject: truncate_file: fixed a possible array overrun --- FICS/utils.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'FICS/utils.c') diff --git a/FICS/utils.c b/FICS/utils.c index d9fac79..992e410 100644 --- a/FICS/utils.c +++ b/FICS/utils.c @@ -789,11 +789,8 @@ truncate_file(char *file, int lines) if ((fp = fopen(file, "r")) == NULL) return 1; - while (!feof(fp)) { - if (fgets(tBuf[bptr], MAX_LINE_SIZE, fp) == NULL || feof(fp)) - break; - - if (tBuf[bptr][strlen(tBuf[bptr]) - 1] != '\n') { + while (fgets(tBuf[bptr], MAX_LINE_SIZE, fp) != NULL) { + if (strchr(tBuf[bptr], '\n') == NULL) { // Line too long fclose(fp); return -1; -- cgit v1.2.3