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

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