[syslinux:elflink] SEG(): make SEG() puke on bad pointers if DEBUG is defined

syslinux-bot for H. Peter Anvin hpa at linux.intel.com
Fri Jun 29 09:42:02 PDT 2012


Commit-ID:  72842b681e7b9e8a26f683417520315595024f31
Gitweb:     http://www.syslinux.org/commit/72842b681e7b9e8a26f683417520315595024f31
Author:     H. Peter Anvin <hpa at linux.intel.com>
AuthorDate: Fri, 29 Jun 2012 09:40:48 -0700
Committer:  H. Peter Anvin <hpa at linux.intel.com>
CommitDate: Fri, 29 Jun 2012 09:40:48 -0700

SEG(): make SEG() puke on bad pointers if DEBUG is defined

SEG() and OFFS() should only be passed on lowmem pointers.  When DEBUG
is defined, make SEG() abort if we pass it a non-lowmem pointer.

Signed-off-by: H. Peter Anvin <hpa at linux.intel.com>

---
 com32/include/com32.h |   14 ++++++++++++++
 core/Makefile         |    2 +-
 2 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/com32/include/com32.h b/com32/include/com32.h
index 6b14208..4ba7ebd 100644
--- a/com32/include/com32.h
+++ b/com32/include/com32.h
@@ -135,10 +135,24 @@ char *lstrdup(const char *);
  * specific segment.  OFFS_VALID() will return whether or not the
  * pointer is actually reachable from the target segment.
  */
+#if defined(DEBUG) && (defined(__COM32__) || defined(__SYSLINUX_CORE__))
+#include <dprintf.h>
+__noreturn _kaboom(void);
+
+static inline uint16_t SEG(const volatile void *__p)
+{
+    if ((uintptr_t)__p > 0xfffff) {
+	dprintf("Non-lowmem pointer passed to SEG(): %p\n", __p);
+	_kaboom();
+    }
+    return (uint16_t) (((uintptr_t) __p) >> 4);
+}
+#else
 static inline uint16_t SEG(const volatile void *__p)
 {
     return (uint16_t) (((uintptr_t) __p) >> 4);
 }
+#endif
 
 static inline uint16_t OFFS(const volatile void *__p)
 {
diff --git a/core/Makefile b/core/Makefile
index 3898b4d..3147566 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -62,7 +62,7 @@ NASMOPT  += $(NASMDEBUG)
 
 PREPCORE = ../lzo/prepcore
 
-# CFLAGS	+= -DDEBUG=1
+CFLAGS	+= -DDEBUG=1 -D__SYSLINUX_CORE__
 
 # The DATE is set on the make command line when building binaries for
 # official release.  Otherwise, substitute a hex string that is pretty much


More information about the Syslinux-commits mailing list