commit - 7fc9410615d293f182da728eb3576f2e228cbfcb
commit + fcbb06bf6925b542428b937afc9f37446058e748
blob - 8dd2c6be9a9fa4eb0d7a42d3cfbb8ba4b61a9d36
blob + d4924b840343815bf194883e5d6cf8f4354da288
--- gotd/repo_write.c
+++ gotd/repo_write.c
imsg_init(&ibuf, client->fd);
- refname = malloc(iref.name_len + 1);
+ refname = strndup(imsg->data + sizeof(iref), iref.name_len);
if (refname == NULL)
- return got_error_from_errno("malloc");
- memcpy(refname, imsg->data + sizeof(iref), iref.name_len);
- refname[iref.name_len] = '\0';
+ return got_error_from_errno("strndup");
ref_update = calloc(1, sizeof(*ref_update));
if (ref_update == NULL) {
blob - a1e9bda45d13cafee15c71ea7364217a9a432442
blob + 2b98e5b861a9809ce19718d8a1895fa536f61c7f
--- gotd/session.c
+++ gotd/session.c
memcpy(&iref, imsg->data, sizeof(iref));
if (datalen != sizeof(iref) + iref.name_len)
return got_error(GOT_ERR_PRIVSEP_LEN);
- refname = malloc(iref.name_len + 1);
+ refname = strndup(imsg->data + sizeof(iref), iref.name_len);
if (refname == NULL)
- return got_error_from_errno("malloc");
- memcpy(refname, imsg->data + sizeof(iref), iref.name_len);
- refname[iref.name_len] = '\0';
+ return got_error_from_errno("strndup");
log_debug("updating ref %s for uid %d", refname, client->euid);
if (datalen != sizeof(icapa) + icapa.key_len + icapa.value_len)
return got_error(GOT_ERR_PRIVSEP_LEN);
- key = malloc(icapa.key_len + 1);
+ key = strndup(imsg->data + sizeof(icapa), icapa.key_len);
if (key == NULL)
- return got_error_from_errno("malloc");
+ return got_error_from_errno("strndup");
if (icapa.value_len > 0) {
- value = malloc(icapa.value_len + 1);
+ value = strndup(imsg->data + sizeof(icapa) + icapa.key_len,
+ icapa.value_len);
if (value == NULL) {
free(key);
- return got_error_from_errno("malloc");
+ return got_error_from_errno("strndup");
}
}
- memcpy(key, imsg->data + sizeof(icapa), icapa.key_len);
- key[icapa.key_len] = '\0';
- if (value) {
- memcpy(value, imsg->data + sizeof(icapa) + icapa.key_len,
- icapa.value_len);
- value[icapa.value_len] = '\0';
- }
-
capa = &client->capabilities[client->ncapabilities++];
capa->key = key;
capa->value = value;
blob - 9cee3eb3d8e8579efbc1af3b1c3a92cac95e4a9f
blob + 3874b5018ba6b20013787a2fbdc8c904ad198063
--- lib/gitconfig.c
+++ lib/gitconfig.c
*section = NULL;
return NULL;
}
- *section = malloc(i);
+ *section = strndup(line + 1, i - 1);
if (*section == NULL)
- return got_error_from_errno("malloc");
- strlcpy(*section, line + 1, i);
+ return got_error_from_errno("strndup");
return NULL;
}
while (isspace((unsigned char)*line))
blob - 5462fb412f766dfe4181df6346d61dc9b5a584fb
blob + 72df858a344baaa7631049c320a8bb04a3024eda
--- lib/privsep.c
+++ lib/privsep.c
case GOT_IMSG_GITCONFIG_STR_VAL:
if (datalen == 0)
break;
- /* datalen does not include terminating \0 */
- *str = malloc(datalen + 1);
+ *str = strndup(imsg.data, datalen);
if (*str == NULL) {
- err = got_error_from_errno("malloc");
+ err = got_error_from_errno("strndup");
break;
}
- memcpy(*str, imsg.data, datalen);
- (*str)[datalen] = '\0';
break;
default:
err = got_error(GOT_ERR_PRIVSEP_MSG);
case GOT_IMSG_GOTCONFIG_STR_VAL:
if (datalen == 0)
break;
- /* datalen does not include terminating \0 */
- *str = malloc(datalen + 1);
+ *str = strndup(imsg.data, datalen);
if (*str == NULL) {
- err = got_error_from_errno("malloc");
+ err = got_error_from_errno("strndup");
break;
}
- memcpy(*str, imsg.data, datalen);
- (*str)[datalen] = '\0';
break;
default:
err = got_error(GOT_ERR_PRIVSEP_MSG);
}
memcpy(tree_id.sha1, itree->id, sizeof(tree_id.sha1));
free(path);
- path = malloc(path_len + 1);
+ path = strndup(imsg.data + sizeof(*itree), path_len);
if (path == NULL) {
- err = got_error_from_errno("malloc");
+ err = got_error_from_errno("strndup");
break;
}
free(canon_path);
err = got_error_from_errno("malloc");
break;
}
- memcpy(path, (uint8_t *)imsg.data + sizeof(*itree),
- path_len);
- path[path_len] = '\0';
if (!got_path_is_absolute(path)) {
err = got_error(GOT_ERR_BAD_PATH);
break;
blob - f5547423081feef64d243f4fa9151ceaec1ce8c6
blob + 684b7ef9d5dcbc8a5abab29eaa64023cc4fb365c
--- lib/serve.c
+++ lib/serve.c
err = got_error(GOT_ERR_PRIVSEP_LEN);
goto done;
}
- refname = malloc(iref.name_len + 1);
+ refname = strndup(imsg.data + sizeof(iref),
+ iref.name_len);
if (refname == NULL) {
- err = got_error_from_errno("malloc");
+ err = got_error_from_errno("strndup");
goto done;
}
- memcpy(refname, imsg.data + sizeof(iref),
- iref.name_len);
- refname[iref.name_len] = '\0';
err = send_ref(outfd, iref.id, refname,
!sent_capabilities, client_is_reading,
NULL, chattygot);
symrefname != NULL || symreftarget != NULL)
break;
- symrefname = malloc(isymref.name_len + 1);
+ symrefname = strndup(imsg.data + sizeof(isymref),
+ isymref.name_len);
if (symrefname == NULL) {
err = got_error_from_errno("malloc");
goto done;
}
- memcpy(symrefname, imsg.data + sizeof(isymref),
- isymref.name_len);
- symrefname[isymref.name_len] = '\0';
- symreftarget = malloc(isymref.target_len + 1);
+ symreftarget = strndup(
+ imsg.data + sizeof(isymref) + isymref.name_len,
+ isymref.target_len);
if (symreftarget == NULL) {
- err = got_error_from_errno("malloc");
+ err = got_error_from_errno("strndup");
goto done;
}
- memcpy(symreftarget,
- imsg.data + sizeof(isymref) + isymref.name_len,
- isymref.target_len);
- symreftarget[isymref.target_len] = '\0';
if (asprintf(&symrefstr, "%s:%s", symrefname,
symreftarget) == -1) {
if (datalen != sizeof(istatus) + istatus.reason_len)
return got_error(GOT_ERR_PRIVSEP_LEN);
- reason = malloc(istatus.reason_len + 1);
+ reason = strndup(imsg->data + sizeof(istatus), istatus.reason_len);
if (reason == NULL) {
- err = got_error_from_errno("malloc");
+ err = got_error_from_errno("strndup");
goto done;
}
- memcpy(reason, imsg->data + sizeof(istatus), istatus.reason_len);
- reason[istatus.reason_len] = '\0';
if (err == NULL)
len = snprintf(buf, sizeof(buf), "unpack ok\n");
memcpy(&iok, imsg->data, sizeof(iok));
- refname = malloc(iok.name_len + 1);
+ refname = strndup(imsg->data + sizeof(iok), iok.name_len);
if (refname == NULL)
- return got_error_from_errno("malloc");
- memcpy(refname, imsg->data + sizeof(iok), iok.name_len);
- refname[iok.name_len] = '\0';
+ return got_error_from_errno("strndup");
len = snprintf(buf, sizeof(buf), "ok %s\n", refname);
if (len >= sizeof(buf)) {
memcpy(&ing, imsg->data, sizeof(ing));
- refname = malloc(ing.name_len + 1);
+ refname = strndup(imsg->data + sizeof(ing), ing.name_len);
if (refname == NULL)
- return got_error_from_errno("malloc");
- memcpy(refname, imsg->data + sizeof(ing), ing.name_len);
- refname[ing.name_len] = '\0';
+ return got_error_from_errno("strndup");
- reason = malloc(ing.reason_len + 1);
+ reason = strndup(imsg->data + sizeof(ing) + ing.name_len,
+ ing.reason_len);
if (reason == NULL) {
- err = got_error_from_errno("malloc");
+ err = got_error_from_errno("strndup");
goto done;
}
- memcpy(refname, imsg->data + sizeof(ing) + ing.name_len,
- ing.reason_len);
- refname[ing.reason_len] = '\0';
len = snprintf(buf, sizeof(buf), "ng %s %s\n", refname, reason);
if (len >= sizeof(buf)) {
blob - c2b23a762db0ab53b3f2b625b26efb74dddcd5c5
blob + dbfaae68ac376c1a772e9b1e6360ddf9decc1f3e
--- libexec/got-fetch-pack/got-fetch-pack.c
+++ libexec/got-fetch-pack/got-fetch-pack.c
err = got_error(GOT_ERR_PRIVSEP_LEN);
goto done;
}
- refname = malloc(href.name_len + 1);
+ refname = strndup(imsg.data + sizeof(href), href.name_len);
if (refname == NULL) {
- err = got_error_from_errno("malloc");
+ err = got_error_from_errno("strndup");
goto done;
}
- memcpy(refname, imsg.data + sizeof(href), href.name_len);
- refname[href.name_len] = '\0';
id = malloc(sizeof(*id));
if (id == NULL) {
err = got_error(GOT_ERR_PRIVSEP_LEN);
goto done;
}
- refname = malloc(wbranch.name_len + 1);
+ refname = strndup(imsg.data + sizeof(wbranch),
+ wbranch.name_len);
if (refname == NULL) {
- err = got_error_from_errno("malloc");
+ err = got_error_from_errno("strndup");
goto done;
}
- memcpy(refname, imsg.data + sizeof(wbranch), wbranch.name_len);
- refname[wbranch.name_len] = '\0';
err = got_pathlist_append(&wanted_branches, refname, NULL);
if (err) {
err = got_error(GOT_ERR_PRIVSEP_LEN);
goto done;
}
- refname = malloc(wref.name_len + 1);
+ refname = strndup(imsg.data + sizeof(wref), wref.name_len);
if (refname == NULL) {
- err = got_error_from_errno("malloc");
+ err = got_error_from_errno("strndup");
goto done;
}
- memcpy(refname, imsg.data + sizeof(wref), wref.name_len);
- refname[wref.name_len] = '\0';
err = got_pathlist_append(&wanted_refs, refname, NULL);
if (err) {