From b7fbac1214cfb38fd81f2d2555b34064456a1424 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 23 Nov 2010 17:42:06 +0000 Subject: [PATCH] * util/deviceiter.c (compare_devices): If the by-id link for a device couldn't be resolved, fall back to sorting by the by-id link rather than segfaulting. Reported and tested by: Daniel Mierswa. --- ChangeLog | 7 +++++++ util/deviceiter.c | 15 +++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9b01330d5..c6bbffd99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-11-23 Colin Watson + + * util/deviceiter.c (compare_devices): If the by-id link for a + device couldn't be resolved, fall back to sorting by the by-id link + rather than segfaulting. + Reported and tested by: Daniel Mierswa. + 2010-11-23 Colin Watson * Makefile.util.def (grub-menulst2cfg): List libraries in ldadd, not diff --git a/util/deviceiter.c b/util/deviceiter.c index 34d34b7bb..1de8e54df 100644 --- a/util/deviceiter.c +++ b/util/deviceiter.c @@ -485,12 +485,15 @@ compare_devices (const void *a, const void *b) { const struct device *left = (const struct device *) a; const struct device *right = (const struct device *) b; - int ret; - ret = strcmp (left->kernel, right->kernel); - if (ret) - return ret; - else - return strcmp (left->stable, right->stable); + + if (left->kernel && right->kernel) + { + int ret = strcmp (left->kernel, right->kernel); + if (ret) + return ret; + } + + return strcmp (left->stable, right->stable); } #endif /* __linux__ */