svn commit: r338473 - head/bin/sh

Jilles Tjoelker jilles at FreeBSD.org
Wed Sep 5 19:16:10 UTC 2018


Author: jilles
Date: Wed Sep  5 19:16:09 2018
New Revision: 338473
URL: https://svnweb.freebsd.org/changeset/base/338473

Log:
  sh: Fix formal overflow in pointer arithmetic
  
  The intention is to lower the value of the pointer, which according to ubsan
  cannot be done by adding an unsigned quantity.
  
  Reported by:	kevans
  Approved by:	re (kib)
  MFC after:	1 week

Modified:
  head/bin/sh/expand.c

Modified: head/bin/sh/expand.c
==============================================================================
--- head/bin/sh/expand.c	Wed Sep  5 19:05:30 2018	(r338472)
+++ head/bin/sh/expand.c	Wed Sep  5 19:16:09 2018	(r338473)
@@ -896,7 +896,7 @@ reprocess(int startloc, int flag, int subtype, int quo
 
 	startp = stackblock() + startloc;
 	len = expdest - startp;
-	if (len >= SIZE_MAX / 2)
+	if (len >= SIZE_MAX / 2 || len > PTRDIFF_MAX)
 		abort();
 	INTOFF;
 	if (len >= buflen) {
@@ -912,7 +912,7 @@ reprocess(int startloc, int flag, int subtype, int quo
 	INTON;
 	memcpy(buf, startp, len);
 	buf[len] = '\0';
-	STADJUST(-len, expdest);
+	STADJUST(-(ptrdiff_t)len, expdest);
 	for (zpos = 0;;) {
 		zlen = strlen(buf + zpos);
 		strtodest(buf + zpos, flag, subtype, quoted, dst);


More information about the svn-src-all mailing list