e2fsprogs icon indicating copy to clipboard operation
e2fsprogs copied to clipboard

Uninitialized Variable Bug in e2fsprogs/e2fsck/emptydir.c (Possible Code Oversight?)

Open zkh8227 opened this issue 8 months ago • 1 comments

Uninitialized Variable Bug in e2fsprogs/e2fsck/emptydir.c (Possible Code Oversight?) #Issue Description In the init_empty_dir function of the e2fsprogs/e2fsck/emptydir.c file, the variable retval is used without being initialized. This may lead to undefined behavior.

#Detail https://github.com/tytso/e2fsprogs/blob/master/e2fsck/emptydir.c#L49

empty_dir_info init_empty_dir(e2fsck_t ctx) { empty_dir_info edi; errcode_t retval; edi = e2fsck_allocate_memzero(ctx, sizeof(struct empty_dir_info_struct),"empty dir info"); if (retval) return NULL; .... } The retval in the if statement here is not initialized. Judging from the code context, it is likely that the wrong variable is used. Maybe edi should be used here instead?

zkh8227 avatar May 12 '25 04:05 zkh8227

Yes; but note that e2fsck/emptydir.c isn't actually used. As near as I can tell, it was a partially written source file that was never used, but was checked in about the time that we converted from RCS to BitKeeper. We've since ported the source code management system used for e2fsprogs from BitKeeper to Mercurial, and then from Mercurial from git, but this is where this source file entered the source code history:

commit f75c28de4731c2cd09f6ca1a23e25c968a1edc2f Author: Theodore Ts'o [email protected] Date: Sat Aug 1 04:18:06 1998 +0000

ChangeLog, e2fsck.c, pass2.c, pass3.c, unix.c:
  pass2.c (e2fsck_pass2): Fix the progress accounting so that we get to
        100%.
  pass3.c (e2fsck_pass3): Change progress accounting to be consistent
        with the other e2fsck passes.
  e2fsck.c (e2fsck_run): At the end of each pass, call the progress
        function with the pass number set to zero.
  unix.c (e2fsck_update_progress): If the pass number is zero, ignore
        the call, since that indicates that we just want to deallocate any
        progress structures.
emptydir.c:
  Commit partially done file.
ChangeLog, badblocks.c:
  badblocks.c (ext2fs_badblocks_list_add): Use a bigger increment than
        10 blocks when we need to expand the size of the badblocks list.

I'll fix it, but then I'll end up deleting the source file. It will still be in the git history, so if we need the (never finished, probably never tested) sources, we can always resurrect it.

tytso avatar May 12 '25 12:05 tytso