commit 54a3381da2970d7de60770bfe6933345b1a5fe19
parent c3419cb5358fde81658eb5edb3fdb7ba4f8701f6
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Wed, 8 Feb 2023 20:32:40 +0000
Fix pop_list on zero-length LIST return
The pop_list function is suppost to treat a zero-length LIST return
as success (and return a non-NULL value), which it did. However,
it's also suppost to define the length as zero, which it did not.
This bug leaves the getmail function's listings length undefined,
which could cause it to dereference NULL.
Diffstat:
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/pop3.c b/pop3.c
@@ -1,4 +1,4 @@
-/* $Id: pop3.c,v 1.6 2022/04/05 01:56:14 jacob Exp $ */
+/* $Id: pop3.c,v 1.7 2023/02/08 20:32:40 jacob Exp $ */
/*
* Copyright (c) 2022 Jacob R. Edwards
@@ -326,9 +326,13 @@ pop_list(FILE *fp, int *_len)
errno = EOVERFLOW;
return NULL;
}
+
listings = calloc(len, sizeof(*listings));
- if (len == 0 || listings == NULL)
+ if (len == 0 || listings == NULL) {
+ if (_len)
+ _len = 0;
return listings;
+ }
if (!pop_okay(pop_comd(fp, buf, sizeof(buf), "LIST", NULL)))
return NULL;