]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
options.c: Fix segv if poptGetContext returns NULL
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 30 Jan 2025 03:27:38 +0000 (13:27 +1000)
committerAndrew Tridgell <andrew@tridgell.net>
Sat, 23 Aug 2025 07:49:03 +0000 (17:49 +1000)
If poptGetContext returns NULL, perhaps due to OOM,
a NULL pointer is passed into poptReadDefaultConfig()
which in turns SEGVs when trying to dereference it.

This was found using https://github.com/sahlberg/malloc-fail-tester.git
$ ./test_malloc_failure.sh rsync -Pav crash crosh

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
options.c

index 55aef66c943de78c9233d71cb603caddf554a9e0..74b39bf6a530ad3ff7bfd8f76cd028dda8e91d7f 100644 (file)
--- a/options.c
+++ b/options.c
@@ -1372,6 +1372,10 @@ int parse_arguments(int *argc_p, const char ***argv_p)
        /* TODO: Call poptReadDefaultConfig; handle errors. */
 
        pc = poptGetContext(RSYNC_NAME, argc, argv, long_options, 0);
+       if (pc == NULL) {
+               strlcpy(err_buf, "poptGetContext returned NULL\n", sizeof err_buf);
+               return 0;
+       }
        if (!am_server) {
                poptReadDefaultConfig(pc, 0);
                popt_unalias(pc, "--daemon");