Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Oct 2018 23:44:39 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r339801 - head/usr.sbin/efivar
Message-ID:  <201810262344.w9QNieZN075517@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: imp
Date: Fri Oct 26 23:44:39 2018
New Revision: 339801
URL: https://svnweb.freebsd.org/changeset/base/339801

Log:
  Fix pointer arithmetic botch.
  
  Pointer subtraction to find size only works with char pointers.
  
  Noticed by: jhb@
  Sponsored by: Netflix, Inc

Modified:
  head/usr.sbin/efivar/efiutil.c

Modified: head/usr.sbin/efivar/efiutil.c
==============================================================================
--- head/usr.sbin/efivar/efiutil.c	Fri Oct 26 23:08:22 2018	(r339800)
+++ head/usr.sbin/efivar/efiutil.c	Fri Oct 26 23:44:39 2018	(r339801)
@@ -116,6 +116,8 @@ bindump(uint8_t *data, size_t datalen)
 
 #define LOAD_OPTION_ACTIVE 1
 
+#define SIZE(dp, edp) (size_t)((intptr_t)(void *)edp - (intptr_t)(void *)dp)
+
 void
 efi_print_load_option(uint8_t *data, size_t datalen, int Aflag, int bflag, int uflag)
 {
@@ -159,9 +161,8 @@ efi_print_load_option(uint8_t *data, size_t datalen, i
 	ucs2_to_utf8(descr, &str);
 	printf("%s", str);
 	free(str);
-	while (dp < edp && (size_t)(edp - dp) > sizeof(efidp_header)) {
-		efidp_format_device_path(buf, sizeof(buf), dp,
-		    (intptr_t)(void *)edp - (intptr_t)(void *)dp);
+	while (dp < edp && SIZE(dp, edp) > sizeof(efidp_header)) {
+		efidp_format_device_path(buf, sizeof(buf), dp, SIZE(dp, edp));
 		dp = (efidp)((char *)dp + efidp_size(dp));
 		printf(" %s\n", buf);
 	}



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