Fix bug #12: asserts in adc_msg_parse -> enabled strict utf8 parsing.

Signed-off-by: Jan Vidar Krey <janvidar@extatic.org>
This commit is contained in:
Jan Vidar Krey 2009-03-23 21:47:05 +01:00
parent ab4eb6db3d
commit 7aeb8651ba
5 changed files with 39 additions and 9 deletions

View File

@ -1,6 +1,7 @@
0.2.8:
- Fix bug #13: getsockname() failure, use sockaddr from accept() instead.
- Fix bug #10: Improve logging, ensure logs are machine readable.
- Fix bug #12: asserts in adc_msg_parse -> enabled strict utf8 parsing.
0.2.7:

View File

@ -26,8 +26,6 @@
uhub_assert(X->capacity); \
uhub_assert(X->length); \
uhub_assert(X->length <= X->capacity); \
if (X->length != strlen(X->cache)) \
hub_log(log_error, "Assert: X->length (%d) != strlen(X->cache) (%d)", X->length, strlen(X->cache)); \
uhub_assert(X->length == strlen(X->cache)); \
uhub_assert(X->references >= 0);
#else
@ -265,6 +263,13 @@ struct adc_message* adc_msg_parse(const char* line, size_t length)
if (command == NULL)
return NULL; /* OOM */
if (!is_printable_utf8(line, length))
{
hub_log(log_debug, "Dropped message with non-printable UTF-8 characters.");
hub_free(command);
return NULL;
}
if (line[length-1] != '\n')
{

View File

@ -31,6 +31,16 @@ int is_white_space(char c)
return 0;
}
int is_printable(char c)
{
if (c >= 32)
return 1;
if (c == '\t' || c == '\r' || c == '\n')
return 1;
return 0;
}
char* strip_white_space(char* string)
{
@ -48,17 +58,15 @@ char* strip_white_space(char* string)
return string;
}
int is_valid_utf8(const char* string)
static int is_valid_utf8_str(const char* string, size_t length)
{
int expect = 0;
char div = 0;
int pos = 0;
int length = strlen(string);
size_t pos = 0;
if (length == 0) return 1;
for (pos = 0; pos < strlen(string); pos++)
for (pos = 0; pos < length; pos++)
{
if (expect)
{
@ -74,13 +82,28 @@ int is_valid_utf8(const char* string)
if (string[pos] & div) expect++;
else break;
}
if ((string[pos] & div) || (pos+expect >= strlen(string))) return 0;
if ((string[pos] & div) || (pos+expect >= length)) return 0;
}
}
}
return 1;
}
int is_valid_utf8(const char* string)
{
return is_valid_utf8_str(string, strlen(string));
}
int is_printable_utf8(const char* string, size_t length)
{
size_t pos = 0;
for (pos = 0; pos < length; pos++)
{
if (!is_printable(string[pos]))
return 0;
}
return is_valid_utf8_str(string, length);
}
int is_valid_base32_char(char c)
{

View File

@ -26,6 +26,7 @@ extern int is_num(char c);
extern int is_space(char c);
extern int is_white_space(char c);
extern int is_valid_utf8(const char* string);
extern int is_printable_utf8(const char* string, size_t length);
extern int is_valid_base32_char(char c);
extern void base32_encode(const unsigned char* buffer, size_t len, char* result);
extern void base32_decode(const char* src, unsigned char* dst, size_t len);

View File

@ -7,7 +7,7 @@
#endif
#ifndef VERSION
#define VERSION "0.2.7"
#define VERSION "0.2.8-alpha"
#endif
#ifndef COPYRIGHT