summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorasomers <asomers@FreeBSD.org>2017-07-07 15:09:08 +0000
committerasomers <asomers@FreeBSD.org>2017-07-07 15:09:08 +0000
commit173bac5bb31d4718be89f254d18b1e561f993845 (patch)
treef86c032af4e5c00aefa3e6d7b00fd829db669f4e
parent002f0e2689c0297acef6d9f709c7cc774b30fa24 (diff)
downloadFreeBSD-src-173bac5bb31d4718be89f254d18b1e561f993845.zip
FreeBSD-src-173bac5bb31d4718be89f254d18b1e561f993845.tar.gz
MFC r318790, r319336
r318790: Fix a buffer overflow in bootparamd(8) If /etc/bootparams contains a line with an excessively long pathname, and a client asks for that path, then bootparamd will overflow a buffer and crash while parsing that line. This is not remotely exploitable since it requires a malformed /etc/bootparams file. Reported by: Coverity CID: 1305954 Sponsored by: Spectra Logic Corp r319336: Fix uninitialized variable in bootparamd.c Restore line that was accidentally deleted in change 318790 Reported by: Coverity CID: 1375855 X-MFC-With: 318790 Sponsored by: Spectra Logic Corp
-rw-r--r--usr.sbin/bootparamd/bootparamd/bootparamd.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/usr.sbin/bootparamd/bootparamd/bootparamd.c b/usr.sbin/bootparamd/bootparamd/bootparamd.c
index 0921305..08cda8c 100644
--- a/usr.sbin/bootparamd/bootparamd/bootparamd.c
+++ b/usr.sbin/bootparamd/bootparamd/bootparamd.c
@@ -199,7 +199,10 @@ int blen;
int ch, pch, fid_len, res = 0;
int match = 0;
- char info[MAX_FILEID + MAX_PATH_LEN+MAX_MACHINE_NAME + 3];
+#define INFOLEN 1343
+ _Static_assert(INFOLEN >= MAX_FILEID + MAX_PATH_LEN+MAX_MACHINE_NAME + 3,
+ "INFOLEN isn't large enough");
+ char info[INFOLEN + 1];
bpf = fopen(bootpfile, "r");
if ( ! bpf )
@@ -252,7 +255,9 @@ int blen;
if (match) {
fid_len = strlen(fileid);
- while ( ! res && (fscanf(bpf,"%s", info)) > 0) { /* read a string */
+#define AS_FORMAT(d) "%" #d "s"
+#define REXPAND(d) AS_FORMAT(d) /* Force another preprocessor expansion */
+ while ( ! res && (fscanf(bpf, REXPAND(INFOLEN), info)) > 0) {
ch = getc(bpf); /* and a character */
if ( *info != '#' ) { /* Comment ? */
if (! strncmp(info, fileid, fid_len) && *(info + fid_len) == '=') {
OpenPOWER on IntegriCloud