9047d52
diff -up sudo-1.8.14b3/plugins/sudoers/ldap.c.ldapconfpatch sudo-1.8.14b3/plugins/sudoers/ldap.c
9047d52
--- sudo-1.8.14b3/plugins/sudoers/ldap.c.ldapconfpatch	2015-07-07 18:51:11.000000000 +0200
9047d52
+++ sudo-1.8.14b3/plugins/sudoers/ldap.c	2015-07-09 11:03:25.686645581 +0200
9047d52
@@ -1922,6 +1922,33 @@ sudo_check_krb5_ccname(const char *ccnam
a5f9360
 }
a5f9360
 #endif /* HAVE_LDAP_SASL_INTERACTIVE_BIND_S */
a5f9360
 
a5f9360
+/*
a5f9360
+ * Read a line of input, remove whole line comments and strip off leading
a5f9360
+ * and trailing spaces.  Returns static storage that is reused.
a5f9360
+ */
a5f9360
+static char *
a5f9360
+sudo_ldap_parseln(fp)
a5f9360
+    FILE *fp;
a5f9360
+{
a5f9360
+    size_t len;
a5f9360
+    char *cp = NULL;
a5f9360
+    static char buf[LINE_MAX];
a5f9360
+
a5f9360
+    if (fgets(buf, sizeof(buf), fp) != NULL) {
a5f9360
+	/* Remove comments */
a5f9360
+	if (*buf == '#')
a5f9360
+	    *buf = '\0';
a5f9360
+
a5f9360
+	/* Trim leading and trailing whitespace/newline */
a5f9360
+	len = strlen(buf);
a5f9360
+	while (len > 0 && isspace((unsigned char)buf[len - 1]))
a5f9360
+	    buf[--len] = '\0';
a5f9360
+	for (cp = buf; isblank(*cp); cp++)
a5f9360
+	    continue;
a5f9360
+    }
a5f9360
+    return(cp);
a5f9360
+}
a5f9360
+
a5f9360
 static bool
a5f9360
 sudo_ldap_read_config(void)
a5f9360
 {
9047d52
@@ -1955,7 +1982,7 @@ sudo_ldap_read_config(void)
a5f9360
     if ((fp = fopen(path_ldap_conf, "r")) == NULL)
a5f9360
 	debug_return_bool(false);
a5f9360
 
a5f9360
-    while (sudo_parseln(&line, &linesize, NULL, fp) != -1) {
a5f9360
+    while ((line = sudo_ldap_parseln(fp)) != NULL) {
a5f9360
 	if (*line == '\0')
a5f9360
 	    continue;		/* skip empty line */
a5f9360
 
9047d52
@@ -1975,7 +2002,7 @@ sudo_ldap_read_config(void)
a5f9360
 	if (!sudo_ldap_parse_keyword(keyword, value, ldap_conf_global))
a5f9360
 	    sudo_ldap_parse_keyword(keyword, value, ldap_conf_conn);
a5f9360
     }
a5f9360
-    free(line);
9047d52
+
a5f9360
     fclose(fp);
a5f9360
 
9047d52
     if (!ldap_conf.host) {