diff options
author | bde <bde@FreeBSD.org> | 1998-04-07 12:43:57 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 1998-04-07 12:43:57 +0000 |
commit | 0c33af9265fb7ae8173e55aefcafb4e7b665963d (patch) | |
tree | c2a631242680d23eeda4536df4e979310ddd316e /sbin/fsck | |
parent | ab8f0419dac940d0aefd7faeeb881636898af449 (diff) | |
download | FreeBSD-src-0c33af9265fb7ae8173e55aefcafb4e7b665963d.zip FreeBSD-src-0c33af9265fb7ae8173e55aefcafb4e7b665963d.tar.gz |
Guess the position of the drive number in the device name better so
that `fsck -p' doesn't check multiple slices on the same drive
concurrently. Don't invoke undefined behaviour when searching for
the drive number in strange device names.
PR: 6129
Reviewed by: phk
Submitted by: Yuichi MATSUTAKA <matutaka@osa.att.ne.jp>, but rewritten
by me.
Diffstat (limited to 'sbin/fsck')
-rw-r--r-- | sbin/fsck/preen.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/sbin/fsck/preen.c b/sbin/fsck/preen.c index 383467b..de9bb55 100644 --- a/sbin/fsck/preen.c +++ b/sbin/fsck/preen.c @@ -206,12 +206,13 @@ finddisk(name) register char *p; size_t len; - for (len = strlen(name), p = name + len - 1; p >= name; --p) - if (isdigit(*p)) { - len = p - name + 1; - break; - } - + p = strrchr(name, '/'); + p = p == NULL ? name : p + 1; + while (*p != '\0' && !isdigit((u_char)*p)) + p++; + while (isdigit((u_char)*p)) + p++; + len = (size_t)(p - name); for (dk = disks, dkp = &disks; dk; dkp = &dk->next, dk = dk->next) { if (strncmp(dk->name, name, len) == 0 && dk->name[len] == 0) |