Bug 249 - findfs finds the wrong partition
Summary: findfs finds the wrong partition
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.13.x
Hardware: PC Linux
: P5 enhancement
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-31 01:48 UTC by Sam Varshavchik
Modified: 2009-05-02 14:34 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
Fix (719 bytes, patch)
2009-03-31 19:46 UTC, Denys Vlasenko
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Varshavchik 2009-03-31 01:48:11 UTC
A lengthy debugging session with kexec-tools identified what looks like a bug in busybox's internal implementation of findfs.

See the 2-3 comments starting with https://bugzilla.redhat.com/show_bug.cgi?id=476368#c38

I'm looking at the following code in busybox:

char *get_devname_from_label(const char *spec)
{
        struct uuidCache_s *uc;
        int spec_len = strlen(spec);

        uuidcache_init();
        uc = uuidCache;
        while (uc) {
// FIXME: empty label ("LABEL=") matches anything??!
                if (uc->label[0] && strncmp(spec, uc->label, spec_len) == 0) {
                        return xstrdup(uc->device);
                }
                uc = uc->next;
        }
        return NULL;
}


My existing partitions have the following labels, "/", "/home", and "/boot" (I use their mountpoints as labels, which is perfectly kosher).

The command "findfs LABEL=/" in busybox ends up returning the wrong partition to me. It looks to me like that strncmp is the culprit. The loop iterates over another partition first. strncmp("/", "/boot", 1) == 0, so this loop returns the partition that carries the "/boot" label, instead of "/". Chaos ensues...
Comment 1 Denys Vlasenko 2009-03-31 19:46:11 UTC
Created attachment 225 [details]
Fix

Try attached patch
Comment 2 Denys Vlasenko 2009-03-31 19:47:52 UTC
Applied as rev 25912.