Make `--max-alloc=0` safer.
authorWayne Davison <wayne@opencoder.net>
Tue, 27 Jun 2023 16:01:15 +0000 (09:01 -0700)
committerWayne Davison <wayne@opencoder.net>
Tue, 27 Jun 2023 16:01:25 +0000 (09:01 -0700)
Always do size checking in my_alloc(), even for `--max-alloc=0`.

options.c
rsync.1.md
util2.c

index 93bbe7b06cc535deb7e38e7503c41df052bafdd8..fd674754cd5e4992b05050d69c092cf207979c91 100644 (file)
--- a/options.c
+++ b/options.c
@@ -1946,6 +1946,8 @@ int parse_arguments(int *argc_p, const char ***argv_p)
                        goto cleanup;
                max_alloc = size;
        }
+       if (!max_alloc)
+               max_alloc = SIZE_MAX;
 
        if (old_style_args < 0) {
                if (!am_server && protect_args <= 0 && (arg = getenv("RSYNC_OLD_ARGS")) != NULL && *arg) {
index 894b3663227c4194966c88df649dc629340c71d2..2ae6f4816d742060bcbf22a88b727bb9e8454919 100644 (file)
@@ -2106,7 +2106,8 @@ expand it.
     See the [`--max-size`](#opt) option for a description of how SIZE can be
     specified.  The default suffix if none is given is bytes.
 
-    Beginning in 3.2.3, a value of 0 specifies no limit.
+    Beginning in 3.2.7, a value of 0 is an easy way to specify SIZE_MAX (the
+    largest limit possible).
 
     You can set a default value using the environment variable
     [`RSYNC_MAX_ALLOC`](#) using the same SIZE values as supported by this
diff --git a/util2.c b/util2.c
index a8609a5d5931d60e7907265f94868ef585df785e..3b5a8f41478c48ce10623ce9c004c51a8f6cbfc3 100644 (file)
--- a/util2.c
+++ b/util2.c
@@ -72,7 +72,7 @@ int msleep(int t)
 
 void *my_alloc(void *ptr, size_t num, size_t size, const char *file, int line)
 {
-       if (max_alloc && num >= max_alloc/size) {
+       if (num >= max_alloc/size) {
                if (!file)
                        return NULL;
                rprintf(FERROR, "[%s] exceeded --max-alloc=%s setting (file=%s, line=%d)\n",