summaryrefslogtreecommitdiff
path: root/upb/table.c
diff options
context:
space:
mode:
Diffstat (limited to 'upb/table.c')
-rw-r--r--upb/table.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/upb/table.c b/upb/table.c
index aa99fe2..fc69125 100644
--- a/upb/table.c
+++ b/upb/table.c
@@ -40,12 +40,16 @@ char *upb_strdup(const char *s) {
}
char *upb_strdup2(const char *s, size_t len) {
+ // Prevent overflow errors.
+ if (len == SIZE_MAX) return NULL;
// Always null-terminate, even if binary data; but don't rely on the input to
// have a null-terminating byte since it may be a raw binary buffer.
size_t n = len + 1;
char *p = malloc(n);
- if (p) memcpy(p, s, len);
- p[len] = 0;
+ if (p) {
+ memcpy(p, s, len);
+ p[len] = 0;
+ }
return p;
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback