commit - fd15d511a0647daea786c663e3f04d1e703e9eec3f1b845607fe201be5b25c1d
commit + e89c5ddbae4d5fd7e9d51feb3e66e4903c0b12301a3868e780be8c4e2d745a9e
blob - eeae60009b22d194c02bc41f3f7686ddb638c24993029fd7ce0e236848ce47b9
blob + 9c73715bd079bc280893b7ad642144f1fd71e41d073945d0c5b1fa7a0743e5da
--- lib/serve.c
+++ lib/serve.c
{
const struct got_error *err = NULL;
char hex[GOT_HASH_DIGEST_STRING_MAXLEN];
- char buf[GOT_PKT_MAX];
+ char *buf = NULL;
+ const size_t bufsize = GOT_PKT_MAX;
size_t len, capalen = 0;
if (got_hash_digest_to_str(id, hex, sizeof(hex), algo) == NULL)
return got_error(GOT_ERR_BAD_OBJ_ID);
- len = snprintf(buf, sizeof(buf), "%s %s", hex, refname);
- if (len >= sizeof(buf))
- return got_error(GOT_ERR_NO_SPACE);
+ buf = calloc(1, bufsize);
+ if (buf == NULL)
+ return got_error_from_errno("calloc");
+ len = snprintf(buf, bufsize, "%s %s", hex, refname);
+ if (len >= bufsize) {
+ err = got_error(GOT_ERR_NO_SPACE);
+ goto done;
+ }
+
if (send_capabilities) {
if (client_is_reading) {
err = append_read_capabilities(&capalen, len,
- symrefstr, buf, sizeof(buf), algo);
+ symrefstr, buf, bufsize, algo);
} else {
err = append_write_capabilities(&capalen, len,
- symrefstr, buf, sizeof(buf), algo);
+ symrefstr, buf, bufsize, algo);
}
if (err)
- return err;
+ goto done;
len += capalen;
}
- if (len + 1 >= sizeof(buf))
- return got_error(GOT_ERR_NO_SPACE);
+ if (len + 1 >= bufsize) {
+ err = got_error(GOT_ERR_NO_SPACE);
+ goto done;
+ }
buf[len] = '\n';
len++;
buf[len] = '\0';
- return got_pkt_writepkt(outfd, buf, len, chattygot);
+ err = got_pkt_writepkt(outfd, buf, len, chattygot);
+done:
+ free(buf);
+ return err;
}
static const struct got_error *
{
const struct got_error *err = NULL;
const char *line;
- char buf[GOT_PKT_MAX];
+ char *buf = NULL;
+ const size_t bufsize = GOT_PKT_MAX;
size_t len, capalen = 0;
if (algo == GOT_HASH_SHA1)
else
return got_error(GOT_ERR_OBJECT_FORMAT);
- len = strlcpy(buf, line, sizeof(buf));
- if (len >= sizeof(buf))
- return got_error(GOT_ERR_NO_SPACE);
+ buf = calloc(1, bufsize);
+ if (buf == NULL)
+ return got_error_from_errno("calloc");
+ len = strlcpy(buf, line, bufsize);
+ if (len >= bufsize) {
+ err = got_error(GOT_ERR_NO_SPACE);
+ goto done;
+ }
+
if (client_is_reading) {
err = append_read_capabilities(&capalen, len,
- NULL, buf, sizeof(buf), algo);
+ NULL, buf, bufsize, algo);
if (err)
- return err;
+ goto done;
} else {
err = append_write_capabilities(&capalen, len,
- NULL, buf, sizeof(buf), algo);
+ NULL, buf, bufsize, algo);
if (err)
- return err;
+ goto done;
}
- return got_pkt_writepkt(outfd, buf, len + capalen, chattygot);
+ err = got_pkt_writepkt(outfd, buf, len + capalen, chattygot);
+done:
+ free(buf);
+ return err;
}
static void
static const struct got_error *
send_ack(int outfd, uint8_t *id, int chattygot, int algo)
{
+ const struct got_error *err = NULL;
char hex[GOT_HASH_DIGEST_STRING_MAXLEN];
- char buf[GOT_PKT_MAX];
+ char *buf = NULL;
+ const size_t bufsize = GOT_PKT_MAX;
int len;
if (got_hash_digest_to_str(id, hex, sizeof(hex), algo) == NULL)
return got_error(GOT_ERR_BAD_OBJ_ID);
- len = snprintf(buf, sizeof(buf), "ACK %s\n", hex);
- if (len >= sizeof(buf))
- return got_error(GOT_ERR_NO_SPACE);
+ buf = calloc(1, bufsize);
+ if (buf == NULL)
+ return got_error_from_errno("calloc");
- return got_pkt_writepkt(outfd, buf, len, chattygot);
+ len = snprintf(buf, bufsize, "ACK %s\n", hex);
+ if (len >= bufsize) {
+ err = got_error(GOT_ERR_NO_SPACE);
+ goto done;
+ }
+
+ err = got_pkt_writepkt(outfd, buf, len, chattygot);
+done:
+ free(buf);
+ return err;
}
static const struct got_error *
const struct got_error *err = NULL;
int pack_starting = 0;
struct gotd_imsg_packfile_progress iprog;
- char buf[GOT_PKT_MAX];
+ char *buf = NULL;
+ const size_t bufsize = GOT_PKT_MAX;
struct imsg imsg;
size_t datalen;
int p_deltify = 0, n;
memset(&imsg, 0, sizeof(imsg));
+ buf = calloc(1, bufsize);
+ if (buf == NULL)
+ return got_error_from_errno("calloc");
+
while (!pack_starting && err == NULL) {
err = gotd_imsg_poll_recv(&imsg, ibuf, 0);
if (err)
iprog.nobj_total;
}
buf[0] = GOT_SIDEBAND_PROGRESS_INFO;
- n = snprintf(&buf[1], sizeof(buf) - 1,
+ n = snprintf(&buf[1], bufsize - 1,
"%d commits colored, "
"%d objects found, "
"deltify %d%%%s",
iprog.ncolored,
iprog.nfound,
p_deltify, eol);
- if (n >= sizeof(buf) - 1)
+ if (n >= bufsize - 1)
break;
err = got_pkt_writepkt(outfd, buf, 1 + n, chattygot);
break;
imsg_free(&imsg);
}
+ free(buf);
return err;
}
int chattygot)
{
const struct got_error *err = NULL;
- char buf[GOT_PKT_MAX];
+ char *buf = NULL;
+ const size_t bufsize = GOT_PKT_MAX;
struct imsgbuf ibuf;
enum protostate {
STATE_EXPECT_WANT,
return got_error_from_errno("imsgbuf_init");
imsgbuf_allow_fdpass(&ibuf);
+ buf = calloc(1, bufsize);
+ if (buf == NULL) {
+ err = got_error_from_errno("calloc");
+ goto done;
+ }
+
err = announce_refs(outfd, &algo, &ibuf, 1, repo_path, chattygot);
if (err)
goto done;
while (curstate != STATE_DONE) {
int n;
- err = got_pkt_readpkt(&n, infd, buf, sizeof(buf), chattygot,
+ err = got_pkt_readpkt(&n, infd, buf, bufsize, chattygot,
timeout);
if (err)
goto done;
* anything we should receive a flush
* packet followed by EOF.
*/
- r = read(infd, buf, sizeof(buf));
+ r = read(infd, buf, bufsize);
if (r == -1) {
err = got_error_from_errno("read");
goto done;
goto done;
pack_chunksize = GOT_SIDEBAND_64K_PACKFILE_DATA_MAX;
} else
- pack_chunksize = sizeof(buf);
+ pack_chunksize = bufsize;
for (;;) {
ssize_t r;
}
done:
imsgbuf_clear(&ibuf);
+ free(buf);
if (packfd != -1 && close(packfd) == -1 && err == NULL)
err = got_error_from_errno("close");
if (err)
const struct got_error *err = NULL;
size_t datalen;
int packfd;
- char buf[GOT_PKT_MAX];
+ char *buf = NULL;
+ const size_t bufsize = GOT_PKT_MAX;
int pack_done = 0;
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
if (err)
return err;
+ buf = calloc(1, bufsize);
+ if (buf == NULL)
+ return got_error_from_errno("calloc");
+
while (!pack_done) {
ssize_t r = 0;
break;
err = NULL;
} else {
- r = read(infd, buf, sizeof(buf));
+ r = read(infd, buf, bufsize);
if (r == -1) {
err = got_error_from_errno("read");
break;
}
close(packfd);
+ free(buf);
return err;
}
{
const struct got_error *err = NULL;
struct gotd_imsg_packfile_status istatus;
- char buf[GOT_PKT_MAX];
+ char *buf = NULL;
+ const size_t bufsize = GOT_PKT_MAX;
size_t datalen, len;
char *reason = NULL;
goto done;
}
+ buf = calloc(1, bufsize);
+ if (buf == NULL) {
+ err = got_error_from_errno("calloc");
+ goto done;
+ }
+
if (err == NULL)
- len = snprintf(buf, sizeof(buf), "unpack ok\n");
+ len = snprintf(buf, bufsize, "unpack ok\n");
else
- len = snprintf(buf, sizeof(buf), "unpack %s\n", reason);
- if (len >= sizeof(buf)) {
+ len = snprintf(buf, bufsize, "unpack %s\n", reason);
+ if (len >= bufsize) {
err = got_error(GOT_ERR_NO_SPACE);
goto done;
}
err = got_pkt_writepkt(outfd, buf, len, chattygot);
done:
free(reason);
+ free(buf);
return err;
}
const struct got_error *err = NULL;
struct gotd_imsg_ref_update_ok iok;
size_t datalen, len;
- char buf[GOT_PKT_MAX];
+ char *buf = NULL;
+ const size_t bufsize = GOT_PKT_MAX;
char *refname = NULL;
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
if (refname == NULL)
return got_error_from_errno("strndup");
- len = snprintf(buf, sizeof(buf), "ok %s\n", refname);
- if (len >= sizeof(buf)) {
+ buf = calloc(1, bufsize);
+ if (buf == NULL) {
+ err = got_error_from_errno("calloc");
+ goto done;
+ }
+
+ len = snprintf(buf, bufsize, "ok %s\n", refname);
+ if (len >= bufsize) {
err = got_error(GOT_ERR_NO_SPACE);
goto done;
}
err = got_pkt_writepkt(outfd, buf, len, chattygot);
done:
free(refname);
+ free(buf);
return err;
}
const struct got_error *err = NULL;
struct gotd_imsg_ref_update_ng ing;
size_t datalen, len;
- char buf[GOT_PKT_MAX];
+ char *buf = NULL;
+ const size_t bufsize = GOT_PKT_MAX;
char *refname = NULL, *reason = NULL;
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
goto done;
}
- len = snprintf(buf, sizeof(buf), "ng %s %s\n", refname, reason);
- if (len >= sizeof(buf)) {
+ buf = calloc(1, bufsize);
+ if (buf == NULL) {
+ err = got_error_from_errno("calloc");
+ goto done;
+ }
+
+ len = snprintf(buf, bufsize, "ng %s %s\n", refname, reason);
+ if (len >= bufsize) {
err = got_error(GOT_ERR_NO_SPACE);
goto done;
}
done:
free(refname);
free(reason);
+ free(buf);
return err;
}
int chattygot)
{
const struct got_error *err = NULL;
- char buf[GOT_PKT_MAX];
+ char *buf = NULL;
+ const size_t bufsize = GOT_PKT_MAX;
struct imsgbuf ibuf;
enum protostate {
STATE_EXPECT_REF_UPDATE,
digest_string_length = got_hash_digest_string_length(algo) - 1;
+ buf = calloc(1, bufsize);
+ if (buf == NULL) {
+ err = got_error_from_errno("calloc");
+ goto done;
+ }
+
while (curstate != STATE_EXPECT_PACKFILE) {
int n;
- err = got_pkt_readpkt(&n, infd, buf, sizeof(buf), chattygot,
+ err = got_pkt_readpkt(&n, infd, buf, bufsize, chattygot,
timeout);
if (err)
goto done;
}
done:
imsgbuf_clear(&ibuf);
+ free(buf);
if (err)
echo_error(err, outfd, chattygot);
return err;
blob - cd948336cf72198f33b7aff532f4776f93c5c9a1a73a0d4adb8a7c065b299037
blob + 726ac28172bd932d6bfafe664ed5c0e0eb50c078d67ca006f73a1e933c4f45a8
--- libexec/got-fetch-http/got-fetch-http.c
+++ libexec/got-fetch-http/got-fetch-http.c
}
static int
-get_refs(int https, const char *host, const char *port, const char *path)
+get_refs(int https, const char *host, const char *port, const char *path,
+ char *buf, const size_t bufsize)
{
struct bufio bio;
- char buf[GOT_PKT_MAX];
const struct got_error *e;
size_t chunksz = 0;
ssize_t r;
/* TODO: validate it's # service=git-upload-pack\n */
while (skip > 0) {
r = http_read(&bio, chunked, &chunksz, buf,
- MINIMUM(skip, sizeof(buf)), NULL);
+ MINIMUM(skip, bufsize), NULL);
if (r <= 0)
goto err;
skip -= r;
static int
upload_request(int https, const char *host, const char *port, const char *path,
- FILE *in)
+ FILE *in, char *buf, const size_t bufsize)
{
struct bufio bio;
- char buf[GOT_PKT_MAX];
const struct got_error *e;
ssize_t r;
size_t chunksz = 0;
goto err;
}
+ if (t > bufsize) {
+ warnx("pktline len is too large");
+ goto err;
+ }
+
r = fread(buf + 4, 1, t - 4, in);
if (r != t - 4)
goto err;
char *path;
int https = 0;
int ch;
+ char *buf = NULL;
+ const size_t bufsize = GOT_PKT_MAX;
#ifndef PROFILE
if (pledge("stdio rpath inet dns unveil", NULL) == -1)
path = argv[3];
got_path_strip_trailing_slashes(path);
- if (get_refs(https, host, port, path) == -1)
+ buf = calloc(1, bufsize);
+ if (buf == NULL)
+ err(1, "calloc");
+
+ if (get_refs(https, host, port, path, buf, bufsize) == -1)
errx(1, "failed to get refs");
pfd.fd = 0;
return 0;
ungetc(ch, stdin);
- if (upload_request(https, host, port, path, stdin) == -1) {
+ memset(buf, '\0', bufsize);
+ if (upload_request(https, host, port, path, stdin,
+ buf, bufsize) == -1) {
errx(1, "failed to upload request");
}
+ free(buf);
return 0;
}
blob - d547cebbf73093f2b7dd97e6c65110ec0db8c98b473808cb1b5ab7c3fed2c01e
blob + ed77a2636a4b56ff5f6b63afde7740ee00d4eb3c5a97977c1f62bf271b967e8e
--- libexec/got-fetch-pack/got-fetch-pack.c
+++ libexec/got-fetch-pack/got-fetch-pack.c
int no_head, struct imsgbuf *ibuf)
{
const struct got_error *err = NULL;
- char buf[GOT_PKT_MAX];
+ char *buf = NULL;
+ const size_t bufsize = GOT_PKT_MAX;
char hashstr[GOT_HASH_DIGEST_STRING_MAXLEN];
struct got_object_id *have, *want;
int is_firstpkt = 1, nref = 0, refsz = 16;
err = got_error_from_errno("malloc");
goto done;
}
+
+ buf = calloc(1, bufsize);
+ if (buf == NULL) {
+ err = got_error_from_errno("calloc");
+ goto done;
+ }
while (1) {
- err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot,
+ err = got_pkt_readpkt(&n, fd, buf, bufsize, chattygot,
INFTIM);
if (err)
goto done;
if (got_object_id_cmp(&have[i], &want[i]) == 0)
continue;
got_object_id_hex(&want[i], hashstr, sizeof(hashstr));
- n = snprintf(buf, sizeof(buf), "want %s%s\n", hashstr,
+ n = snprintf(buf, bufsize, "want %s%s\n", hashstr,
sent_my_capabilites || my_capabilities == NULL ?
"" : my_capabilities);
- if (n < 0 || (size_t)n >= sizeof(buf)) {
+ if (n < 0 || (size_t)n >= bufsize) {
err = got_error(GOT_ERR_NO_SPACE);
goto done;
}
RB_FOREACH(pe, got_pathlist_head, have_refs) {
struct got_object_id *id = pe->data;
got_object_id_hex(id, hashstr, sizeof(hashstr));
- n = snprintf(buf, sizeof(buf), "have %s\n", hashstr);
- if (n < 0 || (size_t)n >= sizeof(buf)) {
+ n = snprintf(buf, bufsize, "have %s\n", hashstr);
+ if (n < 0 || (size_t)n >= bufsize) {
err = got_error(GOT_ERR_NO_SPACE);
goto done;
}
nhave++;
}
- n = strlcpy(buf, "done\n", sizeof(buf));
+ n = strlcpy(buf, "done\n", bufsize);
err = got_pkt_writepkt(fd, buf, n, chattygot);
if (err)
goto done;
struct got_object_id common_id;
/* The server should ACK the object IDs we need. */
- err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot,
+ err = got_pkt_readpkt(&n, fd, buf, bufsize, chattygot,
INFTIM);
if (err)
goto done;
}
if (nhave == 0) {
- err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot,
+ err = got_pkt_readpkt(&n, fd, buf, bufsize, chattygot,
INFTIM);
if (err)
goto done;
"short packet");
goto done;
}
- if (datalen > sizeof(buf) - 5) {
+ if (datalen > bufsize - 5) {
err = got_error_msg(GOT_ERR_BAD_PACKET,
"bad packet length");
goto done;
/* No sideband channel. Every byte is packfile data. */
size_t n = 0;
err = got_poll_read_full_timeout(fd, &n,
- buf, sizeof buf, 1, INFTIM);
+ buf, bufsize, 1, INFTIM);
if (err) {
if (err->code != GOT_ERR_EOF)
goto done;
free(server_capabilities);
free(my_capabilities);
free(capa);
+ free(buf);
return err;
}
-
int
main(int argc, char **argv)
{
blob - 8e337a694a51cf784ebb846929ecda60e92c6adee0794e5a1c15ce0bbbe4327c
blob + d3a6a7ca72ca4047377806092bc7ab95e794c6f93d6e88882ae270aa40287f45
--- libexec/got-send-pack/got-send-pack.c
+++ libexec/got-send-pack/got-send-pack.c
struct got_pathlist_head *delete_refs, struct imsgbuf *ibuf)
{
const struct got_error *err = NULL;
- char buf[GOT_PKT_MAX];
+ char *buf = NULL;
+ const size_t bufsize = GOT_PKT_MAX;
const unsigned char zero_id[GOT_HASH_DIGEST_MAXLEN] = { 0 };
char old_hashstr[GOT_HASH_DIGEST_STRING_MAXLEN];
char new_hashstr[GOT_HASH_DIGEST_STRING_MAXLEN];
if (RB_EMPTY(refs) && RB_EMPTY(delete_refs))
return got_error(GOT_ERR_SEND_EMPTY);
+ buf = calloc(1, bufsize);
+ if (buf == NULL)
+ return got_error_from_errno("calloc");
+
while (1) {
- err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot,
+ err = got_pkt_readpkt(&n, fd, buf, bufsize, chattygot,
INFTIM);
if (err)
goto done;
got_hash_digest_to_str(zero_id, new_hashstr,
sizeof(new_hashstr), algo);
err = describe_refchange(&n, &sent_my_capabilites,
- my_capabilities, buf, sizeof(buf), refname,
+ my_capabilities, buf, bufsize, refname,
old_hashstr, new_hashstr);
if (err)
goto done;
}
got_object_id_hex(id, new_hashstr, sizeof(new_hashstr));
err = describe_refchange(&n, &sent_my_capabilites,
- my_capabilities, buf, sizeof(buf), refname,
+ my_capabilities, buf, bufsize, refname,
old_hashstr, new_hashstr);
if (err)
goto done;
goto done;
}
- err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot, INFTIM);
+ err = got_pkt_readpkt(&n, fd, buf, bufsize, chattygot, INFTIM);
if (err)
goto done;
if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
}
while (nsent > 0) {
- err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot,
+ err = got_pkt_readpkt(&n, fd, buf, bufsize, chattygot,
INFTIM);
if (err)
goto done;
free(server_capabilities);
free(my_capabilities);
free(capa);
+ free(buf);
return err;
}