diff options
Diffstat (limited to 'src/libwpactrl/wpactrl_update.c')
-rw-r--r-- | src/libwpactrl/wpactrl_update.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/libwpactrl/wpactrl_update.c b/src/libwpactrl/wpactrl_update.c index edbdc6f..0462cbe 100644 --- a/src/libwpactrl/wpactrl_update.c +++ b/src/libwpactrl/wpactrl_update.c @@ -1,6 +1,8 @@ /* ISC license. */ #include <string.h> +#include <errno.h> +#include <skalibs/error.h> #include <skalibs/allreadwrite.h> #include <skalibs/stralloc.h> #include <bcnm/wpactrl.h> @@ -24,6 +26,7 @@ static inline int validate (char const *s, size_t len) if (s[0] != '<') return 0 ; if (!memchr("123456789", s[1], 9)) return 0 ; if (s[2] != '>') return 0 ; + if (strnlen(s, len) < len) return 0 ; return s[len-1] == '\n' ; } @@ -31,7 +34,7 @@ int wpactrl_update (wpactrl_t *a) { unsigned int n = WPACTRL_RECV_MAX ; unsigned int count = 0 ; - char buf[WPACTRL_PACKET_MAX] ; + char buf[WPACTRL_PACKET_MAX+1] ; while (n--) { ssize_t r = sanitize_read(wpactrl_fd_recv(a->fda, buf, WPACTRL_PACKET_MAX)) ; @@ -40,7 +43,8 @@ int wpactrl_update (wpactrl_t *a) if (a->options & WPACTRL_OPTION_NOFILTER || (validate(buf, r) && filter_search(buf, r, a->filters.s, a->filters.len))) { - if (!stralloc_catb(&a->data, buf, r)) return -1 ; + buf[r] = 0 ; + if (!stralloc_catb(&a->data, buf, r+1)) return -1 ; count++ ; } } |