Skip to contentSkip to conversation

catch errors

PATCH Ulrich Drepper 1 participant 1 message Aug 29, 2007 SELinux security module

lore
Share & tools
lore
#0 lore raw

Given the buffer overflow which has been fixed recently I think it's worthwhile adding to debug features. It's using the same technology as glibc's _FORTIFY_SOURCE functionality. I would unconditionally define DEBUG, in most cases the compiler can figure out there is no problem.

Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
src/private.h +10 -0
diff -durp libsepol-2.0.7/src/private.h libsepol-2.0.7-chk/src/private.h
@@ -45,3 +45,13 @@ extern struct policydb_compat_info *poli
 extern int next_entry(void *buf, struct policy_file *fp, size_t bytes) hidden;
 extern size_t put_entry(const void *ptr, size_t size, size_t n,
 		        struct policy_file *fp) hidden;
+
+#ifdef DEBUG
+# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR >= 1)
+#  define next_entry(buf, fp, bytes) \
+  ({ size_t _bytes = bytes; \
+     __builtin_object_size (buf, 0) != (size_t) -1 && sizeof (buf) < _bytes \
+     ? (abort (), -1) \
+     : next_entry (buf, fp, _bytes); })
+# endif
+#endif