* util/getroot.c (find_root_devices_from_libzfs): Fix compilation error.

(grub_guess_root_devices): Replace strlen with sizeof.
	Avoid crash.
	(find_root_devices_from_poolname): Remove unused variable.
	Handle raidzN.
This commit is contained in:
Richard Laager 2012-02-03 10:50:56 +01:00 committed by Vladimir 'phcoder' Serbinenko
parent cf5f7ee788
commit e9084abefd
2 changed files with 23 additions and 8 deletions

View file

@ -1,3 +1,11 @@
2012-02-03 Richard Laager <rlaager@wiktel.com>
* util/getroot.c (find_root_devices_from_libzfs): Fix compilation error.
(grub_guess_root_devices): Replace strlen with sizeof.
Avoid crash.
(find_root_devices_from_poolname): Remove unused variable.
Handle raidzN.
2012-02-03 Vladimir Serbinenko <phcoder@gmail.com> 2012-02-03 Vladimir Serbinenko <phcoder@gmail.com>
Support install on multi-device filesystems. Support install on multi-device filesystems.

View file

@ -291,9 +291,11 @@ find_root_devices_from_poolname (char *poolname)
case 2: case 2:
if (strcmp (name, "mirror") && !sscanf (name, "mirror-%u", &dummy) if (strcmp (name, "mirror") && !sscanf (name, "mirror-%u", &dummy)
&& !sscanf (name, "raidz%u", &dummy) && !sscanf (name, "raidz%u", &dummy)
&& !sscanf (name, "raidz1%u", &dummy)
&& !sscanf (name, "raidz2%u", &dummy)
&& !sscanf (name, "raidz3%u", &dummy)
&& !strcmp (state, "ONLINE")) && !strcmp (state, "ONLINE"))
{ {
char *tmp;
if (ndevices >= devices_allocated) if (ndevices >= devices_allocated)
{ {
devices_allocated = 2 * (devices_allocated + 8); devices_allocated = 2 * (devices_allocated + 8);
@ -512,7 +514,7 @@ grub_find_root_devices_from_mountinfo (const char *dir, char **relroot)
static char ** static char **
find_root_devices_from_libzfs (const char *dir) find_root_devices_from_libzfs (const char *dir)
{ {
char **device = NULL; char **devices = NULL;
char *poolname; char *poolname;
char *poolfs; char *poolfs;
@ -520,13 +522,13 @@ find_root_devices_from_libzfs (const char *dir)
if (! poolname) if (! poolname)
return NULL; return NULL;
device = find_root_devices_from_poolname (poolname); devices = find_root_devices_from_poolname (poolname);
free (poolname); free (poolname);
if (poolfs) if (poolfs)
free (poolfs); free (poolfs);
return device; return devices;
} }
#ifdef __MINGW32__ #ifdef __MINGW32__
@ -799,9 +801,9 @@ grub_guess_root_devices (const char *dir)
grub_util_error (_("Storage name for `%s' not NUL-terminated"), dir); grub_util_error (_("Storage name for `%s' not NUL-terminated"), dir);
os_dev = xmalloc (2 * sizeof (os_dev[0])); os_dev = xmalloc (2 * sizeof (os_dev[0]));
os_dev[0] = xmalloc (strlen ("/dev/") + data_len); os_dev[0] = xmalloc (sizeof ("/dev/") - 1 + data_len);
memcpy (os_dev[0], "/dev/", strlen ("/dev/")); memcpy (os_dev[0], "/dev/", sizeof ("/dev/") - 1);
memcpy (os_dev[0] + strlen ("/dev/"), data, data_len); memcpy (os_dev[0] + sizeof ("/dev/") - 1, data, data_len);
os_dev[1] = 0; os_dev[1] = 0;
if (ports && num_ports > 0) if (ports && num_ports > 0)
@ -842,7 +844,12 @@ grub_guess_root_devices (const char *dir)
{ {
char *tmp = *cur; char *tmp = *cur;
int root, dm; int root, dm;
*cur = canonicalize_file_name (*cur); *cur = canonicalize_file_name (tmp);
if (*cur == NULL)
{
grub_util_error (_("failed to get canonical path of %s"), tmp);
break;
}
free (tmp); free (tmp);
root = (strcmp (*cur, "/dev/root") == 0); root = (strcmp (*cur, "/dev/root") == 0);
dm = (strncmp (*cur, "/dev/dm-", sizeof ("/dev/dm-") - 1) == 0); dm = (strncmp (*cur, "/dev/dm-", sizeof ("/dev/dm-") - 1) == 0);