Blame SOURCES/libnfsidmap-0.25-whitspaces.patch

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