Blob Blame History Raw
From 67d1a3ea5d12b1a9f6ff222b55f42b3536a8a745 Mon Sep 17 00:00:00 2001
From: Marek 'marx' Grac <mgrac@redhat.com>
Date: Mon, 2 Mar 2015 10:58:06 +0100
Subject: [PATCH 08/10] fence_kdump: Fix possible problems according to
 Coverity

Previously, there was issue detected by Coverity. They do not matter too much
because we care only about return value and it will not be 0 if program crash.
But it is always better to have clean code, so fixing.

Resolves: rhbz#1196068
---
 fence/agents/kdump/fence_kdump.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/fence/agents/kdump/fence_kdump.c b/fence/agents/kdump/fence_kdump.c
index 29abbda..781df64 100644
--- a/fence/agents/kdump/fence_kdump.c
+++ b/fence/agents/kdump/fence_kdump.c
@@ -118,21 +118,22 @@ do_action_monitor (void)
 {
     const char cmdline_path[] = "/proc/cmdline";
     FILE *procFile;
-    size_t sz;
-    char *lines;
-    int result;
+    size_t sz = 0;
+    char *lines = NULL;
+    int result = 1;
 
     procFile = fopen(cmdline_path, "r");
-    sz = 0;
 
-    while (!feof (procFile)) {
-        getline (&lines, &sz, procFile);
+    if (procFile == NULL) {
+        log_error (0, "Unable to open file %s (%s)\n", cmdline_path, strerror (errno));
+        return 1;
     }
 
-    if (strstr(lines, "crashkernel=") == NULL) {
-        result = 1;
-    } else {
-        result = 0;
+    while (!feof (procFile)) {
+        ssize_t rv = getline (&lines, &sz, procFile);
+        if ((rv != -1) && (strstr(lines, "crashkernel=") != NULL)) {
+            result = 0;
+        }
     }
 
     free (lines);
-- 
1.9.3