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>
This commit is contained in:
parent
9c76f85f9a
commit
6d00cfb233
|
@ -14,6 +14,7 @@ dist_noinst_HEADERS += \
|
||||||
include/crc32.h \
|
include/crc32.h \
|
||||||
include/crc32c.h \
|
include/crc32c.h \
|
||||||
include/debug.h \
|
include/debug.h \
|
||||||
|
include/debugobj.h \
|
||||||
include/env.h \
|
include/env.h \
|
||||||
include/exec_shell.h \
|
include/exec_shell.h \
|
||||||
include/exitcodes.h \
|
include/exitcodes.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_DEFINE_MASKNAMES(m) static const struct ul_debug_maskname m ## _masknames[]
|
||||||
#define UL_DEBUG_MASKNAMES(m) 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)
|
#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 */
|
/* l - library name, p - flag prefix, m - flag postfix, x - function */
|
||||||
#define __UL_DBG(l, p, m, x) \
|
#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); \
|
lib ## _debug_mask = ul_debug_parse_envmask(lib ## _masknames, str); \
|
||||||
} else \
|
} else \
|
||||||
lib ## _debug_mask = mask; \
|
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; \
|
lib ## _debug_mask |= pref ## INIT; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
@ -104,19 +112,6 @@ ul_debug(const char *mesg, ...)
|
||||||
fputc('\n', stderr);
|
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(
|
static inline int ul_debug_parse_envmask(
|
||||||
const struct ul_debug_maskname flagnames[],
|
const struct ul_debug_maskname flagnames[],
|
||||||
const char *mask)
|
const char *mask)
|
||||||
|
|
|
@ -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 */
|
|
@ -57,6 +57,9 @@ UL_DEBUG_DEFINE_MASKNAMES(loopdev) = UL_DEBUG_EMPTY_MASKNAMES;
|
||||||
#define DBG(m, x) __UL_DBG(loopdev, LOOPDEV_DEBUG_, m, x)
|
#define DBG(m, x) __UL_DBG(loopdev, LOOPDEV_DEBUG_, m, x)
|
||||||
#define ON_DBG(m, x) __UL_DBG_CALL(loopdev, LOOPDEV_DEBUG_, m, x)
|
#define ON_DBG(m, x) __UL_DBG_CALL(loopdev, LOOPDEV_DEBUG_, m, x)
|
||||||
|
|
||||||
|
#define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(loopdev)
|
||||||
|
#include "debugobj.h"
|
||||||
|
|
||||||
static void loopdev_init_debug(void)
|
static void loopdev_init_debug(void)
|
||||||
{
|
{
|
||||||
if (loopdev_debug_mask)
|
if (loopdev_debug_mask)
|
||||||
|
|
|
@ -338,6 +338,9 @@ UL_DEBUG_DECLARE_MASK(libblkid);
|
||||||
#define DBG(m, x) __UL_DBG(libblkid, BLKID_DEBUG_, m, x)
|
#define DBG(m, x) __UL_DBG(libblkid, BLKID_DEBUG_, m, x)
|
||||||
#define ON_DBG(m, x) __UL_DBG_CALL(libblkid, BLKID_DEBUG_, m, x)
|
#define ON_DBG(m, x) __UL_DBG_CALL(libblkid, BLKID_DEBUG_, m, x)
|
||||||
|
|
||||||
|
#define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(libblkid)
|
||||||
|
#include "debugobj.h"
|
||||||
|
|
||||||
extern void blkid_debug_dump_dev(blkid_dev dev);
|
extern void blkid_debug_dump_dev(blkid_dev dev);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,9 @@ UL_DEBUG_DECLARE_MASK(libfdisk);
|
||||||
#define ON_DBG(m, x) __UL_DBG_CALL(libfdisk, LIBFDISK_DEBUG_, m, x)
|
#define ON_DBG(m, x) __UL_DBG_CALL(libfdisk, LIBFDISK_DEBUG_, m, x)
|
||||||
#define DBG_FLUSH __UL_DBG_FLUSH(libfdisk, LIBFDISK_DEBUG_)
|
#define DBG_FLUSH __UL_DBG_FLUSH(libfdisk, LIBFDISK_DEBUG_)
|
||||||
|
|
||||||
|
#define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(libfdisk)
|
||||||
|
#include "debugobj.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NLS -- the library has to be independent on main program, so define
|
* NLS -- the library has to be independent on main program, so define
|
||||||
* UL_TEXTDOMAIN_EXPLICIT before you include nls.h.
|
* UL_TEXTDOMAIN_EXPLICIT before you include nls.h.
|
||||||
|
|
|
@ -50,6 +50,9 @@ UL_DEBUG_DECLARE_MASK(libmount);
|
||||||
#define ON_DBG(m, x) __UL_DBG_CALL(libmount, MNT_DEBUG_, m, x)
|
#define ON_DBG(m, x) __UL_DBG_CALL(libmount, MNT_DEBUG_, m, x)
|
||||||
#define DBG_FLUSH __UL_DBG_FLUSH(libmount, MNT_DEBUG_)
|
#define DBG_FLUSH __UL_DBG_FLUSH(libmount, MNT_DEBUG_)
|
||||||
|
|
||||||
|
#define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(libmount)
|
||||||
|
#include "debugobj.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NLS -- the library has to be independent on main program, so define
|
* NLS -- the library has to be independent on main program, so define
|
||||||
* UL_TEXTDOMAIN_EXPLICIT before you include nls.h.
|
* UL_TEXTDOMAIN_EXPLICIT before you include nls.h.
|
||||||
|
|
|
@ -36,6 +36,9 @@ UL_DEBUG_DECLARE_MASK(libsmartcols);
|
||||||
#define ON_DBG(m, x) __UL_DBG_CALL(libsmartcols, SCOLS_DEBUG_, m, x)
|
#define ON_DBG(m, x) __UL_DBG_CALL(libsmartcols, SCOLS_DEBUG_, m, x)
|
||||||
#define DBG_FLUSH __UL_DBG_FLUSH(libsmartcols, SCOLS_DEBUG_)
|
#define DBG_FLUSH __UL_DBG_FLUSH(libsmartcols, SCOLS_DEBUG_)
|
||||||
|
|
||||||
|
#define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(libsmartcols)
|
||||||
|
#include "debugobj.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic iterator
|
* Generic iterator
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -75,6 +75,8 @@ UL_DEBUG_DEFINE_MASKNAMES(lsblk) = UL_DEBUG_EMPTY_MASKNAMES;
|
||||||
#define DBG(m, x) __UL_DBG(lsblk, LSBLK_DEBUG_, m, x)
|
#define DBG(m, x) __UL_DBG(lsblk, LSBLK_DEBUG_, m, x)
|
||||||
#define ON_DBG(m, x) __UL_DBG_CALL(lsblk, LSBLK_DEBUG_, m, x)
|
#define ON_DBG(m, x) __UL_DBG_CALL(lsblk, LSBLK_DEBUG_, m, x)
|
||||||
|
|
||||||
|
#define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(lsblk)
|
||||||
|
#include "debugobj.h"
|
||||||
|
|
||||||
#define LSBLK_EXIT_SOMEOK 64
|
#define LSBLK_EXIT_SOMEOK 64
|
||||||
#define LSBLK_EXIT_ALLFAILED 32
|
#define LSBLK_EXIT_ALLFAILED 32
|
||||||
|
|
|
@ -72,6 +72,9 @@ UL_DEBUG_DEFINE_MASKNAMES(whereis) = UL_DEBUG_EMPTY_MASKNAMES;
|
||||||
#define DBG(m, x) __UL_DBG(whereis, WHEREIS_DEBUG_, m, x)
|
#define DBG(m, x) __UL_DBG(whereis, WHEREIS_DEBUG_, m, x)
|
||||||
#define ON_DBG(m, x) __UL_DBG_CALL(whereis, WHEREIS_DEBUG_, m, x)
|
#define ON_DBG(m, x) __UL_DBG_CALL(whereis, WHEREIS_DEBUG_, m, x)
|
||||||
|
|
||||||
|
#define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(whereis)
|
||||||
|
#include "debugobj.h"
|
||||||
|
|
||||||
static char uflag = 0;
|
static char uflag = 0;
|
||||||
|
|
||||||
/* supported types */
|
/* supported types */
|
||||||
|
|
|
@ -66,6 +66,9 @@ UL_DEBUG_DEFINE_MASKNAMES(lsns) = UL_DEBUG_EMPTY_MASKNAMES;
|
||||||
#define DBG(m, x) __UL_DBG(lsns, LSNS_DEBUG_, m, x)
|
#define DBG(m, x) __UL_DBG(lsns, LSNS_DEBUG_, m, x)
|
||||||
#define ON_DBG(m, x) __UL_DBG_CALL(lsns, LSNS_DEBUG_, m, x)
|
#define ON_DBG(m, x) __UL_DBG_CALL(lsns, LSNS_DEBUG_, m, x)
|
||||||
|
|
||||||
|
#define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(lsns)
|
||||||
|
#include "debugobj.h"
|
||||||
|
|
||||||
static struct idcache *uid_cache = NULL;
|
static struct idcache *uid_cache = NULL;
|
||||||
|
|
||||||
/* column IDs */
|
/* column IDs */
|
||||||
|
|
Loading…
Reference in New Issue