commit - a47330a24a002793ebfd33553aeb80a98f940755
commit + c7b1723265fdbbef35d01135261fab2ca7d52f88
blob - b4f415940ee578ecafa1e8ceca60032674013904
blob + 3b225ca9384c228bc4e2ed56af6e1fbb67ff45d7
--- lib/object_parse.c
+++ lib/object_parse.c
GOT_OBJ_TYPE_TAG,
};
int type = 0;
- size_t size = 0, hdrlen = 0;
+ size_t size = 0;
size_t i;
+ char *end;
*obj = NULL;
- hdrlen = strnlen(buf, len) + 1 /* '\0' */;
- if (hdrlen > len)
+ end = memchr(buf, '\0', len);
+ if (end == NULL)
return got_error(GOT_ERR_BAD_OBJ_HDR);
for (i = 0; i < nitems(obj_labels); i++) {
size_t label_len = strlen(label);
const char *errstr;
- if (strncmp(buf, label, label_len) != 0)
+ if (len <= label_len || buf + label_len >= end ||
+ strncmp(buf, label, label_len) != 0)
continue;
type = obj_types[i];
- if (len <= label_len)
- return got_error(GOT_ERR_BAD_OBJ_HDR);
size = strtonum(buf + label_len, 0, LONG_MAX, &errstr);
if (errstr != NULL)
return got_error(GOT_ERR_BAD_OBJ_HDR);
if (*obj == NULL)
return got_error_from_errno("calloc");
(*obj)->type = type;
- (*obj)->hdrlen = hdrlen;
+ (*obj)->hdrlen = end - buf + 1;
(*obj)->size = size;
return NULL;
}
buf = malloc(zbsize);
if (buf == NULL)
return got_error_from_errno("malloc");
+ buf[0] = '\0';
err = got_inflate_init(&zb, buf, zbsize, NULL);
if (err)