summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cancd.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/cancd.c b/cancd.c
index 9e0bfe9..263ba06 100644
--- a/cancd.c
+++ b/cancd.c
@@ -421,11 +421,11 @@ static int run()
{
int rc;
char *buf;
- size_t bufsize = 8 * getpagesize();
+ size_t bufsize = 0x100000;
struct sockaddr_in from;
socklen_t fromlen;
- buf = malloc(sizeof(char) * bufsize);
+ buf = malloc(bufsize);
if (!buf) {
syslog(LOG_ERR, "Unable to allocate memory for receive buffer: %s", strerror(errno));
return -ENOMEM;
@@ -443,6 +443,10 @@ static int run()
syslog(LOG_ERR, "Error reading from socket: %s", strerror(-rc));
break;
}
+ if (rc >= bufsize) {
+ rc = bufsize - 1;
+ syslog(LOG_ERR, "Receive buffer too small (%zd %d)", bufsize, rc);
+ }
buf[rc] = 0;
/* For now, we process one at a time */
do_output(buf, rc, &from, fromlen);