svn commit: r283115 - head/sys/kern

Alan Somers asomers at FreeBSD.org
Tue May 19 16:23:48 UTC 2015


Author: asomers
Date: Tue May 19 16:23:47 2015
New Revision: 283115
URL: https://svnweb.freebsd.org/changeset/base/283115

Log:
  Properly null-terminate strings in a kernel dump header.  A version string
  longer than 192 bytes will cause the version field of a dump header to
  overflow. strncpy doesn't null terminate it, so savecore will print a
  corrupted info file. Using strlcpy fixes the bug.
  
  Differential Revision:	https://reviews.freebsd.org/D2560
  Reviewed by:		markj
  MFC after:		3 weeks
  Sponsored by:		Spectra Logic

Modified:
  head/sys/kern/kern_shutdown.c

Modified: head/sys/kern/kern_shutdown.c
==============================================================================
--- head/sys/kern/kern_shutdown.c	Tue May 19 15:43:20 2015	(r283114)
+++ head/sys/kern/kern_shutdown.c	Tue May 19 16:23:47 2015	(r283115)
@@ -873,16 +873,16 @@ mkdumpheader(struct kerneldumpheader *kd
 {
 
 	bzero(kdh, sizeof(*kdh));
-	strncpy(kdh->magic, magic, sizeof(kdh->magic));
-	strncpy(kdh->architecture, MACHINE_ARCH, sizeof(kdh->architecture));
+	strlcpy(kdh->magic, magic, sizeof(kdh->magic));
+	strlcpy(kdh->architecture, MACHINE_ARCH, sizeof(kdh->architecture));
 	kdh->version = htod32(KERNELDUMPVERSION);
 	kdh->architectureversion = htod32(archver);
 	kdh->dumplength = htod64(dumplen);
 	kdh->dumptime = htod64(time_second);
 	kdh->blocksize = htod32(blksz);
-	strncpy(kdh->hostname, prison0.pr_hostname, sizeof(kdh->hostname));
-	strncpy(kdh->versionstring, version, sizeof(kdh->versionstring));
+	strlcpy(kdh->hostname, prison0.pr_hostname, sizeof(kdh->hostname));
+	strlcpy(kdh->versionstring, version, sizeof(kdh->versionstring));
 	if (panicstr != NULL)
-		strncpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring));
+		strlcpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring));
 	kdh->parity = kerneldump_parity(kdh);
 }


More information about the svn-src-head mailing list