Skip to content

Commit

Permalink
libdrgn: dwarf_index: fix memcpy() undefined behavior
Browse files Browse the repository at this point in the history
Apparently, it's undefined behavior to pass NULL as the source to
memcpy(), even if the length is zero. It's an easy fix, so let's appease
UBSan.
  • Loading branch information
osandov committed Jul 15, 2019
1 parent 1d4854a commit a17215e
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions libdrgn/dwarf_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,15 +602,18 @@ static struct drgn_error *read_cus(struct drgn_dwarf_index *dindex,
}
}

#pragma omp critical(drgn_read_cus)
if (!err) {
if (compilation_unit_vector_reserve(all_cus,
all_cus->size + cus.size)) {
memcpy(all_cus->data + all_cus->size, cus.data,
cus.size * sizeof(*cus.data));
all_cus->size += cus.size;
} else {
err = &drgn_enomem;
if (cus.size) {
#pragma omp critical(drgn_read_cus)
if (!err) {
if (compilation_unit_vector_reserve(all_cus,
all_cus->size + cus.size)) {
memcpy(all_cus->data + all_cus->size,
cus.data,
cus.size * sizeof(*cus.data));
all_cus->size += cus.size;
} else {
err = &drgn_enomem;
}
}
}

Expand Down

0 comments on commit a17215e

Please sign in to comment.