From: bluhm Date: Tue, 21 Sep 2021 21:33:35 +0000 (+0000) Subject: Add NUL termination to btfile content to avoid that strlcpy(3) reads X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=aa1e5e8822b5557a4f4f3cd9eb4cb6ce9f322860;p=openbsd Add NUL termination to btfile content to avoid that strlcpy(3) reads too much in btrace(8). OK mpi@ deraadt@ --- diff --git a/usr.sbin/btrace/btrace.c b/usr.sbin/btrace/btrace.c index 601b205a663..14a5212e2aa 100644 --- a/usr.sbin/btrace/btrace.c +++ b/usr.sbin/btrace/btrace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: btrace.c,v 1.56 2021/09/09 20:07:49 jasper Exp $ */ +/* $OpenBSD: btrace.c,v 1.57 2021/09/21 21:33:35 bluhm Exp $ */ /* * Copyright (c) 2019 - 2021 Martin Pieuchot @@ -228,7 +228,7 @@ read_btfile(const char *filename, size_t *len) err(1, "can't stat '%s'", filename); fsize = st.st_size; - fcontent = malloc(fsize); + fcontent = malloc(fsize + 1); if (fcontent == NULL) err(1, "malloc"); @@ -238,6 +238,7 @@ read_btfile(const char *filename, size_t *len) if (fread(fcontent, 1, fsize, fp) != fsize) err(1, "can't read '%s'", filename); + fcontent[fsize] = '\0'; fclose(fp); *len = fsize;