File pacemaker-libcrmservice-parse-LSB-long-description.patch of Package pacemaker.14737

commit 92cc63953c6011a6810d37f3f00c01d00aa835df
Author: Ken Gaillot <kgaillot@redhat.com>
Date:   Tue Oct 10 14:48:47 2017 -0500

    Fix: libcrmservice: parse LSB long description correctly
    
    Previously, we would use only the long description continuation lines, ignoring
    the part of the long description on the description line itself. Also, in what
    appears to be a misguided attempt to push a read line back into the file stream,
    we would try writing to a read-only file pointer.

Index: pacemaker-1.1.16+20170320.77ea74d/lib/lrmd/lrmd_client.c
===================================================================
--- pacemaker-1.1.16+20170320.77ea74d.orig/lib/lrmd/lrmd_client.c
+++ pacemaker-1.1.16+20170320.77ea74d/lib/lrmd/lrmd_client.c
@@ -1629,7 +1629,7 @@ stonith_get_metadata(const char *provide
     "<resource-agent name='%s' version='0.1'>\n"                        \
     "  <version>1.0</version>\n"                                        \
     "  <longdesc lang='en'>\n"                                          \
-    "    %s\n"                                                          \
+    "%s"                                                                \
     "  </longdesc>\n"                                                   \
     "  <shortdesc lang='en'>%s</shortdesc>\n"                           \
     "  <parameters>\n"                                                  \
@@ -1701,8 +1701,8 @@ static int
 lsb_get_metadata(const char *type, char **output)
 {
     char ra_pathname[PATH_MAX] = { 0, };
-    FILE *fp;
-    char buffer[1024];
+    FILE *fp = NULL;
+    char buffer[1024] = { 0, };
     char *provides = NULL;
     char *req_start = NULL;
     char *req_stop = NULL;
@@ -1770,27 +1770,37 @@ lsb_get_metadata(const char *type, char
         /* Long description may cross multiple lines */
         if ((offset == 0) // haven't already found long description
             && !strncmp(buffer, DESCRIPTION, strlen(DESCRIPTION))) {
+            bool processed_line = TRUE;
 
-            /* Between # and keyword, more than one space, or a tab
-             * character, indicates the continuation line.
-             *
-             * Extracted from LSB init script standard
-             */
+            // Get remainder of description line itself
+            offset += snprintf(description, max, "%s",
+                               buffer + strlen(DESCRIPTION));
+
+            // Read any continuation lines of the description
+            buffer[0] = '\0';
             while (fgets(buffer, sizeof(buffer), fp)) {
                 if (!strncmp(buffer, "#  ", 3) || !strncmp(buffer, "#\t", 2)) {
-                    buffer[0] = ' ';
-                    offset += snprintf(description+offset, max-offset, "%s", buffer);
-
+                    /* '#' followed by a tab or more than one space indicates a
+                     * continuation of the long description.
+                     */
+                    offset += snprintf(description + offset, max - offset,
+                                       "%s", buffer + 1);
                 } else {
-                    fputs(buffer, fp);
-                    break;      /* Long description ends */
+                    /* This line is not part of the long description,
+                     * so continue with normal processing.
+                     */
+                    processed_line = FALSE;
+                    break;
                 }
             }
-            continue;
-        }
 
-        if (xml_l_dscrpt == NULL && offset > 0) {
+            // Make long description safe to use in XML
             xml_l_dscrpt = (char *)xmlEncodeEntitiesReentrant(NULL, BAD_CAST(description));
+
+            if (processed_line) {
+                // We grabbed the line into the long description
+                continue;
+            }
         }
 
         // Stop if we leave the header block
openSUSE Build Service is sponsored by