/* Find debugging and symbol information for a module in libdwfl.
Copyright (C) 2005-2012, 2014, 2015, 2025 Red Hat, Inc.
+ Copyright (C) 2025 Mark J. Wielaard <mark@klomp.org>
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
}
}
+/* This is a string section/segment, so we want to make sure the last
+ valid index contains a zero character to terminate a string. */
+static void
+validate_strdata (Elf_Data *symstrdata)
+{
+ size_t size = symstrdata->d_size;
+ const char *buf = symstrdata->d_buf;
+ while (size > 0 && *(buf + size - 1) != '\0')
+ --size;
+ symstrdata->d_size = size;
+}
+
+
/* Various addresses we might want to pull from the dynamic segment. */
enum
{
ELF_T_BYTE);
if (mod->symstrdata == NULL)
mod->symdata = NULL;
+ else
+ validate_strdata (mod->symstrdata);
}
if (mod->symdata == NULL)
mod->symerr = DWFL_E (LIBELF, elf_errno ());
mod->symstrdata = elf_getdata (symstrscn, NULL);
if (mod->symstrdata == NULL || mod->symstrdata->d_buf == NULL)
goto elferr;
+ else
+ validate_strdata (mod->symstrdata);
if (xndxscn == NULL)
mod->symxndxdata = NULL;
mod->aux_symstrdata = elf_getdata (aux_strscn, NULL);
if (mod->aux_symstrdata == NULL || mod->aux_symstrdata->d_buf == NULL)
goto aux_cleanup;
+ else
+ validate_strdata (mod->aux_symstrdata);
if (aux_xndxscn == NULL)
mod->aux_symxndxdata = NULL;