[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why does LoadString return NULL for zero-length strings?
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Tue, 2 Sep 2008 08:17:43 -0300
The attached patch fixes this glitch:
> assert(loadstring(('').dump(function()X''end):gsub('\2%z%z%zX','\0\0\0')))()
stdin:1: 1: bad string in precompiled chunk
Thanks for spotting it.
--lhf
--- lundump.c,orig 2008-04-04 16:51:41.000000000 -0300
+++ lundump.c 2008-09-02 08:10:19.000000000 -0300
@@ -73,12 +73,15 @@
return x;
}
-static TString* LoadString(LoadState* S)
+static TString* LoadString(LoadState* S, TString* p)
{
size_t size;
LoadVar(S,size);
if (size==0)
- return NULL;
+ {
+ IF (p==NULL, "bad string");
+ return p;
+ }
else
{
char* s=luaZ_openspace(S->L,S->b,size);
@@ -120,7 +123,7 @@
setnvalue(o,LoadNumber(S));
break;
case LUA_TSTRING:
- setsvalue2n(S->L,o,LoadString(S));
+ setsvalue2n(S->L,o,LoadString(S,NULL));
break;
default:
error(S,"bad constant");
@@ -147,7 +150,7 @@
for (i=0; i<n; i++) f->locvars[i].varname=NULL;
for (i=0; i<n; i++)
{
- f->locvars[i].varname=LoadString(S);
+ f->locvars[i].varname=LoadString(S,NULL);
f->locvars[i].startpc=LoadInt(S);
f->locvars[i].endpc=LoadInt(S);
}
@@ -155,7 +158,7 @@
f->upvalues=luaM_newvector(S->L,n,TString*);
f->sizeupvalues=n;
for (i=0; i<n; i++) f->upvalues[i]=NULL;
- for (i=0; i<n; i++) f->upvalues[i]=LoadString(S);
+ for (i=0; i<n; i++) f->upvalues[i]=LoadString(S,NULL);
}
static Proto* LoadFunction(LoadState* S, TString* p)
@@ -164,7 +167,7 @@
if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep");
f=luaF_newproto(S->L);
setptvalue2s(S->L,S->L->top,f); incr_top(S->L);
- f->source=LoadString(S); if (f->source==NULL) f->source=p;
+ f->source=LoadString(S,p);
f->linedefined=LoadInt(S);
f->lastlinedefined=LoadInt(S);
f->nups=LoadByte(S);