diff options
| author | Naveed Khan <naveed@digiscrypt.com> | 2026-06-22 02:39:41 +0530 |
|---|---|---|
| committer | Mark Wielaard <mark@klomp.org> | 2026-06-22 00:37:44 +0200 |
| commit | f153ef257a8e8901d8f8ed96fd1a2467806e8755 (patch) | |
| tree | 5aff4e491d88408493934fdc4da7db837515d36c | |
| parent | 9515e7ff78facd349ba3d86a637be71acaccc02e (diff) | |
| download | bzip2-f153ef257a8e8901d8f8ed96fd1a2467806e8755.tar.gz bzip2-f153ef257a8e8901d8f8ed96fd1a2467806e8755.tar.bz2 bzip2-f153ef257a8e8901d8f8ed96fd1a2467806e8755.zip | |
bzip2recover: Check argc >= 1 && argv[0] != NULL
main() initialises progName by copying argv[0] with strncpy before argc
is examined. When the program is started with an empty argument vector
(argc == 0 and argv[0] == NULL), for example through
execve(path, (char*[]){ NULL }, envp), this dereferences a NULL pointer
and bzip2recover crashes with SIGSEGV before any argument checking
happens.
Guard the use of argv[0] and fall back to a hard coded "bzip2recover"
string, mirroring the fix already applied to bzip2.c in commit
af79253677ad ("bzip2.c: Check argc >= 1 && argv[0] != NULL").
| -rw-r--r-- | bzip2recover.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/bzip2recover.c b/bzip2recover.c index 28d4a05..8c79a90 100644 --- a/bzip2recover.c +++ b/bzip2recover.c | |||
| @@ -311,7 +311,10 @@ Int32 main ( Int32 argc, Char** argv ) | |||
| 311 | UInt32 buffHi, buffLo, blockCRC; | 311 | UInt32 buffHi, buffLo, blockCRC; |
| 312 | Char* p; | 312 | Char* p; |
| 313 | 313 | ||
| 314 | strncpy ( progName, argv[0], BZ_MAX_FILENAME-1); | 314 | if (argc >= 1 && argv[0] != NULL) |
| 315 | strncpy ( progName, argv[0], BZ_MAX_FILENAME-1); | ||
| 316 | else | ||
| 317 | strncpy ( progName, "bzip2recover", BZ_MAX_FILENAME-1); | ||
| 315 | progName[BZ_MAX_FILENAME-1]='\0'; | 318 | progName[BZ_MAX_FILENAME-1]='\0'; |
| 316 | inFileName[0] = outFileName[0] = 0; | 319 | inFileName[0] = outFileName[0] = 0; |
| 317 | 320 | ||
