]> git.ipfire.org Git - thirdparty/fcron.git/commitdiff
Fix bug where fcrondyn joins two output lines together if a shell command is too...
authorThibault Godouet <yo8192@users.noreply.github.com>
Wed, 29 May 2024 16:24:28 +0000 (17:24 +0100)
committerThibault Godouet <yo8192@users.noreply.github.com>
Wed, 29 May 2024 16:24:28 +0000 (17:24 +0100)
fcrondyn_svr.c

index b27eae3583cef339b3c87e8b9eeedfddc0913c39..ee8800cb91dd5b98b1cbdffc321faeea03fe28c7 100644 (file)
@@ -58,6 +58,7 @@ int fcrondyn_cl_num = 0;        /* number of fcrondyn clients currently connecte
 int listen_fd = -1;             /* fd which catches incoming connection */
 int auth_fail = 0;              /* number of auth failure */
 time_t auth_nofail_since = 0;   /* we refuse auth since x due to too many failures */
+static char truncated[] = " (truncated)\n";
 
 /* some error messages ... */
 char err_no_err_str[] = "Command successfully completed.\n";
@@ -474,14 +475,21 @@ print_line(int fd, struct cl_t *line, unsigned char *details, pid_t pid,
     }
     len += snprintf(buf + len, sizeof(buf) - len, "|%s\n", line->cl_shell);
 
+    /* snprintf() returns the length of what would have been written (excluding terminating null byte)
+      if not limited by maxlen */
+    if (len+1 > sizeof(buf)) {
+        /* the shell command string was too long and was truncated */
+        strcpy(buf + sizeof(buf) - sizeof(truncated), truncated);
+    }
+
     /* as extra safety to make sure the string is always null-terminated
       (even though snprintf man page suggests it does it already) */
     buf[sizeof(buf) - 1] = '\0';
 
     /* add +1 to include the final end-of-string "\0" */
-    if (send(fd, buf, (len+1 < sizeof(buf)) ? len+1 : sizeof(buf), 0) < 0)
+    if (send(fd, buf, (len+1 < sizeof(buf)) ? len+1 : sizeof(buf), 0) < 0) {
         error_e("error in send()");
-
+    }
 }