summaryrefslogtreecommitdiff
path: root/imap-send.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-11-27 01:57:00 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-11-27 01:57:00 (GMT)
commit95bf6151dc6e593ce3dd2b04b2ce1c28a5223199 (patch)
tree5e75b81febcae8cec18c62797b4e657e5be6be28 /imap-send.c
parent7d22aec681f7656e6f30ef9e3fc92b17d9abc3a3 (diff)
parent618ec81abbda91d867ac43320c7fd3e8fcc23e78 (diff)
downloadgit-95bf6151dc6e593ce3dd2b04b2ce1c28a5223199.zip
git-95bf6151dc6e593ce3dd2b04b2ce1c28a5223199.tar.gz
git-95bf6151dc6e593ce3dd2b04b2ce1c28a5223199.tar.bz2
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()
Diffstat (limited to 'imap-send.c')
-rw-r--r--imap-send.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/imap-send.c b/imap-send.c
index e0523d3..54e6a80 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -683,7 +683,7 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
struct imap *imap = ctx->imap;
char *arg, *p;
- if (*s != '[')
+ if (!s || *s != '[')
return RESP_OK; /* no response code */
s++;
if (!(p = strchr(s, ']'))) {
@@ -692,6 +692,10 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
}
*p++ = 0;
arg = next_arg(&s);
+ if (!arg) {
+ fprintf(stderr, "IMAP error: empty response code\n");
+ return RESP_BAD;
+ }
if (!strcmp("UIDVALIDITY", arg)) {
if (!(arg = next_arg(&s)) || !(ctx->uidvalidity = atoi(arg))) {
fprintf(stderr, "IMAP error: malformed UIDVALIDITY status\n");
@@ -724,7 +728,8 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
{
struct imap *imap = ctx->imap;
struct imap_cmd *cmdp, **pcmdp;
- char *cmd, *arg, *arg1;
+ char *cmd;
+ const char *arg, *arg1;
int n, resp, resp2, tag;
for (;;) {
@@ -732,6 +737,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
return RESP_BAD;
arg = next_arg(&cmd);
+ if (!arg) {
+ fprintf(stderr, "IMAP error: empty response\n");
+ return RESP_BAD;
+ }
if (*arg == '*') {
arg = next_arg(&cmd);
if (!arg) {
@@ -806,6 +815,8 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
if (cmdp->cb.cont || cmdp->cb.data)
imap->literal_pending = 0;
arg = next_arg(&cmd);
+ if (!arg)
+ arg = "";
if (!strcmp("OK", arg))
resp = DRV_OK;
else {