From 317beebef8b0f60eb36255b35cbea71c84f6ac38 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Tue, 30 Jun 2020 12:02:48 -0700 Subject: [PATCH] Avoid crash of transfer logging w/default log format. --- NEWS.md | 3 +++ loadparm.c | 19 +++++++++---------- testsuite/rsync.fns | 6 +++++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8d35e252b..1d6dea697 100644 --- 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. diff --git a/loadparm.c b/loadparm.c index 819888c5d..180cf8295 100644 --- a/loadparm.c +++ b/loadparm.c @@ -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--; diff --git a/testsuite/rsync.fns b/testsuite/rsync.fns index 246aab0ce..58701fd73 100644 --- a/testsuite/rsync.fns +++ b/testsuite/rsync.fns @@ -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]