aboutsummaryrefslogtreecommitdiffstats
path: root/main/lua-ossl/0006-optencoding-allow-negative-indices.patch
blob: 836ddd21cc735bfccc567c1d06e2075238210f06 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
From 49ea990493039729e5a856f8bb3c758a0aa98a78 Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Sun, 2 Sep 2018 14:40:07 +0300
Subject: [PATCH 06/10] optencoding: allow negative indices

---
 src/openssl.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/openssl.c b/src/openssl.c
index 5904bf1..cb38f2f 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -846,8 +846,12 @@ static int optencoding(lua_State *L, int index, const char *def, int allow) {
 		break;
 	}
 
-	if (!(type & allow))
-		luaL_argerror(L, index, lua_pushfstring(L, "invalid option %s", luaL_checkstring(L, index)));
+	if (!(type & allow)) {
+		const char *arg = luaL_checkstring(L, index);
+		if (index > 0)
+			luaL_argerror(L, index, lua_pushfstring(L, "invalid format: %s", arg));
+		luaL_error(L, "invalid format: %s", arg);
+	}
 
 	return type;
 } /* optencoding() */
@@ -1186,11 +1190,15 @@ static int auxL_testoption(lua_State *L, int index, const char *def, const char
 
 static int auxL_checkoption(lua_State *L, int index, const char *def, const char *const *optlist, _Bool nocase) {
 	int i;
+	const char *arg;
 
 	if ((i = auxL_testoption(L, index, def, optlist, nocase)) >= 0)
 		return i;
 
-	return luaL_argerror(L, index, lua_pushfstring(L, "invalid option '%s'", luaL_optstring(L, index, def)));
+	arg = luaL_optstring(L, index, def);
+	if (index > 0)
+		return luaL_argerror(L, index, lua_pushfstring(L, "invalid option '%s'", arg));
+	return luaL_error(L, "invalid option '%s'", arg);
 } /* auxL_checkoption() */
 
 /*
-- 
2.24.1