Blame SOURCES/nuxwdog-Allow-unlimited-conf-line-length.patch

12ebd5
From f4b47d21560fd57c7d2e326ebfae66f42b66864f Mon Sep 17 00:00:00 2001
12ebd5
From: Ade Lee <alee@redhat.com>
12ebd5
Date: Mon, 30 Oct 2017 22:47:15 -0400
12ebd5
Subject: [PATCH] Allow unlimited conf line length
12ebd5
12ebd5
Errors occurred because the line length was being truncated,
12ebd5
especially for long lines like JVM args.  Now the line length
12ebd5
will be allocated correctly.
12ebd5
12ebd5
Change-Id: I77553817931883e05180a1082d45a20e3a6afe4c
12ebd5
---
12ebd5
 src/com/redhat/nuxwdog/wdconf.cpp | 45 ++++++++++++++++++++++-----------------
12ebd5
 1 file changed, 26 insertions(+), 19 deletions(-)
12ebd5
12ebd5
diff --git a/src/com/redhat/nuxwdog/wdconf.cpp b/src/com/redhat/nuxwdog/wdconf.cpp
12ebd5
index 086bc5ae36c79ff3570ba0e39da10a42d8ab9687..95603c96dbd021289b60a001ee6fba0b15f9f540 100644
12ebd5
--- a/src/com/redhat/nuxwdog/wdconf.cpp
12ebd5
+++ b/src/com/redhat/nuxwdog/wdconf.cpp
12ebd5
@@ -29,24 +29,23 @@
12ebd5
 #include "wdconf.h"
12ebd5
 #include "wdlog.h"
12ebd5
 
12ebd5
-#define MAX_CONF_LINE_LENGTH 1024
12ebd5
+#define CHUNK 1024
12ebd5
 
12ebd5
 /* Read config file line like util_getline() */
12ebd5
-static int _watchdog_readconf_line(char *line, int maxlen, FILE *file)
12ebd5
+static char * _watchdog_readconf_line(FILE *file)
12ebd5
 {
12ebd5
     int len = 0;
12ebd5
     int nlseen = 0;
12ebd5
-    int src;
12ebd5
-    int dst;
12ebd5
-    char *bufp = line;
12ebd5
+    int src = 0;
12ebd5
+    int dst = 0;
12ebd5
+    char bufp[CHUNK];
12ebd5
 
12ebd5
-    if (feof(file)) {
12ebd5
-        return -1;
12ebd5
-    }
12ebd5
+    char *line = (char *) malloc(1);
12ebd5
+    line[0] = '\0';
12ebd5
 
12ebd5
-    while (!nlseen && (len < maxlen - 1)) {
12ebd5
+    while (!nlseen && !feof(file)) {
12ebd5
 
12ebd5
-        if (!fgets(bufp, maxlen - len, file))
12ebd5
+        if (!fgets(bufp, CHUNK, file))
12ebd5
             break;
12ebd5
 
12ebd5
         /* Scan what was just read */
12ebd5
@@ -68,26 +67,31 @@ static int _watchdog_readconf_line(char *line, int maxlen, FILE *file)
12ebd5
                 ++dst;
12ebd5
             }
12ebd5
         }
12ebd5
+        bufp[dst] = '\0';
12ebd5
 
12ebd5
         if (dst > 0) {
12ebd5
             /* Check for continuation */
12ebd5
             if (nlseen && (bufp[dst-1] == '\\')) {
12ebd5
+                bufp[dst-1] = '\0';
12ebd5
                 dst -= 1;
12ebd5
                 nlseen = 0;
12ebd5
             }
12ebd5
 
12ebd5
             len += dst;
12ebd5
-            bufp += dst;
12ebd5
+
12ebd5
+            line = (char *) realloc(line, len+1);
12ebd5
+            strcat(line, bufp);
12ebd5
         }
12ebd5
     }
12ebd5
                 
12ebd5
     if ((len <= 0) && !nlseen) {
12ebd5
-        return -1;
12ebd5
+        if (line) {
12ebd5
+            free(line);
12ebd5
+        }
12ebd5
+        return NULL;
12ebd5
     }
12ebd5
 
12ebd5
-    line[len] = '\0';
12ebd5
-
12ebd5
-    return len;
12ebd5
+    return line;
12ebd5
 }
12ebd5
 
12ebd5
 static int
12ebd5
@@ -95,8 +99,7 @@ _watchdog_parse_conffile(char *conffile,
12ebd5
                          watchdog_conf_info_t *info)
12ebd5
 {
12ebd5
     FILE *cfile;
12ebd5
-    char line[MAX_CONF_LINE_LENGTH];
12ebd5
-    char *name, *value;
12ebd5
+    char *line, *name, *value;
12ebd5
     int len;
12ebd5
 
12ebd5
     cfile = fopen(conffile, "r");
12ebd5
@@ -110,7 +113,8 @@ _watchdog_parse_conffile(char *conffile,
12ebd5
         return -1;
12ebd5
     }
12ebd5
 
12ebd5
-    while ((len = _watchdog_readconf_line(line, MAX_CONF_LINE_LENGTH, cfile)) >= 0) {
12ebd5
+    while ((line = _watchdog_readconf_line(cfile)) != NULL) {
12ebd5
+        len = strlen(line);
12ebd5
         name = line;
12ebd5
         if ((*name) == '#')
12ebd5
             continue;
12ebd5
@@ -154,10 +158,13 @@ _watchdog_parse_conffile(char *conffile,
12ebd5
         if (!strcasecmp(name, "ChildSecurity")) {
12ebd5
             info->childSecurity = atoi(value);
12ebd5
         }
12ebd5
+        if (line != NULL) {
12ebd5
+            free(line);
12ebd5
+            line = NULL;
12ebd5
+        }
12ebd5
     }
12ebd5
 
12ebd5
     fclose(cfile);
12ebd5
-
12ebd5
     return 0;
12ebd5
 }
12ebd5
 
12ebd5
-- 
12ebd5
2.9.5
12ebd5