added NULL check to webserver.c
This commit is contained in:
@@ -18,12 +18,25 @@ static char post_buffer[400];
|
||||
static uint16_t post_buffer_len = 0;
|
||||
|
||||
void parse_post(const char *key, char delimiter, char *dest, int max_len) {
|
||||
char *pos = strstr(post_buffer, key) + strlen(key);
|
||||
char *end = strchr(pos, delimiter);
|
||||
char *start = strstr(post_buffer, key);
|
||||
if (!start) {
|
||||
dest[0] = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
char *pos = start + strlen(key);
|
||||
char *end = (delimiter == '\0') ? (post_buffer + strlen(post_buffer))
|
||||
: strchr(pos, delimiter);
|
||||
|
||||
if (!end) {
|
||||
end = post_buffer + strlen(post_buffer);
|
||||
}
|
||||
|
||||
int len = end - pos;
|
||||
if (len > max_len) {
|
||||
len = max_len;
|
||||
}
|
||||
|
||||
strncpy(dest, pos, len);
|
||||
dest[len] = '\0';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user