diff --git a/src/basic/macro.h b/src/basic/macro.h index 99262e9206..13620a60bc 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -250,6 +250,10 @@ static inline int __coverity_check_and_return__(int condition) { #define sizeof_field(struct_type, member) sizeof(((struct_type *) 0)->member) #define endoffsetof_field(struct_type, member) (offsetof(struct_type, member) + sizeof_field(struct_type, member)) +/* Maximum buffer size needed for formatting an unsigned integer type as hex, including space for '0x' + * prefix and trailing NUL suffix. */ +#define HEXADECIMAL_STR_MAX(type) (2 + sizeof(type) * 2 + 1) + /* Returns the number of chars needed to format variables of the specified type as a decimal string. Adds in * extra space for a negative '-' prefix for signed types. Includes space for the trailing NUL. */ #define DECIMAL_STR_MAX(type) \ diff --git a/src/shared/coredump-util.c b/src/shared/coredump-util.c index bf8ea00b14..dc137317a9 100644 --- a/src/shared/coredump-util.c +++ b/src/shared/coredump-util.c @@ -158,9 +158,9 @@ int parse_auxv(int log_level, } int set_coredump_filter(uint64_t value) { - char t[STRLEN("0xFFFFFFFF")]; + char t[HEXADECIMAL_STR_MAX(uint64_t)]; - sprintf(t, "0x%"PRIx64, value); + xsprintf(t, "0x%"PRIx64, value); return write_string_file("/proc/self/coredump_filter", t, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_DISABLE_BUFFER);