From 9a06490c079589ba01a5b847b6c30ef985853363 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 21 Apr 2012 16:49:56 +0200 Subject: [PATCH] Fix kfreebsd compile and behaviour. * grub-core/kern/emu/hostdisk.c (grub_util_follow_gpart_up): Fix format-security. * util/getroot.c: Fix wait.h include. (grub_guess_root_devices): Error if grub_find_device fails. (grub_util_get_geom_abstraction): Fix shadowing and format-security. (grub_util_get_dev_abstraction): Likewise. (grub_util_pull_device): Likewise. (grub_util_get_grub_dev): Likewise. * util/lvm.c (grub_util_lvm_isvolume): Likewise. --- ChangeLog | 14 ++++++++ grub-core/kern/emu/hostdisk.c | 4 +-- util/getroot.c | 60 +++++++++++++++++++---------------- util/lvm.c | 12 +++---- 4 files changed, 55 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 28b4a9f00..986267b9c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2012-04-21 Vladimir Serbinenko + + Fix kfreebsd compile and behaviour. + + * grub-core/kern/emu/hostdisk.c (grub_util_follow_gpart_up): Fix + format-security. + * util/getroot.c: Fix wait.h include. + (grub_guess_root_devices): Error if grub_find_device fails. + (grub_util_get_geom_abstraction): Fix shadowing and format-security. + (grub_util_get_dev_abstraction): Likewise. + (grub_util_pull_device): Likewise. + (grub_util_get_grub_dev): Likewise. + * util/lvm.c (grub_util_lvm_isvolume): Likewise. + 2012-04-21 Vladimir Serbinenko Fix and unify wholedisk detection. diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 531fc026f..3b41ce8a9 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -438,7 +438,7 @@ grub_util_follow_gpart_up (const char *name, grub_disk_addr_t *off_out, char **n /* TRANSLATORS: geom is the name of (k)FreeBSD device framework. Usually left untranslated. */ - grub_util_error (_("couldn't open geom")); + grub_util_error ("%s", _("couldn't open geom")); LIST_FOREACH (class, &mesh.lg_class, lg_class) if (strcasecmp (class->lg_name, "part") == 0) @@ -447,7 +447,7 @@ grub_util_follow_gpart_up (const char *name, grub_disk_addr_t *off_out, char **n /* TRANSLATORS: geom is the name of (k)FreeBSD device framework. Usually left untranslated. "part" is the identifier of one of its classes. */ - grub_util_error (_("couldn't find geom `part' class")); + grub_util_error ("%s", _("couldn't find geom `part' class")); LIST_FOREACH (geom, &class->lg_geom, lg_geom) { diff --git a/util/getroot.c b/util/getroot.c index 0f47cba06..508a40d03 100644 --- a/util/getroot.c +++ b/util/getroot.c @@ -51,10 +51,8 @@ #include #endif -#ifdef __linux__ -# include -# include -#endif +#include +#include #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) # include @@ -1047,6 +1045,12 @@ grub_guess_root_devices (const char *dir) /* This might be truly slow, but is there any better way? */ os_dev[0] = grub_find_device ("/dev", dev); #endif + if (!os_dev[0]) + { + free (os_dev); + return 0; + } + os_dev[1] = 0; #endif /* !__GNU__ */ @@ -1179,7 +1183,7 @@ grub_util_get_geom_abstraction (const char *dev) struct gmesh mesh; struct gclass *class; const char *name; - int error; + int err; if (strncmp (dev, "/dev/", sizeof ("/dev/") - 1) != 0) return 0; @@ -1188,12 +1192,12 @@ grub_util_get_geom_abstraction (const char *dev) grub_util_info ("following geom '%s'", name); - error = geom_gettree (&mesh); - if (error != 0) + err = geom_gettree (&mesh); + if (err != 0) /* TRANSLATORS: geom is the name of (k)FreeBSD device framework. Usually left untranslated. */ - grub_util_error (_("couldn't open geom")); + grub_util_error ("%s", _("couldn't open geom")); LIST_FOREACH (class, &mesh.lg_class, lg_class) { @@ -1235,10 +1239,10 @@ grub_util_get_dev_abstraction (const char *os_dev) #endif #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) - const char *abs; - abs = grub_util_get_geom_abstraction (os_dev); - grub_util_info ("abstraction of %s is %s", os_dev, abs); - if (abs && grub_strcasecmp (abs, "eli") == 0) + const char *abstrac; + abstrac = grub_util_get_geom_abstraction (os_dev); + grub_util_info ("abstraction of %s is %s", os_dev, abstrac); + if (abstrac && grub_strcasecmp (abstrac, "eli") == 0) return GRUB_DEV_ABSTRACTION_GELI; /* Check for LVM. */ @@ -1406,7 +1410,7 @@ grub_util_pull_device (const char *os_dev) struct gmesh mesh; struct gclass *class; const char *name; - int error; + int err; char *lastsubdev = NULL; if (strncmp (os_dev, "/dev/", sizeof ("/dev/") - 1) != 0) @@ -1416,12 +1420,12 @@ grub_util_pull_device (const char *os_dev) grub_util_info ("following geom '%s'", name); - error = geom_gettree (&mesh); - if (error != 0) + err = geom_gettree (&mesh); + if (err != 0) /* TRANSLATORS: geom is the name of (k)FreeBSD device framework. Usually left untranslated. */ - grub_util_error (_("couldn't open geom")); + grub_util_error ("%s", _("couldn't open geom")); LIST_FOREACH (class, &mesh.lg_class, lg_class) { @@ -1434,12 +1438,12 @@ grub_util_pull_device (const char *os_dev) { struct gconsumer *consumer; char *fname; - char *uuid; LIST_FOREACH (consumer, &geom->lg_consumer, lg_consumer) break; if (!consumer) - grub_util_error (_("couldn't find geli consumer")); + grub_util_error ("%s", + _("couldn't find geli consumer")); fname = xasprintf ("/dev/%s", consumer->lg_provider->lg_name); grub_util_info ("consumer %s", consumer->lg_provider->lg_name); lastsubdev = consumer->lg_provider->lg_name; @@ -1456,9 +1460,9 @@ grub_util_pull_device (const char *os_dev) if (grdev) { - grub_err_t err; - err = grub_cryptodisk_cheat_mount (grdev, os_dev); - if (err) + grub_err_t gr_err; + gr_err = grub_cryptodisk_cheat_mount (grdev, os_dev); + if (gr_err) grub_util_error (_("can't mount encrypted volume `%s': %s"), lastsubdev, grub_errmsg); } @@ -2390,7 +2394,7 @@ grub_util_get_grub_dev (const char *os_dev) struct gmesh mesh; struct gclass *class; const char *name; - int error; + int err; if (strncmp (os_dev, "/dev/", sizeof ("/dev/") - 1) != 0) return 0; @@ -2399,12 +2403,12 @@ grub_util_get_grub_dev (const char *os_dev) grub_util_info ("following geom '%s'", name); - error = geom_gettree (&mesh); - if (error != 0) + err = geom_gettree (&mesh); + if (err != 0) /* TRANSLATORS: geom is the name of (k)FreeBSD device framework. Usually left untranslated. */ - grub_util_error (_("couldn't open geom")); + grub_util_error ("%s", _("couldn't open geom")); LIST_FOREACH (class, &mesh.lg_class, lg_class) { @@ -2422,11 +2426,13 @@ grub_util_get_grub_dev (const char *os_dev) LIST_FOREACH (consumer, &geom->lg_consumer, lg_consumer) break; if (!consumer) - grub_util_error (_("couldn't find geli consumer")); + grub_util_error ("%s", + _("couldn't find geli consumer")); fname = xasprintf ("/dev/%s", consumer->lg_provider->lg_name); uuid = grub_util_get_geli_uuid (fname); if (!uuid) - grub_util_error (_("couldn't retrieve geli UUID")); + grub_util_error ("%s", + _("couldn't retrieve geli UUID")); grub_dev = xasprintf ("cryptouuid/%s", uuid); free (fname); free (uuid); diff --git a/util/lvm.c b/util/lvm.c index 0bc271e46..5dac4f050 100644 --- a/util/lvm.c +++ b/util/lvm.c @@ -28,17 +28,17 @@ int grub_util_lvm_isvolume (char *name) { - char *devname; + char *lvmdevname; struct stat st; int err; - devname = xmalloc (strlen (name) + sizeof (LVM_DEV_MAPPER_STRING)); + lvmdevname = xmalloc (strlen (name) + sizeof (LVM_DEV_MAPPER_STRING)); - strcpy (devname, LVM_DEV_MAPPER_STRING); - strcpy (devname + sizeof(LVM_DEV_MAPPER_STRING) - 1, name); + strcpy (lvmdevname, LVM_DEV_MAPPER_STRING); + strcpy (lvmdevname + sizeof(LVM_DEV_MAPPER_STRING) - 1, name); - err = stat (devname, &st); - free (devname); + err = stat (lvmdevname, &st); + free (lvmdevname); if (err) return 0;