Blame SOURCES/libnfsidmap-0.25-whitspaces.patch

8287c7
diff -up libnfsidmap-0.25/cfg.c.orig libnfsidmap-0.25/cfg.c
8287c7
--- libnfsidmap-0.25/cfg.c.orig	2011-12-05 15:28:10.000000000 -0500
8287c7
+++ libnfsidmap-0.25/cfg.c	2017-11-17 12:01:56.756692437 -0500
8287c7
@@ -210,69 +210,98 @@ static void
8287c7
 conf_parse_line (int trans, char *line, size_t sz)
8287c7
 {
8287c7
   char *val;
8287c7
-  size_t i;
8287c7
-  int j;
8287c7
+  char *ptr;
8287c7
   static char *section = 0;
8287c7
   static int ln = 0;
8287c7
 
8287c7
   ln++;
8287c7
 
8287c7
+  /* Strip off any leading blanks */
8287c7
+  while (isblank(*line))
8287c7
+    line++;
8287c7
+
8287c7
+ 
8287c7
   /* Lines starting with '#' or ';' are comments.  */
8287c7
   if (*line == '#' || *line == ';')
8287c7
     return;
8287c7
 
8287c7
   /* '[section]' parsing...  */
8287c7
-  if (*line == '[')
8287c7
-    {
8287c7
-      for (i = 1; i < sz; i++)
8287c7
-	if (line[i] == ']')
8287c7
-	  break;
8287c7
-      if (section)
8287c7
-	free (section);
8287c7
-      if (i == sz)
8287c7
-	{
8287c7
-	  warnx("conf_parse_line: %d:"
8287c7
-		     "non-matched ']', ignoring until next section", ln);
8287c7
-	  section = 0;
8287c7
-	  return;
8287c7
+  if (*line == '[') {
8287c7
+    line++;
8287c7
+
8287c7
+    if (section) free(section);
8287c7
+
8287c7
+    while (isblank(*line)) line++;
8287c7
+
8287c7
+    /* find the closing ] */
8287c7
+    ptr = strchr(line, ']');
8287c7
+
8287c7
+	if (ptr == NULL) {
8287c7
+      warnx("conf_parse_line: %d:"
8287c7
+            "non-matched ']', ignoring until next section", ln);
8287c7
+      section = NULL;
8287c7
+      return;
8287c7
 	}
8287c7
-      section = malloc (i);
8287c7
-      if (!section)
8287c7
-	{
8287c7
-	  warnx("conf_parse_line: %d: malloc (%lu) failed", ln,
8287c7
-		(unsigned long)i);
8287c7
-	  return;
8287c7
+
8287c7
+    /* just ignore everything after the closing ] */
8287c7
+    *(ptr--) = '\0';
8287c7
+
8287c7
+    /* strip off any blanks before ']' */
8287c7
+    while (ptr >= line && isblank(*ptr))
8287c7
+      *(ptr--) = '\0';
8287c7
+
8287c7
+    section = strdup(line);
8287c7
+    if (!section) {
8287c7
+      warnx("conf_parse_line: %d: malloc failed", ln);
8287c7
+
8287c7
 	}
8287c7
-      strlcpy (section, line + 1, i);
8287c7
-      return;
8287c7
-    }
8287c7
+    return;
8287c7
+  }
8287c7
 
8287c7
   /* Deal with assignments.  */
8287c7
-  for (i = 0; i < sz; i++)
8287c7
-    if (line[i] == '=')
8287c7
-      {
8287c7
-	/* If no section, we are ignoring the lines.  */
8287c7
-	if (!section)
8287c7
-	  {
8287c7
+  ptr = strchr(line, '=');
8287c7
+
8287c7
+  /* not an assignment line */
8287c7
+  if (ptr == NULL) {
8287c7
+    /* and not just whitespace either, weird */
8287c7
+    if (line[strspn(line, " \t")])
8287c7
+      warnx("conf_parse_line: %d: syntax error", ln);
8287c7
+    return;
8287c7
+  }
8287c7
+
8287c7
+  /* If no section, we are ignoring the lines.  */
8287c7
+  if (!section) {
8287c7
 	    warnx("conf_parse_line: %d: ignoring line due to no section", ln);
8287c7
 	    return;
8287c7
-	  }
8287c7
-	line[strcspn (line, " \t=")] = '\0';
8287c7
-	val = line + i + 1 + strspn (line + i + 1, " \t");
8287c7
-	/* Skip trailing whitespace, if any */
8287c7
-	for (j = sz - (val - line) - 1; j > 0 && isspace (val[j]); j--)
8287c7
-	  val[j] = '\0';
8287c7
-	/* XXX Perhaps should we not ignore errors?  */
8287c7
-	conf_set (trans, section, line, val, 0, 0);
8287c7
-	return;
8287c7
-      }
8287c7
-
8287c7
-  /* Other non-empty lines are weird.  */
8287c7
-  i = strspn (line, " \t");
8287c7
-  if (line[i])
8287c7
-    warnx("conf_parse_line: %d: syntax error", ln);
8287c7
+   }
8287c7
 
8287c7
-  return;
8287c7
+  val = ptr + 1;
8287c7
+  *(ptr--) = '\0';
8287c7
+
8287c7
+  /* strip spaces before and after the = */
8287c7
+  while (ptr >= line && isblank(*ptr))
8287c7
+      *(ptr--) = '\0';
8287c7
+  while (*val != '\0' && isblank(*val))
8287c7
+      val++;
8287c7
+
8287c7
+  /* trim any trailing spaces or comments */
8287c7
+  if ((ptr=strchr(val, '#'))!=NULL) *ptr = '\0';
8287c7
+  if ((ptr=strchr(val, ';'))!=NULL) *ptr = '\0';
8287c7
+  ptr = val + strlen(val) - 1;
8287c7
+  while (ptr > val && isspace(*ptr))
8287c7
+      *(ptr--) = '\0';
8287c7
+
8287c7
+  if (*line == '\0') {
8287c7
+      warnx("conf_parse_line: %d: missing tag in assignment", ln);
8287c7
+      return;
8287c7
+  }
8287c7
+  if (*val == '\0') {
8287c7
+      warnx("conf_parse_line: %d: missing value in assignment", ln);
8287c7
+      return;
8287c7
+  }
8287c7
+ 
8287c7
+  /* XXX Perhaps should we not ignore errors?  */
8287c7
+  conf_set (trans, section, line, val, 0, 0);
8287c7
 }
8287c7
 
8287c7
 /* Parse the mapped configuration file.  */