[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] src/tests/run_test.c: add one to buffer sizes and read size-
From: |
Rui Batista |
Subject: |
[PATCH 2/2] src/tests/run_test.c: add one to buffer sizes and read size-1 to prevent buffer overflows |
Date: |
Thu, 18 Feb 2010 17:13:26 +0000 |
* Thhis patch should correct all cases, if not I'm so so so sorry.
---
src/tests/run_test.c | 11 +++++------
1 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/tests/run_test.c b/src/tests/run_test.c
index 5308f33..8f16a0c 100644
--- a/src/tests/run_test.c
+++ b/src/tests/run_test.c
@@ -35,8 +35,8 @@
#include "def.h"
-#define LINE_BUFFER_SIZE 1024
-#define REPLY_BUFFER_SIZE 1000
+#define LINE_BUFFER_SIZE 1025
+#define REPLY_BUFFER_SIZE 1025
#define FATAL(msg) { printf(msg"\n"); exit(1); }
@@ -64,7 +64,6 @@ send_data (int fd, const char *message, int wfr, char *reply)
{
int bytes;
-
/* write message to the socket */
bytes = write (fd, message, strlen (message));
assert (bytes == strlen (message)); /* this also accounts for -1 */
@@ -72,7 +71,7 @@ send_data (int fd, const char *message, int wfr, char *reply)
/* read reply to the buffer */
if (wfr == 1)
{
- bytes = read (fd, reply, REPLY_BUFFER_SIZE);
+ bytes = read (fd, reply, REPLY_BUFFER_SIZE - 1);
assert (bytes > 0);
/* print server reply to as a string */
reply[bytes] = 0;
@@ -90,7 +89,7 @@ wait_for (int fd, const char *event)
reply[0] = 0;
while (0 == strcasestr (reply, event))
{
- bytes = read (fd, reply, REPLY_BUFFER_SIZE);
+ bytes = read (fd, reply, REPLY_BUFFER_SIZE - 1);
if (bytes > 0)
{
reply[bytes] = 0;
@@ -179,7 +178,7 @@ main (int argc, char *argv[])
while (1)
{
- ret = fgets (line, 1024, test_file);
+ ret = fgets (line, LINE_BUFFER_SIZE, test_file); /* fgets reads at most
size -1 chars */
if (ret == NULL)
break;
if (strlen (line) <= 1)
--
1.6.3.3