Blob Blame History Raw
From ca59eb345cfef368242929ea33beca4bff837e9d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dan=20Vr=C3=A1til?= <dvratil@redhat.com>
Date: Thu, 18 Sep 2014 16:54:26 +0200
Subject: [PATCH 06/30] Don't crash when setmntent returns NULL

setmntent can fail when there's no /etc/mtab file for instance and
passing NULL pointer to getmntent crashes, so we need to return when
this happens.
---
 server/src/utils.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/server/src/utils.cpp b/server/src/utils.cpp
index b04a812..b51c330 100644
--- a/server/src/utils.cpp
+++ b/server/src/utils.cpp
@@ -179,6 +179,9 @@ QString Utils::getDirectoryFileSystem(const QString &directory)
     QString bestMatchFS;
 
     FILE *mtab = setmntent("/etc/mtab", "r");
+    if (!mtab) {
+        return QString();
+    }
     while (mntent *mnt = getmntent(mtab)) {
         if (qstrcmp(mnt->mnt_type, MNTTYPE_IGNORE) == 0) {
             continue;
-- 
2.1.0