[Bug 627] modprobe-small: incorrect alias-based probe with dep_bb_fd < 0

bugzilla at busybox.net bugzilla at busybox.net
Mon Sep 28 11:27:32 UTC 2009


https://bugs.busybox.net/show_bug.cgi?id=627





--- Comment #12 from Jiri J. <jirij.jabb at gmail.com>  2009-09-28 11:27:30 UTC ---
I've tried to write down an algorithm that does the "3rd idea", I ended up in
doing substring matches and counting characters back to the last match, when I
realized all this can be done much more easily.
Consider the following example:

#include <stdio.h>
#include <string.h>

#define ASTERISK_CHR '*'

int alias_match(const char *in_alias,
                const char *cmp_alias)
{
        char *pos;
        int count;

        /* count asterisks */
        count = 0;
        pos = strchr(cmp_alias, ASTERISK_CHR);
        while (pos != NULL)
        {
                pos = strchr(pos+1, ASTERISK_CHR);
                count++;
        }

        /* calculate wildcard replacement */
        count = strlen(in_alias) - (strlen(cmp_alias) - count);

        return count;
}

int main(int argc, char **argv)
{
        int num1;
        int num2;

        /* 1: input, 2: old alias, 3: new alias to compare */
        if (argc < 4)
                return 1;

        /* if the number of asterisk-replaced characters
         * in the new alias is lesser, use it, otherwise
         * use the old alias (this includes num1==num2) */
        num1 = alias_match(argv[1], argv[2]);
        num2 = alias_match(argv[1], argv[3]);

        printf("use %s\n", num1 > num2 ? argv[3] : argv[2]);

        return 0;
}


$ ./a.out \
> v00008086d00007010sv00000000sd00000000bc01sc01i80 \
> v*d*sv*sd*bc01sc01i* \
> v00008086d00007010sv*sd*bc*sc*i*
use v00008086d00007010sv*sd*bc*sc*i*

I believe it should be accurate enough for the rare cases where two or more
aliases matches the provided pattern.
If you diagree, you can simply modify the function to return original asterisk
count as well and do some more checks.


-- 
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


More information about the busybox-cvs mailing list