Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Jun 2010 12:50:54 +0000 (UTC)
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r209392 - head/sbin/geom/misc
Message-ID:  <201006211250.o5LCosXr027115@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ae
Date: Mon Jun 21 12:50:54 2010
New Revision: 209392
URL: http://svn.freebsd.org/changeset/base/209392

Log:
  Check for overflow before it occurs. Also add check for
  negative numbers.
  
  Suggested by:	ache
  Approved by:	kib (mentor)

Modified:
  head/sbin/geom/misc/subr.c

Modified: head/sbin/geom/misc/subr.c
==============================================================================
--- head/sbin/geom/misc/subr.c	Mon Jun 21 10:43:13 2010	(r209391)
+++ head/sbin/geom/misc/subr.c	Mon Jun 21 12:50:54 2010	(r209392)
@@ -139,7 +139,7 @@ g_parse_lba(const char *lbastr, unsigned
 	assert(sectors != NULL);
 
 	number = (off_t)strtoimax(lbastr, &s, 0);
-	if (s == lbastr)
+	if (s == lbastr || number < 0)
 		return (EINVAL);
 
 	mult = 1;
@@ -187,7 +187,7 @@ sfx:
 	if (*s != '\0')
 		return (EINVAL);
 done:
-	if (mult * unit < mult || number * mult * unit < number)
+	if ((OFF_MAX / unit) < mult || (OFF_MAX / mult / unit) < number)
 		return (ERANGE);
 	number *= mult * unit;
 	if (number % sectorsize)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201006211250.o5LCosXr027115>