summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-04-27 17:00:37 +0200
committerMattes D <github@xoft.cz>2014-04-27 17:00:37 +0200
commita0f6149d0551c532896db2b920333718f68888d8 (patch)
tree27826e519c342e395e535190201a47e4a65e74e0
parentMerge pull request #941 from archshift/master (diff)
parentFixed unitialized member in gZipFile (CID 43673) (diff)
downloadcuberite-a0f6149d0551c532896db2b920333718f68888d8.tar
cuberite-a0f6149d0551c532896db2b920333718f68888d8.tar.gz
cuberite-a0f6149d0551c532896db2b920333718f68888d8.tar.bz2
cuberite-a0f6149d0551c532896db2b920333718f68888d8.tar.lz
cuberite-a0f6149d0551c532896db2b920333718f68888d8.tar.xz
cuberite-a0f6149d0551c532896db2b920333718f68888d8.tar.zst
cuberite-a0f6149d0551c532896db2b920333718f68888d8.zip
Diffstat (limited to '')
-rw-r--r--src/Bindings/ManualBindings.cpp5
-rw-r--r--src/Noise.cpp2
-rw-r--r--src/OSSupport/GZipFile.cpp2
-rw-r--r--src/Protocol/Authenticator.cpp33
-rw-r--r--src/WorldStorage/WSSCompact.cpp10
5 files changed, 49 insertions, 3 deletions
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 92b410481..b3f75aff1 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -1750,7 +1750,6 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S)
{
return 0;
}
- cLuaChunkStay * ChunkStay = new cLuaChunkStay(*Plugin);
// Read the params:
cWorld * World = (cWorld *)tolua_tousertype(tolua_S, 1, NULL);
@@ -1760,8 +1759,12 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S)
L.LogStackTrace();
return 0;
}
+
+ cLuaChunkStay * ChunkStay = new cLuaChunkStay(*Plugin);
+
if (!ChunkStay->AddChunks(2))
{
+ delete ChunkStay;
return 0;
}
diff --git a/src/Noise.cpp b/src/Noise.cpp
index efbb128c3..95a022ea3 100644
--- a/src/Noise.cpp
+++ b/src/Noise.cpp
@@ -744,6 +744,8 @@ void cCubicNoise::CalcFloorFrac(
int * a_Same, int & a_NumSame
) const
{
+ ASSERT(a_Size > 0);
+
NOISE_DATATYPE val = a_Start;
NOISE_DATATYPE dif = (a_End - a_Start) / (a_Size - 1);
for (int i = 0; i < a_Size; i++)
diff --git a/src/OSSupport/GZipFile.cpp b/src/OSSupport/GZipFile.cpp
index 7a8433f4f..22d887783 100644
--- a/src/OSSupport/GZipFile.cpp
+++ b/src/OSSupport/GZipFile.cpp
@@ -11,7 +11,7 @@
cGZipFile::cGZipFile(void) :
- m_File(NULL)
+ m_File(NULL), m_Mode(fmRead)
{
}
diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp
index e0fcc0007..bbc656eda 100644
--- a/src/Protocol/Authenticator.cpp
+++ b/src/Protocol/Authenticator.cpp
@@ -165,6 +165,10 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
if ((ret = ctr_drbg_init(&ctr_drbg, entropy_func, &entropy, (const unsigned char *)pers, strlen(pers))) != 0)
{
LOGWARNING("cAuthenticator: ctr_drbg_init returned %d", ret);
+
+ // Free all resources which have been initialized up to this line
+ x509_crt_free(&cacert);
+ entropy_free(&entropy);
return false;
}
@@ -175,6 +179,10 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
if (ret < 0)
{
LOGWARNING("cAuthenticator: x509_crt_parse returned -0x%x", -ret);
+
+ // Free all resources which have been initialized up to this line
+ x509_crt_free(&cacert);
+ entropy_free(&entropy);
return false;
}
@@ -182,6 +190,10 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
if ((ret = net_connect(&server_fd, m_Server.c_str(), 443)) != 0)
{
LOGWARNING("cAuthenticator: Can't connect to %s: %d", m_Server.c_str(), ret);
+
+ // Free all resources which have been initialized up to this line
+ x509_crt_free(&cacert);
+ entropy_free(&entropy);
return false;
}
@@ -189,6 +201,13 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
if ((ret = ssl_init(&ssl)) != 0)
{
LOGWARNING("cAuthenticator: ssl_init returned %d", ret);
+
+ // Free all resources which have been initialized up to this line
+ x509_crt_free(&cacert);
+ net_close(server_fd);
+ ssl_free(&ssl);
+ entropy_free(&entropy);
+ memset(&ssl, 0, sizeof(ssl));
return false;
}
ssl_set_endpoint(&ssl, SSL_IS_CLIENT);
@@ -203,6 +222,13 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
if ((ret != POLARSSL_ERR_NET_WANT_READ) && (ret != POLARSSL_ERR_NET_WANT_WRITE))
{
LOGWARNING("cAuthenticator: ssl_handshake returned -0x%x", -ret);
+
+ // Free all resources which have been initialized up to this line
+ x509_crt_free(&cacert);
+ net_close(server_fd);
+ ssl_free(&ssl);
+ entropy_free(&entropy);
+ memset(&ssl, 0, sizeof(ssl));
return false;
}
}
@@ -223,6 +249,13 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
if (ret <= 0)
{
LOGWARNING("cAuthenticator: ssl_write returned %d", ret);
+
+ // Free all resources which have been initialized up to this line
+ x509_crt_free(&cacert);
+ net_close(server_fd);
+ ssl_free(&ssl);
+ entropy_free(&entropy);
+ memset(&ssl, 0, sizeof(ssl));
return false;
}
diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp
index c07c9e96f..359bac4a8 100644
--- a/src/WorldStorage/WSSCompact.cpp
+++ b/src/WorldStorage/WSSCompact.cpp
@@ -468,7 +468,15 @@ cWSSCompact::cPAKFile::cPAKFile(const AString & a_FileName, int a_LayerX, int a_
for (int i = 0; i < NumChunks; i++)
{
sChunkHeader * Header = new sChunkHeader;
- READ(*Header);
+
+ // Here we do not use the READ macro, as it does not free the resources
+ // allocated with new in case of error.
+ if (f.Read(Header, sizeof(*Header)) != sizeof(*Header))
+ {
+ LOGERROR("ERROR READING %s FROM FILE %s (line %d); file offset %d", "Header", m_FileName.c_str(), __LINE__, f.Tell());
+ delete Header;
+ return;
+ }
m_ChunkHeaders.push_back(Header);
} // for i - chunk headers