Skip to content

Commit

Permalink
Make --max-alloc=0 safer.
Browse files Browse the repository at this point in the history
Always do size checking in my_alloc(), even for `--max-alloc=0`.
  • Loading branch information
WayneD committed Jun 27, 2023
1 parent 3476cae commit 2f9b963
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion rsync.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion util2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2f9b963

Please sign in to comment.