summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoern Engel <joern@logfs.org>2012-01-16 12:56:25 -0800
committerJoern Engel <joern@logfs.org>2012-01-16 13:17:36 -0800
commit4d7cf7e91bd397bbb41f7f685d346c22188ac897 (patch)
treedacb0a381bdd6c9b08e93b6b1b1846f3f9fd1209
parent7f9450c5281fb0e0ba27e92dcc99bf1475b13715 (diff)
downloadcancd-4d7cf7e91bd397bbb41f7f685d346c22188ac897.tar.gz
Sanitize buffer size
There is no point in depending on page size or supporting machines where sizeof(char) is not one. Also warn if ever the buffer is too small, so people have an indication to go and increase it. And just in case 32k is not enough, bump the size to 1M. Memory is cheap enough these days. Signed-off-by: Joern Engel <joern@logfs.org>
-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);