Skip to content

Commit d4a5de7

Browse files
committed
Merge branch 'rs/imap-send-next-arg-fix'
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 fcaba62 + 618ec81 commit d4a5de7

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
@@ -684,7 +684,7 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
684684
struct imap *imap = ctx->imap;
685685
char *arg, *p;
686686

687-
if (*s != '[')
687+
if (!s || *s != '[')
688688
return RESP_OK; /* no response code */
689689
s++;
690690
if (!(p = strchr(s, ']'))) {
@@ -693,6 +693,10 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
693693
}
694694
*p++ = 0;
695695
arg = next_arg(&s);
696+
if (!arg) {
697+
fprintf(stderr, "IMAP error: empty response code\n");
698+
return RESP_BAD;
699+
}
696700
if (!strcmp("UIDVALIDITY", arg)) {
697701
if (!(arg = next_arg(&s)) || !(ctx->uidvalidity = atoi(arg))) {
698702
fprintf(stderr, "IMAP error: malformed UIDVALIDITY status\n");
@@ -725,14 +729,19 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
725729
{
726730
struct imap *imap = ctx->imap;
727731
struct imap_cmd *cmdp, **pcmdp;
728-
char *cmd, *arg, *arg1;
732+
char *cmd;
733+
const char *arg, *arg1;
729734
int n, resp, resp2, tag;
730735

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

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

0 commit comments

Comments
 (0)