summaryrefslogtreecommitdiff
path: root/src/libwpactrl/wpactrl_update.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-07-09 07:46:23 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-07-09 07:46:23 +0000
commit22a1dc61ef8e4e1c98e3a088db1dbc84d424c7a7 (patch)
treeefc5d779a40c004e708bd6a99b359c660931249b /src/libwpactrl/wpactrl_update.c
parent0c9b6b3625dff03b6d590af597aa0f194790addb (diff)
downloadbcnm-22a1dc61ef8e4e1c98e3a088db1dbc84d424c7a7.tar.xz
Separate messages via \0, read messages one by one. Add wpactrl_scan_parse() skel.
Diffstat (limited to 'src/libwpactrl/wpactrl_update.c')
-rw-r--r--src/libwpactrl/wpactrl_update.c8
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++ ;
}
}