Bug 27071 - fsck can't find filesystems with 16 character labels
Summary: fsck can't find filesystems with 16 character labels
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: e2fsprogs
Version: 7.1
Hardware: i386
OS: Linux
medium
low
Target Milestone: ---
Assignee: Florian La Roche
QA Contact: Aaron Brown
URL:
Whiteboard:
Depends On:
Blocks:
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)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2001-02-11 19:06:26 UTC
Embargoed:


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:
e2fsprogs-1.19/misc/get_device_by_label.c:get_label_uuid().

Mount does not have the same fault.  Its code correctly handles a non-NUL
terminated character array.  See:
util-linux-2.10p/mount/mount_by_label.c:get_label_uuid().

Find fix for this problem in the attached file:
e2fsprogs-1.19-16clabel.patch.
    
NOTES:
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
i386.

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
use:

    #include <stdio.h>

and the other half use:

    #ifdef HAVE_STDLIB_H
    #include <stdlib.h>
    #endif

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.