Make sure dw_at2name() never returns NULL. This call is used in various
authorclaudio <claudio@openbsd.org>
Wed, 21 Feb 2024 13:16:14 +0000 (13:16 +0000)
committerclaudio <claudio@openbsd.org>
Wed, 21 Feb 2024 13:16:14 +0000 (13:16 +0000)
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@

usr.bin/ctfconv/dw.c
usr.bin/ctfconv/dwarf.h

index e1ee7bf..9ebe9d9 100644 (file)
@@ -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 <errno.h>
 #include <stdint.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -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 *
index 7da94aa..ecb7887 100644 (file)
@@ -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 <mpi@openbsd.org>
 #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
 
        "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