*/
#include <algorithm>
-#include <common/compat/endian.h>
-#include <common/error.h>
-#include <common/lttng-elf.h>
-#include <common/macros.h>
-#include <common/readwrite.h>
+#include <common/compat/endian.hpp>
+#include <common/error.hpp>
+#include <common/lttng-elf.hpp>
+#include <common/macros.hpp>
+#include <common/readwrite.hpp>
#include <fcntl.h>
#include <stdbool.h>
#include <stdint.h>
#define EV_NUM 2
#endif
+namespace {
struct lttng_elf_ehdr {
uint16_t e_type;
uint16_t e_machine;
uint64_t st_value;
uint64_t st_size;
};
+} /* namespace */
struct lttng_elf {
int fd;
* We found the length of the section name, now seek back to the
* beginning of the name and copy it in the newly allocated buffer.
*/
- name = (char *)zmalloc(sizeof(char) * (name_length + 1)); /* + 1 for \0 */
+ name = calloc<char>((name_length + 1)); /* + 1 for \0 */
if (!name) {
PERROR("Error allocating ELF section name buffer");
goto error;
goto end;
}
- elf->ehdr = (lttng_elf_ehdr *) zmalloc(sizeof(struct lttng_elf_ehdr));
+ elf->ehdr = zmalloc<lttng_elf_ehdr>();
if (!elf->ehdr) {
PERROR("Error allocation buffer for ELF header");
ret = LTTNG_ERR_NOMEM;
goto error;
}
- elf = (lttng_elf *) zmalloc(sizeof(struct lttng_elf));
+ elf = zmalloc<lttng_elf>();
if (!elf) {
PERROR("Error allocating struct lttng_elf");
goto error;
max_alloc_size);
goto error;
}
- data = (char *) zmalloc(shdr->sh_size);
+ data = calloc<char>(shdr->sh_size);
if (!data) {
PERROR("Error allocating buffer for ELF section data");
goto error;
}
/* Get the number of symbol in the table for the iteration. */
+ if (symtab_hdr.sh_entsize == 0) {
+ DBG("Invalid ELF string table entry size.");
+ ret = LTTNG_ERR_ELF_PARSING;
+ goto free_string_table_data;
+ }
+
sym_count = symtab_hdr.sh_size / symtab_hdr.sh_entsize;
/* Loop over all symbol. */