diff options
author | Josh Haberman <jhaberman@gmail.com> | 2015-05-08 16:56:29 -0700 |
---|---|---|
committer | Josh Haberman <jhaberman@gmail.com> | 2015-05-08 16:56:29 -0700 |
commit | 3bd691a4975b2267ff04611507e766a7f9f87e83 (patch) | |
tree | e5628144f6f920d9ccf792a1499e55503e6ff4d2 /upb/table.c | |
parent | 87fc2c516bff207f880c71526926842fd8dcc77e (diff) |
Google-internal development.
Diffstat (limited to 'upb/table.c')
-rw-r--r-- | upb/table.c | 8 |
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; } |