diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2020-08-04 17:29:31 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2020-08-04 17:29:31 +0200 |
commit | 8a6021268e83b8712acc8d73ab2f4073ee402245 (patch) | |
tree | dd728aa0467fbc218e5c7d3d5807f2f3d6bdfb13 /nDPIsrvd.c | |
parent | 823b95828c7a3321e4375ddee858e3a44ad1cd4c (diff) |
introduced NETWORK_BUFFER_MAX_SIZE to replace BUFSIZ as this might change depending on the arch/libc used
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'nDPIsrvd.c')
-rw-r--r-- | nDPIsrvd.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/nDPIsrvd.c b/nDPIsrvd.c index 3996e2c26..61b857c8a 100644 --- a/nDPIsrvd.c +++ b/nDPIsrvd.c @@ -25,7 +25,7 @@ struct remote_desc { enum ev_type type; int fd; - uint8_t buf[BUFSIZ]; + uint8_t buf[NETWORK_BUFFER_MAX_SIZE]; size_t buf_used; unsigned long long int buf_wanted; union { @@ -367,18 +367,19 @@ int main(void) } if ((uint8_t *)json_str_start == current->buf) { - current->buf_used = 0; - current->buf_wanted = 0; syslog(LOG_DAEMON | LOG_ERR, "Missing size before JSON string: %.*s", - (int) current->buf_wanted, current->buf); + (int) current->buf_used, current->buf); + current->buf_used = 0; + current->buf_wanted = 0; continue; } - if (current->buf_wanted > BUFSIZ) + if (current->buf_wanted > sizeof(current->buf)) { + syslog(LOG_DAEMON | LOG_ERR, "BUG: JSON string too big: %llu > %zu", + current->buf_wanted, sizeof(current->buf)); current->buf_used = 0; current->buf_wanted = 0; - syslog(LOG_DAEMON | LOG_ERR, "BUG: JSON string too big: %llu > %d", current->buf_wanted, BUFSIZ); continue; } } @@ -390,10 +391,10 @@ int main(void) /* after buffering complete, last character should always be a '}' (end of object) */ if (current->buf[current->buf_wanted - 1] != '}') { - current->buf_used = 0; - current->buf_wanted = 0; syslog(LOG_DAEMON | LOG_ERR, "Invalid JSON string: %.*s", (int) current->buf_wanted, current->buf); + current->buf_used = 0; + current->buf_wanted = 0; continue; } @@ -430,7 +431,7 @@ int main(void) } memmove(current->buf, current->buf + current->buf_wanted, current->buf_used - current->buf_wanted); - current->buf_used = 0; + current->buf_used -= current->buf_wanted; current->buf_wanted = 0; } } |