From: claudio Date: Wed, 21 Feb 2024 13:16:14 +0000 (+0000) Subject: Make sure dw_at2name() never returns NULL. This call is used in various X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=283ced89295eb8dc056ac371250a6c974c74a688;p=openbsd Make sure dw_at2name() never returns NULL. This call is used in various printf calls that clang decided to optimise into puts calls that crash with a NULL argument. Also add DW_AT_noreturn which caused this when running ./ctfconv -d ./ctfconv OK mpi@ --- diff --git a/usr.bin/ctfconv/dw.c b/usr.bin/ctfconv/dw.c index e1ee7bf11f0..9ebe9d95004 100644 --- a/usr.bin/ctfconv/dw.c +++ b/usr.bin/ctfconv/dw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dw.c,v 1.5 2021/10/25 19:54:29 kn Exp $ */ +/* $OpenBSD: dw.c,v 1.6 2024/02/21 13:16:14 claudio Exp $ */ /* * Copyright (c) 2016 Martin Pieuchot @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -184,6 +185,7 @@ const char * dw_at2name(uint64_t at) { static const char *dw_attrs[] = { DW_AT_NAMES }; + static char buf[64]; if (at <= nitems(dw_attrs)) return dw_attrs[at - 1]; @@ -193,7 +195,8 @@ dw_at2name(uint64_t at) if (at == DW_AT_hi_user) return "DW_AT_hi_user"; - return NULL; + snprintf(buf, sizeof(buf), "#%llu", at); + return buf; } const char * diff --git a/usr.bin/ctfconv/dwarf.h b/usr.bin/ctfconv/dwarf.h index 7da94aaebfa..ecb78873161 100644 --- a/usr.bin/ctfconv/dwarf.h +++ b/usr.bin/ctfconv/dwarf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dwarf.h,v 1.2 2017/08/11 14:58:56 jasper Exp $ */ +/* $OpenBSD: dwarf.h,v 1.3 2024/02/21 13:16:14 claudio Exp $ */ /* * Copyright (c) 2016 Martin Pieuchot @@ -273,6 +273,7 @@ #define DW_AT_const_expr 0x6c #define DW_AT_enum_class 0x6d #define DW_AT_linkage_name 0x6e +#define DW_AT_noreturn 0x87 #define DW_AT_lo_user 0x2000 #define DW_AT_hi_user 0x3fff @@ -413,6 +414,7 @@ "DW_AT_const_expr", \ "DW_AT_enum_class", \ "DW_AT_linkage_name", \ + [0x87 - 1] = "DW_AT_noreturn", \ #define DW_FORM_addr 0x01 #define DW_FORM_block2 0x03