Accept space, tab, cr, and nl chars after POP3 and SMTP commands

POP3 clients may and do append CRLF to commands.
So use the new util_get_first_word_len() function.
pull/48/head
Soner Tari 4 years ago
parent 01577657fd
commit e3b0ba94d8

@ -27,6 +27,7 @@
#include "protopop3.h"
#include "protossl.h"
#include "util.h"
#include <string.h>
@ -47,8 +48,7 @@ protopop3_validate_command(char *packet, size_t packet_size
#endif /* DEBUG_PROXY */
)
{
char *command_end = memchr(packet, ' ', packet_size);
size_t command_len = command_end ? (size_t)(command_end - packet) : packet_size;
size_t command_len = util_get_first_word_len(packet, packet_size);
unsigned int i;
for (i = 0; i < sizeof(protopop3_commands)/sizeof(char *); i++) {

@ -28,6 +28,7 @@
#include "protosmtp.h"
#include "prototcp.h"
#include "protossl.h"
#include "util.h"
#include <string.h>
@ -49,8 +50,7 @@ protosmtp_validate_command(char *packet, size_t packet_size
#endif /* DEBUG_PROXY */
)
{
char *command_end = memchr(packet, ' ', packet_size);
size_t command_len = command_end ? (size_t)(command_end - packet) : packet_size;
size_t command_len = util_get_first_word_len(packet, packet_size);
unsigned int i;
for (i = 0; i < sizeof(protosmtp_commands)/sizeof(char *); i++) {

@ -42,4 +42,23 @@ util_skipws(const char *s)
return (char*) s + strspn(s, " \t");
}
/*
* Returns the length of the first word in a given memory area.
* Memory area may not be null-terminated, hence we cannot use string
* manipulation functions.
*/
size_t
util_get_first_word_len(char *mem, size_t size)
{
char *command_end;
// @attention The detection order of ws chars is important: space, tab, cr, and nl
if ((command_end = memchr(mem, ' ', size)) ||
(command_end = memchr(mem, '\t', size)) ||
(command_end = memchr(mem, '\r', size)) ||
(command_end = memchr(mem, '\n', size))) {
return (size_t)(command_end - mem);
}
return size;
}
/* vim: set noet ft=c: */

@ -31,7 +31,10 @@
#include "attrib.h"
#include <string.h>
char * util_skipws(const char *) NONNULL(1) PURE;
size_t util_get_first_word_len(char *packet, size_t packet_size) NONNULL(1);
#define util_max(a,b) ((a) > (b) ? (a) : (b))

@ -47,6 +47,81 @@
}
},
"2": {
"comment": "Validates CAPA+CR",
"states": {
"1": {
"testend": "client",
"cmd": "send",
"payload": "CAPA\r"
},
"2": {
"testend": "server",
"cmd": "recv",
"payload": "CAPA\r"
}
}
},
"3": {
"comment": "Validates CAPA+NL",
"states": {
"1": {
"testend": "client",
"cmd": "send",
"payload": "CAPA\n"
},
"2": {
"testend": "server",
"cmd": "recv",
"payload": "CAPA\n"
}
}
},
"4": {
"comment": "Validates CAPA+CRNL",
"states": {
"1": {
"testend": "client",
"cmd": "send",
"payload": "CAPA\r\n"
},
"2": {
"testend": "server",
"cmd": "recv",
"payload": "CAPA\r\n"
}
}
},
"5": {
"comment": "Validates CAPA+TAB",
"states": {
"1": {
"testend": "client",
"cmd": "send",
"payload": "CAPA\t"
},
"2": {
"testend": "server",
"cmd": "recv",
"payload": "CAPA\t"
}
}
},
"6": {
"comment": "Validates CAPA+TABCRNL",
"states": {
"1": {
"testend": "client",
"cmd": "send",
"payload": "CAPA\t\r\n"
},
"2": {
"testend": "server",
"cmd": "recv",
"payload": "CAPA\t\r\n"
}
}
},
"7": {
"comment": "Does not validate CAP",
"states": {
"1": {
@ -66,7 +141,7 @@
}
}
},
"3": {
"8": {
"comment": "Does not validate CAP1",
"states": {
"1": {
@ -86,7 +161,7 @@
}
}
},
"3": {
"9": {
"comment": "Does not validate CAPA1",
"states": {
"1": {

Loading…
Cancel
Save