extend checks of ensuring there's valid CTF data before attempting to use it.
authorjasper <jasper@openbsd.org>
Wed, 27 Oct 2021 21:21:35 +0000 (21:21 +0000)
committerjasper <jasper@openbsd.org>
Wed, 27 Oct 2021 21:21:35 +0000 (21:21 +0000)
sys/ddb/db_ctf.c

index 7b844f8..ddb7ae8 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: db_ctf.c,v 1.30 2020/10/15 03:14:00 deraadt Exp $     */
+/*     $OpenBSD: db_ctf.c,v 1.31 2021/10/27 21:21:35 jasper Exp $      */
 
 /*
  * Copyright (c) 2016-2017 Martin Pieuchot
@@ -248,13 +248,15 @@ const struct ctf_type *
 db_ctf_type_by_symbol(Elf_Sym *st)
 {
        Elf_Sym                 *symp;
-       uint32_t                 objtoff = db_ctf.cth->cth_objtoff;
+       uint32_t                 objtoff;
        uint16_t                *dsp;
        size_t                   idx = 0;
 
        if (!db_ctf.ctf_found || st == NULL)
                return NULL;
 
+       objtoff = db_ctf.cth->cth_objtoff;
+
        while (objtoff < db_ctf.cth->cth_funcoff) {
                dsp = (uint16_t *)(db_ctf.data + objtoff);
 
@@ -493,6 +495,9 @@ db_ctf_off2name(uint32_t offset)
 {
        const char              *name;
 
+       if (!db_ctf.ctf_found)
+               return NULL;
+
        if (CTF_NAME_STID(offset) != CTF_STRTAB_0)
                return "external";