aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-04-23 11:52:41 -0700
committerJunio C Hamano <gitster@pobox.com>2024-04-23 11:52:41 -0700
commitfb9f603f3c6756de772ac16ddddbcb4474dd96b8 (patch)
tree34bbe885cb342a8af7eea30517cbad89c3a47d06
parent9cb0bbf0b43803a68aadb3e0f929b3082233d288 (diff)
parent21b5821acd6a5627d2efcc22021f8f040373a69c (diff)
Merge branch 'rs/imap-send-simplify-cmd-issuing-codepath'
Code simplification. * rs/imap-send-simplify-cmd-issuing-codepath: imap-send: increase command size limit
-rw-r--r--imap-send.c35
1 files changed, 12 insertions, 23 deletions
diff --git a/imap-send.c b/imap-send.c
index 4caa8668e6..0afd088d8a 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -68,20 +68,6 @@ static void imap_warn(const char *, ...);
static char *next_arg(char **);
-static int nfvasprintf(char **strp, const char *fmt, va_list ap)
-{
- int len;
- char tmp[8192];
-
- len = vsnprintf(tmp, sizeof(tmp), fmt, ap);
- if (len < 0)
- die("Fatal: Out of memory");
- if (len >= sizeof(tmp))
- die("imap command overflow!");
- *strp = xmemdupz(tmp, len);
- return len;
-}
-
struct imap_server_conf {
const char *name;
const char *tunnel;
@@ -503,11 +489,11 @@ static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx,
{
struct imap *imap = ctx->imap;
struct imap_cmd *cmd;
- int n, bufl;
- char buf[1024];
+ int n;
+ struct strbuf buf = STRBUF_INIT;
cmd = xmalloc(sizeof(struct imap_cmd));
- nfvasprintf(&cmd->cmd, fmt, ap);
+ cmd->cmd = xstrvfmt(fmt, ap);
cmd->tag = ++imap->nexttag;
if (cb)
@@ -519,27 +505,30 @@ static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx,
get_cmd_result(ctx, NULL);
if (!cmd->cb.data)
- bufl = xsnprintf(buf, sizeof(buf), "%d %s\r\n", cmd->tag, cmd->cmd);
+ strbuf_addf(&buf, "%d %s\r\n", cmd->tag, cmd->cmd);
else
- bufl = xsnprintf(buf, sizeof(buf), "%d %s{%d%s}\r\n",
- cmd->tag, cmd->cmd, cmd->cb.dlen,
- CAP(LITERALPLUS) ? "+" : "");
+ strbuf_addf(&buf, "%d %s{%d%s}\r\n", cmd->tag, cmd->cmd,
+ cmd->cb.dlen, CAP(LITERALPLUS) ? "+" : "");
+ if (buf.len > INT_MAX)
+ die("imap command overflow!");
if (0 < verbosity) {
if (imap->num_in_progress)
printf("(%d in progress) ", imap->num_in_progress);
if (!starts_with(cmd->cmd, "LOGIN"))
- printf(">>> %s", buf);
+ printf(">>> %s", buf.buf);
else
printf(">>> %d LOGIN <user> <pass>\n", cmd->tag);
}
- if (socket_write(&imap->buf.sock, buf, bufl) != bufl) {
+ if (socket_write(&imap->buf.sock, buf.buf, buf.len) != buf.len) {
free(cmd->cmd);
free(cmd);
if (cb)
free(cb->data);
+ strbuf_release(&buf);
return NULL;
}
+ strbuf_release(&buf);
if (cmd->cb.data) {
if (CAP(LITERALPLUS)) {
n = socket_write(&imap->buf.sock, cmd->cb.data, cmd->cb.dlen);