From: Egor Date: Tue, 3 May 2022 08:10:05 +0000 (+0300) Subject: remove dumb null termination from append_strn X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=dd4fa2061d9bc29674f2f7aea0d2cf3becc7f897;p=patchyircd.git remove dumb null termination from append_strn literal buffer overrun --- diff --git a/util.c b/util.c index 73e84c1..df9b878 100644 --- a/util.c +++ b/util.c @@ -6,15 +6,12 @@ void append_strn(struct dynarr *d, const char *s, int len){ if (d->len + len > d->cap){ while (d->len + len > d->cap) d->cap *= 2; - void* ndata=realloc(d->buf, d->cap); - if(!ndata)abort(); + void *ndata = realloc(d->buf, d->cap); + if(!ndata) abort(); d->buf = ndata; } memcpy(d->buf + d->len, s, len); d->len += len; - // Null - d->buf[d->len] = 0; - d->buf[d->cap] = 0; } void append_str(struct dynarr *d, const char *s){ append_strn(d, s, strlen(s));