diff options
author | Karel Zak | 2018-01-12 11:01:26 +0100 |
---|---|---|
committer | Karel Zak | 2018-01-12 11:01:26 +0100 |
commit | 6d00cfb2330cb47d00d350eedfbffbbf5991a743 (patch) | |
tree | 868f3ee9d066d0cf70339b0a693a4cda503a8dc1 /include | |
parent | libfdisk: allow to start freespace for zero (diff) | |
download | kernel-qcow2-util-linux-6d00cfb2330cb47d00d350eedfbffbbf5991a743.tar.gz kernel-qcow2-util-linux-6d00cfb2330cb47d00d350eedfbffbbf5991a743.tar.xz kernel-qcow2-util-linux-6d00cfb2330cb47d00d350eedfbffbbf5991a743.zip |
include/debug: don't print pointer address for SUID programs
* introduce new flag __UL_DEBUG_FL_NOADDR to suppress pointer address printing
* use __UL_DEBUG_FL_NOADDR when SUID
* move ul_debugobj() to debugobj.h, and require UL_DEBUG_CURRENT_MASK
to provide access to the current mask from ul_debugobj(). It's better
than modify all ul_debugobj() calls and use the global mask as
argument.
* remove never used UL_DEBUG_DEFINE_FLAG
Reported-by: halfdog <me@halfdog.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/Makemodule.am | 1 | ||||
-rw-r--r-- | include/debug.h | 27 | ||||
-rw-r--r-- | include/debugobj.h | 22 |
3 files changed, 34 insertions, 16 deletions
diff --git a/include/Makemodule.am b/include/Makemodule.am index cfea1457c..3e7f7a01e 100644 --- a/include/Makemodule.am +++ b/include/Makemodule.am @@ -14,6 +14,7 @@ dist_noinst_HEADERS += \ include/crc32.h \ include/crc32c.h \ include/debug.h \ + include/debugobj.h \ include/env.h \ include/exec_shell.h \ include/exitcodes.h \ diff --git a/include/debug.h b/include/debug.h index 97c0e1f08..07a8dcb2a 100644 --- a/include/debug.h +++ b/include/debug.h @@ -49,11 +49,15 @@ struct ul_debug_maskname { #define UL_DEBUG_DEFINE_MASKNAMES(m) static const struct ul_debug_maskname m ## _masknames[] #define UL_DEBUG_MASKNAMES(m) m ## _masknames -#define UL_DEBUG_DEFINE_MASK(m) int m ## _debug_mask +#define UL_DEBUG_MASK(m) m ## _debug_mask +#define UL_DEBUG_DEFINE_MASK(m) int UL_DEBUG_MASK(m) #define UL_DEBUG_DECLARE_MASK(m) extern UL_DEBUG_DEFINE_MASK(m) -/* p - flag prefix, m - flag postfix */ -#define UL_DEBUG_DEFINE_FLAG(p, m) p ## m +/* + * Internal mask flags (above 0xffffff) + */ +#define __UL_DEBUG_FL_NOADDR (1 << 24) /* Don't print object address */ + /* l - library name, p - flag prefix, m - flag postfix, x - function */ #define __UL_DBG(l, p, m, x) \ @@ -90,6 +94,10 @@ struct ul_debug_maskname { lib ## _debug_mask = ul_debug_parse_envmask(lib ## _masknames, str); \ } else \ lib ## _debug_mask = mask; \ + if (lib ## _debug_mask) { \ + if (getuid() != geteuid() || getgid() != getegid()) \ + lib ## _debug_mask |= __UL_DEBUG_FL_NOADDR; \ + } \ lib ## _debug_mask |= pref ## INIT; \ } while (0) @@ -104,19 +112,6 @@ ul_debug(const char *mesg, ...) fputc('\n', stderr); } -static inline void __attribute__ ((__format__ (__printf__, 2, 3))) -ul_debugobj(const void *handler, const char *mesg, ...) -{ - va_list ap; - - if (handler) - fprintf(stderr, "[%p]: ", handler); - va_start(ap, mesg); - vfprintf(stderr, mesg, ap); - va_end(ap); - fputc('\n', stderr); -} - static inline int ul_debug_parse_envmask( const struct ul_debug_maskname flagnames[], const char *mask) diff --git a/include/debugobj.h b/include/debugobj.h new file mode 100644 index 000000000..73b70b8df --- /dev/null +++ b/include/debugobj.h @@ -0,0 +1,22 @@ +#ifndef UTIL_LINUX_DEBUGOBJ_H +#define UTIL_LINUX_DEBUGOBJ_H + +/* + * Include *after* debug.h and after UL_DEBUG_CURRENT_MASK define. + */ + +static inline void __attribute__ ((__format__ (__printf__, 2, 3))) +ul_debugobj(const void *handler, const char *mesg, ...) +{ + va_list ap; + + if (handler && !(UL_DEBUG_CURRENT_MASK & __UL_DEBUG_FL_NOADDR)) + fprintf(stderr, "[%p]: ", handler); + + va_start(ap, mesg); + vfprintf(stderr, mesg, ap); + va_end(ap); + fputc('\n', stderr); +} + +#endif /* UTIL_LINUX_DEBUGOBJ_H */ |