forked from Mirrors/openclonk
Merge pull request #80 from isilkor/check-setlength-parameter-for-nil
Script: Test SetLength parameter 0 for nil (GH #79)master
commit
ad2eddcd63
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (c) 1998-2000, Matthes Bender
|
* Copyright (c) 1998-2000, Matthes Bender
|
||||||
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
|
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
|
||||||
* Copyright (c) 2009-2016, The OpenClonk Team and contributors
|
* Copyright (c) 2009-2019, The OpenClonk Team and contributors
|
||||||
*
|
*
|
||||||
* Distributed under the terms of the ISC license; see accompanying file
|
* Distributed under the terms of the ISC license; see accompanying file
|
||||||
* "COPYING" for details.
|
* "COPYING" for details.
|
||||||
|
@ -811,9 +811,21 @@ static bool FnDeepEqual(C4PropList * _this, const C4Value & v1, const C4Value &
|
||||||
|
|
||||||
static void FnSetLength(C4PropList * _this, C4ValueArray *pArray, int iNewSize)
|
static void FnSetLength(C4PropList * _this, C4ValueArray *pArray, int iNewSize)
|
||||||
{
|
{
|
||||||
// safety
|
if (!pArray)
|
||||||
if (iNewSize<0 || iNewSize > C4ValueArray::MaxSize)
|
{
|
||||||
throw C4AulExecError(FormatString("SetLength: invalid array size (%d)", iNewSize).getData());
|
throw C4AulExecError(strprintf(R"(call to "%s" parameter %d: passed %s, but expected %s)",
|
||||||
|
"SetLength", 1, GetC4VName(C4V_Nil), GetC4VName(C4V_Array))
|
||||||
|
.c_str()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iNewSize < 0 || iNewSize > C4ValueArray::MaxSize)
|
||||||
|
{
|
||||||
|
throw C4AulExecError(strprintf(R"(call to "SetLength": parameter 2: invalid array size (expected value between 0 and %d, but got %d)",
|
||||||
|
C4ValueArray::MaxSize, iNewSize)
|
||||||
|
.c_str()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// set new size
|
// set new size
|
||||||
pArray->SetSize(iNewSize);
|
pArray->SetSize(iNewSize);
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
class C4ValueArray: public C4RefCnt
|
class C4ValueArray: public C4RefCnt
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum { MaxSize = 1000000 }; // ye shalt not create arrays larger than that!
|
static const int MaxSize = 1000000; // ye shalt not create arrays larger than that!
|
||||||
|
|
||||||
C4ValueArray();
|
C4ValueArray();
|
||||||
C4ValueArray(int32_t inSize);
|
C4ValueArray(int32_t inSize);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* OpenClonk, http://www.openclonk.org
|
* OpenClonk, http://www.openclonk.org
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016, The OpenClonk Team and contributors
|
* Copyright (c) 2016-2019, The OpenClonk Team and contributors
|
||||||
*
|
*
|
||||||
* Distributed under the terms of the ISC license; see accompanying file
|
* Distributed under the terms of the ISC license; see accompanying file
|
||||||
* "COPYING" for details.
|
* "COPYING" for details.
|
||||||
|
@ -48,3 +48,16 @@ TEST_F(AulDeathTest, issue1891)
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(AulDeathTest, SetLengthWithNil)
|
||||||
|
{
|
||||||
|
// Github #79: NULL dereference when SetLength is called with nil parameter
|
||||||
|
EXPECT_NO_DEATH(
|
||||||
|
try
|
||||||
|
{
|
||||||
|
RunExpr("SetLength(nil, 0)");
|
||||||
|
}
|
||||||
|
catch (C4AulExecError &)
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue