aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-08-09 10:30:33 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-08-09 10:30:33 -0300
commit9e6aa878c96485ba0658303c0da16adef56ba54c (patch)
tree9b47d859f5c08375932782135068ccf552ac039f
parentc0fdaf58420a4c224f7d0167465b40b7bf91e934 (diff)
downloadlua-9e6aa878c96485ba0658303c0da16adef56ba54c.tar.gz
lua-9e6aa878c96485ba0658303c0da16adef56ba54c.tar.bz2
lua-9e6aa878c96485ba0658303c0da16adef56ba54c.zip
string.byte truncates indices out of range
-rw-r--r--lstrlib.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/lstrlib.c b/lstrlib.c
index 06263e67..c637a724 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.104 2004/07/09 18:24:41 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.105 2004/08/06 17:35:38 roberto Exp roberto $
3** Standard library for string operations and pattern-matching 3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -110,8 +110,9 @@ static int str_byte (lua_State *L) {
110 sint32 posi = posrelat(luaL_optinteger(L, 2, 1), l); 110 sint32 posi = posrelat(luaL_optinteger(L, 2, 1), l);
111 sint32 pose = posrelat(luaL_optinteger(L, 3, posi), l); 111 sint32 pose = posrelat(luaL_optinteger(L, 3, posi), l);
112 int n, i; 112 int n, i;
113 if (!(0 < posi && posi <= pose && (size_t)pose <= l)) 113 if (posi <= 0) posi = 1;
114 return 0; /* index out of range; no answer */ 114 if ((size_t)pose > l) pose = l;
115 if (posi > pose) return 0; /* empty interval; return no values */
115 n = pose - posi + 1; 116 n = pose - posi + 1;
116 luaL_checkstack(L, n, "string slice too long"); 117 luaL_checkstack(L, n, "string slice too long");
117 for (i=0; i<n; i++) 118 for (i=0; i<n; i++)