Drop all ADC messages containing illegal ADC escapes.

This commit is contained in:
Jan Vidar Krey 2012-08-07 11:55:29 +02:00
parent ccaf755da3
commit fb11589bb0
1 changed files with 28 additions and 1 deletions

View File

@ -63,6 +63,27 @@ static void msg_free(void* ptr)
#define msg_free(X) hub_free(X)
#endif /* MSG_MEMORY_DEBUG */
static int msg_check_escapes(const char* string, size_t len)
{
char* start = (char*) string;
while ((start = memchr(start, '\\', len - (start - string))))
{
if (start+1 == (string + len))
return 0;
switch (*(++start))
{
case '\\':
case 'n':
case 's':
break;
default:
return 0;
}
}
return 1;
}
struct adc_message* adc_msg_incref(struct adc_message* msg)
{
@ -319,6 +340,13 @@ struct adc_message* adc_msg_parse(const char* line, size_t length)
return NULL;
}
if (!msg_check_escapes(line, length))
{
LOG_DEBUG("Dropped message with invalid ADC escape.");
msg_free(command);
return NULL;
}
if (line[length-1] != '\n')
{
need_terminate = 1;
@ -877,7 +905,6 @@ char* adc_msg_unescape(const char* string)
return new_string;
}
char* adc_msg_escape(const char* string)
{
char* str = hub_malloc(adc_msg_escape_length(string)+1);