summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2010-12-08 15:19:36 +0000
committerStef Walter <stef@memberwebs.com>2010-12-08 15:19:36 +0000
commitd6039235778a7dacacf1abf2e1d6e34c8dfbf065 (patch)
tree88558a61262f45431a3b079b241deced5f63b052
parentba68e5648d3b8ad270baa4391a42b8c5bc87df1b (diff)
Fix problems parsing multiple line input.
-rw-r--r--.gitignore2
-rw-r--r--tools/notify-dns-slaves.c29
2 files changed, 20 insertions, 11 deletions
diff --git a/.gitignore b/.gitignore
index ecd03bf..d9f9c32 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,8 @@ Makefile
Makefile.in
run-tests*
*.tar.gz
+/.cproject
+/.project
/aclocal.m4
/autom4te.cache
diff --git a/tools/notify-dns-slaves.c b/tools/notify-dns-slaves.c
index e2c3325..65e5a5a 100644
--- a/tools/notify-dns-slaves.c
+++ b/tools/notify-dns-slaves.c
@@ -725,41 +725,48 @@ static void
stdin_callback (int fd, int type, void *arg)
{
char *line;
- int num;
+ int num, rc;
assert (fd == 0);
- num = read (fd, stdin_buffer + stdin_offset, LINE_LENGTH - stdin_offset);
- if (num < 0) {
+ rc = read (fd, stdin_buffer + stdin_offset, LINE_LENGTH - stdin_offset);
+ if (rc < 0) {
if (errno == EAGAIN || errno == EINTR)
return;
warningx ("couldn't read from stdin");
input_complete = 1;
- } else if (num == 0) {
+ } else if (rc == 0) {
debug ("input closed");
input_complete = 1;
} else {
- stdin_offset += num;
+ stdin_offset += rc;
+ assert (stdin_offset <= LINE_LENGTH);
}
do {
- line = strchr (stdin_buffer, '\n');
+ line = memchr (stdin_buffer, '\n', stdin_offset);
+
+ if (line) {
+ num = (line - stdin_buffer) + 1;
- if (!line && input_complete)
+ } else if (!line && input_complete) {
line = stdin_buffer + stdin_offset;
+ num = line - stdin_buffer;
- if (!line && stdin_offset >= LINE_LENGTH) {
+ } else if (!line && stdin_offset >= LINE_LENGTH) {
warningx ("input line too long");
line = stdin_buffer + LINE_LENGTH;
- }
+ num = LINE_LENGTH;
- if (!line) /* Wait for more data */
+ } else {
+ /* Wait for more data */
break;
+ }
*line = 0;
- num = (line + 1) - stdin_buffer;
process_stdin_line (stdin_buffer);
+ assert (stdin_offset >= num);
stdin_offset = stdin_offset - num;
if (stdin_offset)
memmove (stdin_buffer, stdin_buffer + num, stdin_offset);