From ce4a999d4d84d02cce50d74e498a4faca73ce2c2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 24 Dec 2011 02:45:17 +0100 Subject: [PATCH] * grub-core/kern/ieee1275/openfw.c (grub_devalias_iterate): Fix allocation and zero-setting. (grub_ieee1275_get_devname): Check that alias is complete. --- ChangeLog | 6 ++++++ grub-core/kern/ieee1275/openfw.c | 12 ++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 18f6778c5..f62a3a11b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-12-24 Vladimir Serbinenko + + * grub-core/kern/ieee1275/openfw.c (grub_devalias_iterate): Fix + allocation and zero-setting. + (grub_ieee1275_get_devname): Check that alias is complete. + 2011-12-24 Vladimir Serbinenko * grub-core/kern/disk.c (grub_disk_read): Fix hook calling for diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c index a063cfe63..2c081e57d 100644 --- a/grub-core/kern/ieee1275/openfw.c +++ b/grub-core/kern/ieee1275/openfw.c @@ -164,7 +164,7 @@ grub_devalias_iterate (int (*hook) (struct grub_ieee1275_devalias *alias)) strings, so we will add a NULL byte at the end explicitly. */ pathlen += 1; - devpath = grub_malloc (pathlen); + devpath = grub_malloc (pathlen + 1); if (! devpath) { grub_free (devtype); @@ -173,12 +173,15 @@ grub_devalias_iterate (int (*hook) (struct grub_ieee1275_devalias *alias)) } if (grub_ieee1275_get_property (aliases, aliasname, devpath, pathlen, - &actual)) + &actual) || actual < 0) { grub_dprintf ("devalias", "get_property (%s) failed\n", aliasname); goto nextprop; } - devpath [actual] = '\0'; + if (actual > pathlen) + actual = pathlen; + devpath[actual] = '\0'; + devpath[pathlen] = '\0'; if (grub_ieee1275_finddevice (devpath, &dev)) { @@ -294,7 +297,8 @@ grub_ieee1275_get_devname (const char *path) int match_alias (struct grub_ieee1275_devalias *curalias) { /* briQ firmware can change capitalization in /chosen/bootpath. */ - if (! grub_strncasecmp (curalias->path, path, pathlen)) + if (grub_strncasecmp (curalias->path, path, pathlen) == 0 + && curalias->path[pathlen] == 0) { newpath = grub_strdup (curalias->name); return 1;