Skip to content

Commit

Permalink
Avoid potential NULL dereference when argv[0]
Browse files Browse the repository at this point in the history
Addresses-Coverity-Bug: 1500772
Addresses-Coverity-Bug: 1500769
Addresses-Coverity-Bug: 1500767
Addresses-Coverity-Bug: 1500758
Addresses-Coverity-Bug: 1500756
Signed-off-by: Theodore Ts'o <[email protected]>
  • Loading branch information
tytso committed Aug 12, 2022
1 parent e8b05eb commit 7bb8da7
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 4 deletions.
8 changes: 6 additions & 2 deletions e2fsck/unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@ int journal_enable_debug = -1;

static void usage(e2fsck_t ctx)
{
char *program_name = "e2fsck";

if (ctx && ctx->program_name)
program_name = ctx>program_name;
fprintf(stderr,
_("Usage: %s [-panyrcdfktvDFV] [-b superblock] [-B blocksize]\n"
"\t\t[-l|-L bad_blocks_file] [-C fd] [-j external_journal]\n"
"\t\t[-E extended-options] [-z undo_file] device\n"),
ctx->program_name);
program_name);

fprintf(stderr, "%s", _("\nEmergency help:\n"
" -p Automatic repair (no questions)\n"
Expand Down Expand Up @@ -849,7 +853,7 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
if (argc && *argv)
ctx->program_name = *argv;
else
ctx->program_name = "e2fsck";
usage(NULL);

phys_mem_kb = get_memory_size() / 1024;
ctx->readahead_kb = ~0ULL;
Expand Down
2 changes: 2 additions & 0 deletions misc/badblocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,8 @@ int main (int argc, char ** argv)

if (argc && *argv)
program_name = *argv;
else
usage();
while ((c = getopt (argc, argv, "b:d:e:fi:o:svwnc:p:h:t:BX")) != EOF) {
switch (c) {
case 'b':
Expand Down
3 changes: 2 additions & 1 deletion misc/dumpe2fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,8 @@ int main (int argc, char ** argv)
mmp_check = 1;
header_only = 1;
}
}
} else
usage();

if (!mmp_check)
fprintf(stderr, "dumpe2fs %s (%s)\n", E2FSPROGS_VERSION,
Expand Down
2 changes: 2 additions & 0 deletions misc/e2image.c
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,8 @@ int main (int argc, char ** argv)
E2FSPROGS_DATE);
if (argc && *argv)
program_name = *argv;
else
usage();
add_error_table(&et_ext2_error_table);
while ((c = getopt(argc, argv, "b:B:nrsIQafo:O:pc")) != EOF)
switch (c) {
Expand Down
2 changes: 2 additions & 0 deletions misc/lsattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ int main (int argc, char ** argv)
#endif
if (argc && *argv)
program_name = *argv;
else
usage();
while ((c = getopt (argc, argv, "RVadlvp")) != EOF)
switch (c)
{
Expand Down
2 changes: 2 additions & 0 deletions misc/tune2fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2951,6 +2951,8 @@ int tune2fs_main(int argc, char **argv)
#endif
if (argc && *argv)
program_name = *argv;
else
usage();
add_error_table(&et_ext2_error_table);

#ifdef CONFIG_BUILD_FINDFS
Expand Down
4 changes: 3 additions & 1 deletion resize/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void usage (char *prog)
fprintf (stderr, _("Usage: %s [-d debug_flags] [-f] [-F] [-M] [-P] "
"[-p] device [-b|-s|new_size] [-S RAID-stride] "
"[-z undo_file]\n\n"),
prog);
prog ? prog : "resize2fs");

exit (1);
}
Expand Down Expand Up @@ -287,6 +287,8 @@ int main (int argc, char ** argv)
E2FSPROGS_VERSION, E2FSPROGS_DATE);
if (argc && *argv)
program_name = *argv;
else
usage(NULL);

while ((c = getopt(argc, argv, "d:fFhMPpS:bsz:")) != EOF) {
switch (c) {
Expand Down

0 comments on commit 7bb8da7

Please sign in to comment.