Avoid crash of transfer logging w/default log format.
authorWayne Davison <wayne@opencoder.net>
Tue, 30 Jun 2020 19:02:48 +0000 (12:02 -0700)
committerWayne Davison <wayne@opencoder.net>
Tue, 30 Jun 2020 19:16:52 +0000 (12:16 -0700)
NEWS.md
loadparm.c
testsuite/rsync.fns

diff --git a/NEWS.md b/NEWS.md
index 8d35e252b0fb11b3da080fcb4c30c8ca50551cb4..1d6dea697ece042cdfe093aae839257914495000 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -8,6 +8,9 @@ Protocol: 31 (unchanged)
 
 ### BUG FIXES:
 
+ - Avoid a crash when a daemon module enables `transfer logging` without
+   setting a `log format` value.
+
  - Fixed installing rsync-ssl script from an alternate build dir.
 
  - Fixed the updating of configure.sh from an alternate build dir.
index 819888c5d35c9cb061333658c1823d2ab5229a76..180cf82957dd3ed51314ba9d5ce5b18541abdae4 100644 (file)
@@ -463,25 +463,25 @@ void reset_daemon_vars(void)
 
 /* Expand %VAR% references.  Any unknown vars or unrecognized
  * syntax leaves the raw chars unchanged. */
-static char *expand_vars(char *str)
+static char *expand_vars(const char *str)
 {
-       char *buf, *t, *f;
+       char *buf, *t;
+       const char *f;
        int bufsize;
 
        if (!str || !strchr(str, '%'))
-               return str;
+               return (char *)str; /* TODO change return value to const char* at some point. */
 
        bufsize = strlen(str) + 2048;
        buf = new_array(char, bufsize+1); /* +1 for trailing '\0' */
 
        for (t = buf, f = str; bufsize && *f; ) {
-               if (*f == '%' && *++f != '%') {
-                       char *percent = strchr(f, '%');
-                       if (percent) {
+               if (*f == '%' && isUpper(f+1)) {
+                       char *percent = strchr(f+1, '%');
+                       if (percent && percent - f < bufsize) {
                                char *val;
-                               *percent = '\0';
-                               val = getenv(f);
-                               *percent = '%';
+                               strlcpy(t, f+1, percent - f);
+                               val = getenv(t);
                                if (val) {
                                        int len = strlcpy(t, val, bufsize+1);
                                        if (len > bufsize)
@@ -492,7 +492,6 @@ static char *expand_vars(char *str)
                                        continue;
                                }
                        }
-                       f--;
                }
                *t++ = *f++;
                bufsize--;
index 246aab0cea84db089fd47279fa0fad2e0ec87961..58701fd739401a88e91f584efabee43fb19aa9ed 100644 (file)
@@ -297,8 +297,9 @@ use chroot = no
 munge symlinks = no
 hosts allow = localhost 127.0.0.0/24 192.168.0.0/16 10.0.0.0/8 $hostname
 log file = $logfile
-log format = %i %h [%a] %m (%u) %l %f%L
 transfer logging = yes
+# We don't define log format here so that the test-hidden module will default
+# to the internal static string (since we had a crash trying to tweak it).
 exclude = ? foobar.baz
 max verbosity = 4
 $uid_setting
@@ -306,16 +307,19 @@ $gid_setting
 
 [test-from]
        path = $fromdir
+       log format = %i %h [%a] %m (%u) %l %f%L
        read only = yes
        comment = r/o
 
 [test-to]
        path = $todir
+       log format = %i %h [%a] %m (%u) %l %f%L
        read only = no
        comment = r/w
 
 [test-scratch]
        path = $scratchdir
+       log format = %i %h [%a] %m (%u) %l %f%L
        read only = no
 
 [test-hidden]