svn commit: r290463 - head/sbin/savecore

Alan Somers asomers at FreeBSD.org
Fri Nov 6 19:18:22 UTC 2015


Author: asomers
Date: Fri Nov  6 19:18:20 2015
New Revision: 290463
URL: https://svnweb.freebsd.org/changeset/base/290463

Log:
  Always check the return value of lseek.
  
  This is a follow-up to r289845, which only fixed one occurence of CID
  1009429.
  
  Coverity CID:	1009429
  Reviewed by:	markj
  MFC after:	2 weeks
  X-MFC-With:	r289845
  Sponsored by:	Spectra Logic
  Differential Revision:	https://reviews.freebsd.org/D4096

Modified:
  head/sbin/savecore/savecore.c

Modified: head/sbin/savecore/savecore.c
==============================================================================
--- head/sbin/savecore/savecore.c	Fri Nov  6 18:50:01 2015	(r290462)
+++ head/sbin/savecore/savecore.c	Fri Nov  6 19:18:20 2015	(r290463)
@@ -491,9 +491,8 @@ DoFile(const char *savedir, const char *
 	}
 
 	lasthd = mediasize - sectorsize;
-	lseek(fd, lasthd, SEEK_SET);
-	error = read(fd, &kdhl, sizeof kdhl);
-	if (error != sizeof kdhl) {
+	if (lseek(fd, lasthd, SEEK_SET) != lasthd ||
+	    read(fd, &kdhl, sizeof(kdhl)) != sizeof(kdhl)) {
 		syslog(LOG_ERR,
 		    "error reading last dump header at offset %lld in %s: %m",
 		    (long long)lasthd, device);
@@ -569,9 +568,8 @@ DoFile(const char *savedir, const char *
 	}
 	dumpsize = dtoh64(kdhl.dumplength);
 	firsthd = lasthd - dumpsize - sizeof kdhf;
-	lseek(fd, firsthd, SEEK_SET);
-	error = read(fd, &kdhf, sizeof kdhf);
-	if (error != sizeof kdhf) {
+	if (lseek(fd, firsthd, SEEK_SET) != firsthd ||
+	    read(fd, &kdhf, sizeof(kdhf)) != sizeof(kdhf)) {
 		syslog(LOG_ERR,
 		    "error reading first dump header at offset %lld in %s: %m",
 		    (long long)firsthd, device);


More information about the svn-src-all mailing list