aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden
diff options
context:
space:
mode:
Diffstat (limited to 'linden')
-rw-r--r--linden/indra/llmessage/lldatapacker.cpp30
1 files changed, 17 insertions, 13 deletions
diff --git a/linden/indra/llmessage/lldatapacker.cpp b/linden/indra/llmessage/lldatapacker.cpp
index e4243a5..dc7efae 100644
--- a/linden/indra/llmessage/lldatapacker.cpp
+++ b/linden/indra/llmessage/lldatapacker.cpp
@@ -188,27 +188,31 @@ BOOL LLDataPackerBinaryBuffer::packString(const std::string& value, const char *
188 188
189BOOL LLDataPackerBinaryBuffer::unpackString(std::string& value, const char *name) 189BOOL LLDataPackerBinaryBuffer::unpackString(std::string& value, const char *name)
190{ 190{
191 //Sanitise the string before attemping ANY buffer operations 191 // Verify that the buffer members are meaningful
192 U8 * pos; 192 llassert(mBufferp != NULL);
193 S32 length=0; 193 llassert(mBufferSize > 0);
194 for(pos=mCurBufferp;pos<(mBufferp+mBufferSize);pos++) 194 llassert(mCurBufferp >= mBufferp);
195 llassert(mCurBufferp < (mBufferp + mBufferSize));
196
197 // Compute the length of the mCurBufferp string *without* assuming NULL termination of that string (avoids attempt to read beyond mBufferp boundary)
198 U8 *pos;
199 for (pos = mCurBufferp; pos < (mBufferp+mBufferSize); pos++)
195 { 200 {
196 length++; 201 if ((*pos) == 0)
197 if((*pos)==0)
198 break; 202 break;
199 } 203 }
204 S32 length = pos - mCurBufferp + 1; // mCurBufferp length
205 S32 max_length = mBufferSize - (mCurBufferp - mBufferp); // Possible max length of mCurBufferp in mBufferp
200 206
201 if(length>=mBufferSize) 207 if (length > max_length)
202 { 208 {
203 llwarns << "Unpack string failed, null termination not found"<<llendl; 209 llwarns << "Buffer overflow in BinaryBuffer unpackString, field name " << name << "!" << llendl;
210 llwarns << "Null termination not found" << llendl;
211 llwarns << "Current pos in buffer: " << (int)(mCurBufferp - mBufferp) << " Buffer size: " << mBufferSize << llendl;
204 return false; 212 return false;
205 } 213 }
206 214
207 if(!verifyLength(length, name)) 215 value = std::string((char*)mCurBufferp);
208 return false;
209
210 value = std::string((char*)mCurBufferp); // We already assume NULL termination calling strlen()
211
212 mCurBufferp += length; 216 mCurBufferp += length;
213 return true; 217 return true;
214} 218}