Skip to content

Commit 95bf615

Browse files
committed
Merge branch 'rs/imap-send-next-arg-fix' into maint
Error checking in "git imap-send" for empty response has been improved. * rs/imap-send-next-arg-fix: imap-send: handle missing response codes gracefully imap-send: handle NULL return of next_arg()
2 parents 7d22aec + 618ec81 commit 95bf615

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

imap-send.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
683683
struct imap *imap = ctx->imap;
684684
char *arg, *p;
685685

686-
if (*s != '[')
686+
if (!s || *s != '[')
687687
return RESP_OK; /* no response code */
688688
s++;
689689
if (!(p = strchr(s, ']'))) {
@@ -692,6 +692,10 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
692692
}
693693
*p++ = 0;
694694
arg = next_arg(&s);
695+
if (!arg) {
696+
fprintf(stderr, "IMAP error: empty response code\n");
697+
return RESP_BAD;
698+
}
695699
if (!strcmp("UIDVALIDITY", arg)) {
696700
if (!(arg = next_arg(&s)) || !(ctx->uidvalidity = atoi(arg))) {
697701
fprintf(stderr, "IMAP error: malformed UIDVALIDITY status\n");
@@ -724,14 +728,19 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
724728
{
725729
struct imap *imap = ctx->imap;
726730
struct imap_cmd *cmdp, **pcmdp;
727-
char *cmd, *arg, *arg1;
731+
char *cmd;
732+
const char *arg, *arg1;
728733
int n, resp, resp2, tag;
729734

730735
for (;;) {
731736
if (buffer_gets(&imap->buf, &cmd))
732737
return RESP_BAD;
733738

734739
arg = next_arg(&cmd);
740+
if (!arg) {
741+
fprintf(stderr, "IMAP error: empty response\n");
742+
return RESP_BAD;
743+
}
735744
if (*arg == '*') {
736745
arg = next_arg(&cmd);
737746
if (!arg) {
@@ -806,6 +815,8 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
806815
if (cmdp->cb.cont || cmdp->cb.data)
807816
imap->literal_pending = 0;
808817
arg = next_arg(&cmd);
818+
if (!arg)
819+
arg = "";
809820
if (!strcmp("OK", arg))
810821
resp = DRV_OK;
811822
else {

0 commit comments

Comments
 (0)