aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexander Færøy <ahf@torproject.org>2017-03-17 04:18:31 +0100
committerAlexander Færøy <ahf@0x90.dk>2017-03-17 04:27:12 +0100
commita28be68cf21353ca860dc4455b064155678ca2c0 (patch)
tree1821bd458a797ecf04420e0e4d40e80b515f9f5d /src
parent7505f452c865ef9ca5be35647032f93bfb392762 (diff)
downloadtor-a28be68cf21353ca860dc4455b064155678ca2c0.tar.gz
tor-a28be68cf21353ca860dc4455b064155678ca2c0.zip
Split strings at newline in tor_get_lines_from_handle().
This patch fixes a regression described in bug #21757 that first appeared after commit 6e78ede73f which was an attempt to fix bug #21654. When switching from buffered I/O to direct file descriptor I/O our output strings from get_string_from_pipe() might contain newline characters (\n). In this patch we modify tor_get_lines_from_handle() to ensure that the function splits the newly read string at the newline character and thus might return multiple lines from a single call to get_string_from_pipe(). Additionally, we add a test case to test_util_string_from_pipe() to ensure that get_string_from_pipe() correctly returns multiple lines in a single call. See: https://bugs.torproject.org/21757 See: https://bugs.torproject.org/21654
Diffstat (limited to 'src')
-rw-r--r--src/common/util.c2
-rw-r--r--src/test/test_util.c10
2 files changed, 11 insertions, 1 deletions
diff --git a/src/common/util.c b/src/common/util.c
index e800fa7b6c..93befe9d77 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -5270,7 +5270,7 @@ tor_get_lines_from_handle, (int fd, enum stream_status *stream_status_out))
goto done;
if (!lines) lines = smartlist_new();
- smartlist_add_strdup(lines, stdout_buf);
+ smartlist_split_string(lines, stdout_buf, "\n", 0, 0);
}
done:
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 38401305ef..203f9dd1c4 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -4029,6 +4029,16 @@ test_util_string_from_pipe(void *ptr)
tt_mem_op(buf, OP_EQ, "B\0\xff\xff", sizeof(buf));
errno = 0;
+ /* Send in multiple lines. */
+ retlen = write(test_pipe[1], "A\nB", 3);
+ tt_int_op(retlen, OP_EQ, 3);
+
+ status = get_string_from_pipe(test_pipe[0], buf, sizeof(buf)-1);
+ tt_int_op(errno, OP_EQ, 0);
+ tt_int_op(status, OP_EQ, IO_STREAM_OKAY);
+ tt_str_op(buf, OP_EQ, "A\nB");
+ errno = 0;
+
/* Send in a line and close */
retlen = write(test_pipe[1], "AB", 2);
tt_int_op(retlen, OP_EQ, 2);