Bug: Missing NULL-checks and weak input validation in CLI argument parsing #152
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
Several CLI argument parsing paths in
client_cli.chave inadequate input validation, risking crashes or silent misbehavior:1. str_dup() results unchecked (lines 254-255)
If
mallocfails insidestr_dup, the code continues with NULL pointers. The subsequent NULL check at line 271 will catch this, but the error message will be misleading ("source and destination directories are required" rather than "out of memory").2. str_dup() for --exclude / --include unchecked (lines 120, 130)
If
str_dupreturns NULL, the config stores a NULL pattern, and later calls toglob_matchorstrcmpmay dereference it.3. --max-size / --min-size no errno/endptr validation (lines 131-133)
Passes
NULLforendptr— garbage like--max-size abcsilently becomes 0. Noerrnocheck for overflow.4. --chunk-size no lower bound validation (line 213-215)
Passes
NULLforendptr. No upper bound check — chunk_size of ULLONG_MAX would cause allocation failures later.Location
src/client/client_cli.c:120, 130-133, 213-215, 254-255Suggested Fix
str_dupcall, with proper error message.--max-size,--min-size, and--chunk-size: pass anendptrand check*end != 0; also checkerrnoforERANGE.--chunk-size(e.g., 1 GB max).static bool parse_u64(const char* str, unsigned long long* out, unsigned long long min, unsigned long long max).Severity
High
Category
Bug / Reliability