aboutsummaryrefslogtreecommitdiff
path: root/src/host/minilua.c
diff options
context:
space:
mode:
authorMike Pall <mike>2026-01-09 17:34:15 +0100
committerMike Pall <mike>2026-01-09 17:34:15 +0100
commit221ea00775b2694dc088331a05ebb3c4273b182f (patch)
treed2ebf9e18e7d7ddd65afddc7300896b93d8adcaf /src/host/minilua.c
parent282e1a969daa343ed8c21904f275ee63becbf683 (diff)
downloadluajit-v2.0.tar.gz
luajit-v2.0.tar.bz2
luajit-v2.0.zip
Fix minilua undefined behavior in bit.tohex.v2.0master
Note: this is not a vulnerability! minilua is only used during the LuaJIT build process. It only runs controlled and static Lua code (DynASM), which is entirely contained within this repo and does not trigger the undefined behavior. This change is solely for the benefit of others, who might possibly use minilua for purposes other than running DynASM. Reported by quart27219. #1424
Diffstat (limited to 'src/host/minilua.c')
-rw-r--r--src/host/minilua.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/host/minilua.c b/src/host/minilua.c
index 76f32aed..2d59de41 100644
--- a/src/host/minilua.c
+++ b/src/host/minilua.c
@@ -7722,11 +7722,11 @@ static int bswap(lua_State*L){
7722UB b=barg(L,1);b=(b>>24)|((b>>8)&0xff00)|((b&0xff00)<<8)|(b<<24);BRET(b)} 7722UB b=barg(L,1);b=(b>>24)|((b>>8)&0xff00)|((b&0xff00)<<8)|(b<<24);BRET(b)}
7723static int tohex(lua_State*L){ 7723static int tohex(lua_State*L){
7724UB b=barg(L,1); 7724UB b=barg(L,1);
7725int n=lua_isnone(L,2)?8:(int)barg(L,2); 7725UB n=lua_isnone(L,2)?8:barg(L,2);
7726const char*hexdigits="0123456789abcdef"; 7726const char*hexdigits="0123456789abcdef";
7727char buf[8]; 7727char buf[8];
7728int i; 7728int i;
7729if(n<0){n=-n;hexdigits="0123456789ABCDEF";} 7729if((int)n<0){n=~n+1;hexdigits="0123456789ABCDEF";}
7730if(n>8)n=8; 7730if(n>8)n=8;
7731for(i=(int)n;--i>=0;){buf[i]=hexdigits[b&15];b>>=4;} 7731for(i=(int)n;--i>=0;){buf[i]=hexdigits[b&15];b>>=4;}
7732lua_pushlstring(L,buf,(size_t)n); 7732lua_pushlstring(L,buf,(size_t)n);