Bug 27071 - fsck can't find filesystems with 16 character labels
Summary: fsck can't find filesystems with 16 character labels
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: e2fsprogs
Version: 7.1
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Florian La Roche
QA Contact: Aaron Brown
Depends On:
TreeView+ depends on / blocked
Reported: 2001-02-11 18:56 UTC by Mike Fleetwood
Modified: 2007-04-18 16:31 UTC (History)
1 user (show)

Clone Of:
Last Closed: 2001-02-11 19:06:26 UTC

Attachments (Terms of Use)
Code fix (578 bytes, patch)
2001-02-11 19:06 UTC, Mike Fleetwood
no flags Details | Diff

Description Mike Fleetwood 2001-02-11 18:56:30 UTC
Fsck fails to find a filesystem which uses a 16 character volume label.  15
character (and less) labels work.  The error message reported when root
tries to fsck a filesystem is:

    [root]# fsck LABEL=opt1_67890123456
    Couldn't find matching filesystem: LABEL=opt1_67890123456

and for non-root users the error is:

    [mike]$ /sbin/fsck LABEL=opt1_67890123456
    Must be root to scan for matching filesystems: LABEL=opt1_67890123456

The problem is caused by using strdup() to copy the volume label from the
e2fs superblock structure in memory.  The volume label is a 16 character
fixed sized array, not a NUL terminated C string.  It works with labels
less than 16 characters because the array is NUL byte padded up to 16
characters.  When a 16 character label is used strdup() includes random
data from the stack until a 0 byte is found.  (Fsck uses a cut down version
of the e2fs superblock structure which ends with s_last_mounted, hence
random data from the stack and not data from the "Last mounted on" field,
s_last_mounted, is appended).

The faulty code is in:

Mount does not have the same fault.  Its code correctly handles a non-NUL
terminated character array.  See:

Find fix for this problem in the attached file:
1) Rawhide also uses the same e2fprogs RPM so is also effected.

2) All platforms are probably effected, but it has only been verified on

3) The fix also adds inclusion of stdlib.h for the required malloc()
function prototype, but half the source files in e2fsprogs-1.19/misc just

    #include <stdio.h>

and the other half use:

    #ifdef HAVE_STDLIB_H
    #include <stdlib.h>

Comment 1 Mike Fleetwood 2001-02-11 19:06:23 UTC
Created attachment 9680 [details]
Code fix

Comment 2 Florian La Roche 2001-02-12 14:39:37 UTC
Thanks a lo for this patch.

Note You need to log in before you can comment on or make changes to this bug.