From 2cdb64897d4fe33a11af13c6356dcd338c561e77 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Mon, 28 Apr 2008 16:29:12 +1000 Subject: Fix for segfault when reading /proc/mdstat Some kernel versions don't put a space between 'active' and '(auto-read-only)' in /proc/mdstat. This causes a parsing problem leaving 'level' set to NULL which causes a crash. So synthesise a space there if it is missing, and check for 'level' to be NULL and don't de-ref if it is. --- config.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'config.c') diff --git a/config.c b/config.c index 29eadc5..121b337 100644 --- a/config.c +++ b/config.c @@ -161,11 +161,24 @@ char *conf_word(FILE *file, int allow_key) word[len++] = c; } c = getc(file); + /* Hack for broken kernels (2.6.14-.24) that put + * "active(auto-read-only)" + * in /proc/mdstat instead of + * "active (auto-read-only)" + */ + if (c == '(' && len >= 6 + && strncmp(word+len-6, "active", 6) == 0) + c = ' '; } } if (c != EOF) ungetc(c, file); } word[len] = 0; + + /* Further HACK for broken kernels.. 2.6.14-2.6.24 */ + if (strcmp(word, "auto-read-only)") == 0) + strcpy(word, "(auto-read-only)"); + /* printf("word is <%s>\n", word); */ if (!wordfound) { free(word); -- cgit