From ba6e6b33ddaf05d7b2a9ff73ebc02a83f02084f6 Mon Sep 17 00:00:00 2001 From: Nunuhara Cabbage Date: Sat, 7 Dec 2019 14:16:53 -0800 Subject: [PATCH] Fix buffer overflows --- ald.c | 2 +- string.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ald.c b/ald.c index 33eb849..b46e0a3 100644 --- a/ald.c +++ b/ald.c @@ -156,7 +156,7 @@ static int _ald_get(struct ald_archive *ar, int no, int *disk_out, int *dataptr_ int disk, ptr, dataptr, dataptr2; // check that index is within range of file map - if (no > ar->maxfile) + if (no < 0 || no >= ar->maxfile) return 0; // look up data in file map diff --git a/string.c b/string.c index 94c6f3c..d4540ad 100644 --- a/string.c +++ b/string.c @@ -284,7 +284,7 @@ void string_set_char(struct string **_str, int i, unsigned int c) str->size--; } else if (bytes_src == 2 && bytes_dst == 1) { // grow 1 byte - str = xrealloc(str, sizeof(struct string) + str->size + 1); + str = xrealloc(str, sizeof(struct string) + str->size + 2); str->size++; *_str = str; for (int j = str->size; j > i; j--) {