]> git.ipfire.org Git - thirdparty/HylaFAX.git/commitdiff
Allow non-nul terminated messages on the PIPE
authorPatrice Fournier <pfournier@ifax.com>
Sun, 29 Apr 2012 00:51:26 +0000 (20:51 -0400)
committerPatrice Fournier <patrice.fournier@ifax.com>
Mon, 5 Aug 2024 09:42:35 +0000 (05:42 -0400)
non-nul terminated messages on the PIPE will be accepted so that messages
can be sent with echo. But such message need to be parsed by the daemon
before a new message come in, else the behaviour is unspecified.

faxd/faxApp.c++

index 7ddf56686b14d32d03830fb603dc774e972e0360..fd99008d5ce9ab5f4dfec67184e9595ba83c1422 100644 (file)
@@ -163,7 +163,7 @@ faxApp::FIFOInput(int fd)
        char* bp = &buf[0];
        do {
            char* cp = strchr(bp, '\0');
-           if (cp == &buf[n]) {
+           if (bp != &buf[0] && cp == &buf[n]) {
                /*
                 * We reached the end of the read buffer, but the last message
                 * is missing it's NUL terminator. The message must be
@@ -173,7 +173,13 @@ faxApp::FIFOInput(int fd)
                u_int left = cp-bp;
                memmove(buf, bp, left);
                n = Sys::read(fd, &buf[left], sizeof (buf)-1-left);
-               n += left;
+               if (n == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
+                   /* There is nothing left to read. The message must not be
+                       NUL terminated. (maybe sent with "echo") */
+                   n = left + 1;
+                   buf[n-1] = '\0';
+               } else
+                   n += left;
                buf[n] = '\0';
                bp = &buf[0];
            } else if (cp > bp) {