Fix ubsan warning on null pointer usage
For the allocation of a new revocation entry, hiba-grl passes a NULL
pointer as source of memcpy(), triggering a ubsan warning.
Since it also passes a size of zero, this did not actually trigger any
error condition, but should be fixed nonetheless.
The warning in question is:
revocations.c:439:3: runtime error: null pointer passed as argument 2, which is declared to never be null
diff --git a/revocations.c b/revocations.c
index 5858588..2cc93ec 100644
--- a/revocations.c
+++ b/revocations.c
@@ -434,9 +434,13 @@
char *prev_map = r->map;
debug2("hibagrl_revoke_grant: resizing map to %d", required_size);
r->map = calloc(required_size, 1);
- memcpy(r->map, prev_map, r->size);
+ if (prev_map) {
+ /* if we already add revocations for this serial, we
+ * must copy them. */
+ memcpy(r->map, prev_map, r->size);
+ free(prev_map);
+ }
r->size = required_size;
- free(prev_map);
}
/* Add our grants. */
for (i = lo; i <= hi; ++i) {