aboutsummaryrefslogtreecommitdiffstats
path: root/main/lua-ldap/fix-open_simple-segfault.patch
blob: 7a7ffdeb6d12a53d582d6348aa3b01764aed89bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Fri, 10 Mar 2017 00:28:52 +0100
Subject: [PATCH] Fix segfault in lualdap_open_simple()

Upstream-Issue: https://github.com/bdellegrazie/lualdap/pull/1
--- a/src/lualdap.c
+++ b/src/lualdap.c
@@ -1011,7 +1011,7 @@
 	int use_tls = lua_toboolean (L, 4);
 	conn_data *conn = (conn_data *)lua_newuserdata (L, sizeof(conn_data));
 #if defined(LDAP_API_FEATURE_X_OPENLDAP) && LDAP_API_FEATURE_X_OPENLDAP >= 20300
-	struct berval cred = { 0, NULL };
+	struct berval *cred = NULL;
 	char *host_with_schema = NULL;
 #endif
 	int err;
@@ -1045,12 +1045,9 @@
 	}
 	/* Bind to a server */
 #if defined(LDAP_API_FEATURE_X_OPENLDAP) && LDAP_API_FEATURE_X_OPENLDAP >= 20300
-	cred.bv_len = strlen(password);
-	cred.bv_val = malloc(cred.bv_len+1);
-	strcpy(cred.bv_val, password);
-	err = ldap_sasl_bind_s (conn->ld, who, LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL);
-	free(cred.bv_val);
-	memset(&cred, 0, sizeof(cred));
+	cred = ber_bvstrdup(password);
+	err = ldap_sasl_bind_s (conn->ld, who, LDAP_SASL_SIMPLE, cred, NULL, NULL, NULL);
+	ber_bvfree(cred);
 #else
 	err = ldap_bind_s (conn->ld, who, password, LDAP_AUTH_SIMPLE);
 #endif