installer: Fix disk_find() on systems that have both da1 and da10.
authorSascha Wildner <saw@online.de>
Thu, 29 May 2014 06:26:47 +0000 (08:26 +0200)
committerSascha Wildner <saw@online.de>
Thu, 29 May 2014 06:26:47 +0000 (08:26 +0200)
In addition to comparing names (up to the length of the disk which
was found previously), also compare name lengths.

While here, remove the disk_find() check in disk_new(). disk_new()
didn't deal with it returning NULL. But because the list of disks
we offer as targets for installing is taken from sysctl kern.disks'
output, it will not have duplicates (else it would likely be a bug
in the kernel).

Reported-by: BSDUX on IRC
usr.sbin/installer/libinstaller/diskutil.c

index 82fa689..2ca75c5 100644 (file)
@@ -153,11 +153,6 @@ disk_new(struct storage *s, const char *dev_name)
 {
        struct disk *d;
 
-       if (disk_find(s, dev_name) != NULL) {
-               /* Already discovered */
-               return(NULL);
-       }
-
        AURA_MALLOC(d, disk);
 
        d->device = aura_strdup(dev_name);
@@ -275,7 +270,8 @@ disk_find(const struct storage *s, const char *device)
        struct disk *d = s->disk_head;
 
        while (d != NULL) {
-               if (strncmp(device, d->device, strlen(d->device)) == 0)
+               if (strncmp(device, d->device, strlen(d->device)) == 0 &&
+                   strlen(device) == strlen(d->device))
                        return(d);
                d = d->next;
        }