summaryrefslogtreecommitdiffstats
path: root/XAlloc.h
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2017-07-27 16:07:50 -0300
committerHisham Muhammad <hisham@gobolinux.org>2017-07-27 16:07:50 -0300
commit09e241fb1271021e3615512debd3136891547562 (patch)
tree8245b6084607a34185cfa7d3d45f5228937020f1 /XAlloc.h
parent3975e9ce5cba0e3972b2ddab28c198e000441501 (diff)
Security review: check results of snprintf.
Calls marked with xSnprintf shouldn't fail. Abort program cleanly if any of them does.
Diffstat (limited to 'XAlloc.h')
-rw-r--r--XAlloc.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/XAlloc.h b/XAlloc.h
index eaebb087..2ebee1a8 100644
--- a/XAlloc.h
+++ b/XAlloc.h
@@ -7,6 +7,7 @@
#define _GNU_SOURCE
#endif
+#include <err.h>
#include <assert.h>
#include <stdlib.h>
@@ -16,6 +17,8 @@ void* xCalloc(size_t nmemb, size_t size);
void* xRealloc(void* ptr, size_t size);
+#define xSnprintf(fmt, len, ...) do { int _l=len; int _n=snprintf(fmt, _l, __VA_ARGS__); if (!(_n > -1 && _n < _l)) { curs_set(1); endwin(); err(1, NULL); } } while(0)
+
#undef xStrdup
#undef xStrdup_
#ifdef NDEBUG

© 2014-2024 Faster IT GmbH | imprint | privacy policy