diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-12-02 21:23:30 +0100 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-12-02 21:23:30 +0100 |
commit | a0eeb184e4277b15e4408c2b29db150dcf42f6bb (patch) | |
tree | 69f61a02e0dda3b26396d9424a5d0bca6b3002a6 | |
parent | b57978b307b88821ea1d7d7972e01537805f7d0c (diff) |
truncate_file: fixed a possible array overrun
-rw-r--r-- | FICS/utils.c | 7 |
1 files changed, 2 insertions, 5 deletions
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; |