Browse Source

Check for max buffer size in stdout grabber

Serj Kalichev 8 years ago
parent
commit
7c65fd3a66
2 changed files with 9 additions and 1 deletions
  1. 3 0
      clish/shell.h
  2. 6 1
      clish/shell/shell_execute.c

+ 3 - 0
clish/shell.h

@@ -29,6 +29,9 @@
 #define CLISH_LOCK_PATH "/tmp/clish.lock"
 #define CLISH_LOCK_WAIT 20
 
+#define CLISH_STDOUT_CHUNK 1024
+#define CLISH_STDOUT_MAXBUF (CLISH_STDOUT_CHUNK * 1024)
+
 #define CLISH_XML_ERROR_STR "Error parsing XML: "
 #define CLISH_XML_ERROR_ATTR(attr) CLISH_XML_ERROR_STR"The \""attr"\" attribute is required.\n"
 

+ 6 - 1
clish/shell/shell_execute.c

@@ -236,7 +236,8 @@ static int clish_shell_exec_oaction(clish_hook_oaction_fn_t func,
 		lub_list_t *l;
 		lub_list_node_t *node;
 		struct iovec *iov;
-		const int rsize = 1024; /* Read chunk size */
+		const int rsize = CLISH_STDOUT_CHUNK; /* Read chunk size */
+		size_t cur_size = 0;
 
 		close(pipe1[1]);
 		close(pipe2[0]);
@@ -258,6 +259,10 @@ static int clish_shell_exec_oaction(clish_hook_oaction_fn_t func,
 			}
 			iov->iov_len = ret;
 			lub_list_add(l, iov);
+			/* Check the max size of buffer */
+			cur_size += ret;
+			if (cur_size >= CLISH_STDOUT_MAXBUF)
+				break;
 		}
 		close(pipe1[0]);