From d1c06c2180f337deaa059fc408fcca4f4770a585 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Mon, 3 Mar 2008 18:33:11 -0800 Subject: [PATCH] Fixing a problem with a NULL config_file pointer when accessing a single-use daemon without no --config option specified. Added a test to ensure that this doesn't break in the future. --- clientserver.c | 22 +++++++++++++--------- testsuite/daemon.test | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/clientserver.c b/clientserver.c index a3301117..7c15e3bf 100644 --- a/clientserver.c +++ b/clientserver.c @@ -864,6 +864,17 @@ static void send_listing(int fd) io_printf(fd,"@RSYNCD: EXIT\n"); } +static int load_config(int globals_only) +{ + if (!config_file) { + if (am_server && am_root <= 0) + config_file = RSYNCD_USERCONF; + else + config_file = RSYNCD_SYSCONF; + } + return lp_load(config_file, globals_only); +} + /* this is called when a connection is established to a client and we want to start talking. The setup of the system is done from here */ @@ -879,7 +890,7 @@ int start_daemon(int f_in, int f_out) * might cause log-file output to occur. This ensures that the * "log file" param gets honored for the 2 non-forked use-cases * (when rsync is run by init and run by a remote shell). */ - if (!lp_load(config_file, 0)) + if (!load_config(0)) exit_cleanup(RERR_SYNTAX); addr = client_addr(f_in); @@ -988,13 +999,6 @@ static void become_daemon(void) int daemon_main(void) { - if (!config_file) { - if (am_server && am_root <= 0) - config_file = RSYNCD_USERCONF; - else - config_file = RSYNCD_SYSCONF; - } - if (is_a_socket(STDIN_FILENO)) { int i; @@ -1009,7 +1013,7 @@ int daemon_main(void) return start_daemon(STDIN_FILENO, STDIN_FILENO); } - if (!lp_load(config_file, 1)) { + if (!load_config(1)) { fprintf(stderr, "Failed to parse config file: %s\n", config_file); exit_cleanup(RERR_SYNTAX); } diff --git a/testsuite/daemon.test b/testsuite/daemon.test index 54865053..439b8835 100644 --- a/testsuite/daemon.test +++ b/testsuite/daemon.test @@ -24,8 +24,29 @@ . "$suitedir/rsync.fns" +SSH="$scratchdir/pretend-ssh" + +cat >"$SSH" <<'EOT' +while : ; do + case "$1" in + -*) shift ;; + localhost) shift; break ;; + *) exit 1 ;; + esac +done + +eval "${@}" +EOT +chmod +x "$SSH" + build_rsyncd_conf +cd "$scratchdir" + +ln -s test-rsyncd.conf rsyncd.conf + +$RSYNC -ve $SSH --rsync-path="$RSYNC" localhost:: + RSYNC_CONNECT_PROG="$RSYNC --config=$conf --daemon" export RSYNC_CONNECT_PROG -- 2.34.1