Subject: watchdog: shutdown procedure could segfault
Package: watchdog
Version: 5.4
Severity: important
Tags: patch

*** Please type your report below this line ***

I've discovered that watchdog package may crash during shutdown
procedure in mnt_off() function due to the missing MNTTAB file.

This may be due to the exotic platform (and handmade gentoo derivate
distro) I'm trying to use watchdog on but I still think it is not
neccessary to crash so hard here.

MNTTAB is defined as /etc/fstab and this file is not present on the
system. Thus NULL is returned from setmntent and is later used without
validation.

I'm attaching simple patch that performs validation and thus
eliminates segfault.

I think that the problem is not debian related as it occured on a
different distro
but looking at the AUTHORS I found out that author of the package is also the
debian maintainer so I'm submitting this way.

Wish you good day,
ja.ro
--- src/shutdown.c	2009-02-06 01:10:34.000000000 +0100
+++ src/shutdown.c	2009-02-06 01:14:44.000000000 +0100
@@ -172,7 +172,8 @@
     struct mntent *mnt;
 
     fp = setmntent(MNTTAB, "r");
-    while ((mnt = getmntent(fp)) != (struct mntent *) 0) {
+    /* in some rare cases fp might be NULL so be careful */
+    while (fp != NULL && ((mnt = getmntent(fp)) != (struct mntent *) 0)) {
 	/* First check if swap */
 	if (!strcmp(mnt->mnt_type, MNTTYPE_SWAP))
 	    if (swapoff(mnt->mnt_fsname) < 0)

Reply via email to