Browse Source

accept zero-sized messages from IMAP

while such a thing is rather pointless, completely empty messages are
not forbidden. consequently, we should be able to deal with them, and
above all not crash.
master
Oswald Buddenhagen 1 month ago
parent
commit
15c7e02e4a
  1. 5
      src/drv_imap.c
  2. 1
      src/socket.c
  3. 5
      src/util.c

5
src/drv_imap.c

@ -780,6 +780,8 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts )
if (sts->callback->atom( ctx, NULL, bytes, AtomChunkedLiteral ) != LIST_OK) if (sts->callback->atom( ctx, NULL, bytes, AtomChunkedLiteral ) != LIST_OK)
goto bail; goto bail;
sts->in_literal = ChunkedLiteral; sts->in_literal = ChunkedLiteral;
if (!bytes)
goto nobytes;
sts->big_literal = 1; sts->big_literal = 1;
get_chunked: get_chunked:
n = 1; n = 1;
@ -806,7 +808,7 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts )
} else if (DFlags & DEBUG_NET_ALL) { } else if (DFlags & DEBUG_NET_ALL) {
printf( "%s=========\n", ctx->label ); printf( "%s=========\n", ctx->label );
fwrite( p, n, 1, stdout ); fwrite( p, n, 1, stdout );
if (p[n - 1] != '\n') if (n && p[n - 1] != '\n')
fputs( "\n(no-nl) ", stdout ); fputs( "\n(no-nl) ", stdout );
printf( "%s=========\n", ctx->label ); printf( "%s=========\n", ctx->label );
} else { } else {
@ -819,6 +821,7 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts )
bytes -= n; bytes -= n;
if (bytes > 0) if (bytes > 0)
goto postpone; goto postpone;
nobytes:
if (sts->in_literal == ChunkedLiteral && sts->callback->atom( ctx, NULL, 0, AtomLiteral ) != LIST_OK) if (sts->in_literal == ChunkedLiteral && sts->callback->atom( ctx, NULL, 0, AtomLiteral ) != LIST_OK)
goto bail; goto bail;
getline: getline:

1
src/socket.c

@ -952,7 +952,6 @@ socket_expect_bytes( conn_t *conn, uint len )
char * char *
socket_read( conn_t *conn, uint min_len, uint max_len, uint *out_len ) socket_read( conn_t *conn, uint min_len, uint max_len, uint *out_len )
{ {
assert( min_len > 0 );
assert( min_len <= sizeof(conn->buf) ); assert( min_len <= sizeof(conn->buf) );
assert( min_len <= max_len ); assert( min_len <= max_len );

5
src/util.c

@ -637,6 +637,11 @@ nfmalloc( size_t sz )
{ {
void *ret; void *ret;
#ifndef __GLIBC__
// The C standard allows NULL returns for zero-sized allocations.
if (!sz)
sz = 1;
#endif
if (!(ret = malloc( sz ))) if (!(ret = malloc( sz )))
oom(); oom();
return ret; return ret;

Loading…
Cancel
Save