diff options
author | Karen Clark <karen@lindenlab.com> | 2007-03-20 22:21:42 +0000 |
---|---|---|
committer | Karen Clark <karen@lindenlab.com> | 2007-03-20 22:21:42 +0000 |
commit | fceae96eb171be0396512e251aab311d4e3ef9cc (patch) | |
tree | e648d1dd42aeae4d47168bd8d696ff0895819b8b /indra/llmessage | |
parent | 5e9e67cb2d1d3dfc82dfe96103270b2341991ddd (diff) |
svn merge -r59459:59476 svn+ssh://svn.lindenlab.com/svn/linden/branches/adroit.r69-75_2 into svn+ssh://svn.lindenlab.com/svn/linden/release.
Diffstat (limited to 'indra/llmessage')
-rw-r--r-- | indra/llmessage/llassetstorage.cpp | 2 | ||||
-rw-r--r-- | indra/llmessage/lldatapacker.cpp | 220 | ||||
-rw-r--r-- | indra/llmessage/llhost.cpp | 4 | ||||
-rw-r--r-- | indra/llmessage/llhttpassetstorage.cpp | 6 | ||||
-rw-r--r-- | indra/llmessage/llinstantmessage.cpp | 17 | ||||
-rw-r--r-- | indra/llmessage/llxfer_file.cpp | 2 | ||||
-rw-r--r-- | indra/llmessage/message.cpp | 58 |
7 files changed, 183 insertions, 126 deletions
diff --git a/indra/llmessage/llassetstorage.cpp b/indra/llmessage/llassetstorage.cpp index d1bb575c36..873e8fa9db 100644 --- a/indra/llmessage/llassetstorage.cpp +++ b/indra/llmessage/llassetstorage.cpp @@ -1253,7 +1253,7 @@ void LLAssetStorage::legacyGetDataCallback(LLVFS *vfs, const LLUUID &uuid, LLAss char uuid_str[UUID_STR_LENGTH]; /* Flawfinder: ignore */ uuid.toString(uuid_str); - snprintf(filename,sizeof(filename),"%s.%s",gDirUtilp->getExpandedFilename(LL_PATH_CACHE,uuid_str).c_str(),LLAssetType::lookup(type)); /* Flawfinder: ignore */ + snprintf(filename,sizeof(filename),"%s.%s",gDirUtilp->getExpandedFilename(LL_PATH_CACHE,uuid_str).c_str(),LLAssetType::lookup(type)); /* Flawfinder: ignore */ FILE* fp = LLFile::fopen(filename, "wb"); /* Flawfinder: ignore */ if (fp) diff --git a/indra/llmessage/lldatapacker.cpp b/indra/llmessage/lldatapacker.cpp index 10929dfbb2..9670c641c2 100644 --- a/indra/llmessage/lldatapacker.cpp +++ b/indra/llmessage/lldatapacker.cpp @@ -538,7 +538,7 @@ void LLDataPackerBinaryBuffer::dumpBufferToLog() S32 cur_line = 0; for (i = 0; i < mBufferSize; i++) { - snprintf(line_buffer + cur_line_pos*3, sizeof(line_buffer) - cur_line_pos*3, "%02x ", mBufferp[i]); /*Flawfinder: ignore*/ + snprintf(line_buffer + cur_line_pos*3, sizeof(line_buffer) - cur_line_pos*3, "%02x ", mBufferp[i]); /* Flawfinder: ignore */ cur_line_pos++; if (cur_line_pos >= 16) { @@ -563,7 +563,7 @@ BOOL LLDataPackerAsciiBuffer::packString(const char *value, const char *name) int numCopied = 0; if (mWriteEnabled) { - numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\n", value); /*Flawfinder: ignore*/ + numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\n", value); /* Flawfinder: ignore */ } else { @@ -572,14 +572,15 @@ BOOL LLDataPackerAsciiBuffer::packString(const char *value, const char *name) // snprintf returns number of bytes that would have been written // had the output not being truncated. In that case, it will - // return >= passed in size value. so a check needs to be added + // return either -1 or value >= passed in size value . So a check needs to be added // to detect truncation, and if there is any, only account for the // actual number of bytes written..and not what could have been // written. - if (numCopied > getBufferSize()-getCurrentSize()) + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { // *NOTE: I believe we need to mark a failure bit at this point. numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::packString: string truncated: " << value << llendl; } mCurBufferp += numCopied; return success; @@ -607,7 +608,7 @@ BOOL LLDataPackerAsciiBuffer::packBinaryData(const U8 *value, S32 size, const ch int numCopied = 0; if (mWriteEnabled) { - numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%010d ", size); /*Flawfinder: ignore*/ + numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%010d ", size); /* Flawfinder: ignore */ // snprintf returns number of bytes that would have been // written had the output not being truncated. In that case, @@ -615,9 +616,10 @@ BOOL LLDataPackerAsciiBuffer::packBinaryData(const U8 *value, S32 size, const ch // to be added to detect truncation, and if there is any, only // account for the actual number of bytes written..and not // what could have been written. - if (numCopied > getBufferSize()-getCurrentSize()) + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::packBinaryData: number truncated: " << size << llendl; } mCurBufferp += numCopied; @@ -626,10 +628,11 @@ BOOL LLDataPackerAsciiBuffer::packBinaryData(const U8 *value, S32 size, const ch BOOL bBufferFull = FALSE; for (i = 0; i < size && !bBufferFull; i++) { - numCopied = snprintf(mCurBufferp, getBufferSize()-getCurrentSize(), "%02x ", value[i]); /* Flawfinder: ignore */ - if (numCopied > getBufferSize()-getCurrentSize()) + numCopied = snprintf(mCurBufferp, getBufferSize()-getCurrentSize(), "%02x ", value[i]); /* Flawfinder: ignore */ + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::packBinaryData: data truncated: " << llendl; bBufferFull = TRUE; } mCurBufferp += numCopied; @@ -637,10 +640,11 @@ BOOL LLDataPackerAsciiBuffer::packBinaryData(const U8 *value, S32 size, const ch if (!bBufferFull) { - numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(), "\n"); /* Flawfinder: ignore */ - if (numCopied > getBufferSize()-getCurrentSize()) + numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(), "\n"); /* Flawfinder: ignore */ + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::packBinaryData: newline truncated: " << llendl; } mCurBufferp += numCopied; } @@ -698,10 +702,11 @@ BOOL LLDataPackerAsciiBuffer::packBinaryDataFixed(const U8 *value, S32 size, con BOOL bBufferFull = FALSE; for (i = 0; i < size && !bBufferFull; i++) { - numCopied = snprintf(mCurBufferp, getBufferSize()-getCurrentSize(), "%02x ", value[i]); /* Flawfinder: ignore */ - if (numCopied > getBufferSize()-getCurrentSize()) + numCopied = snprintf(mCurBufferp, getBufferSize()-getCurrentSize(), "%02x ", value[i]); /* Flawfinder: ignore */ + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::packBinaryDataFixed: data truncated: " << llendl; bBufferFull = TRUE; } mCurBufferp += numCopied; @@ -709,10 +714,11 @@ BOOL LLDataPackerAsciiBuffer::packBinaryDataFixed(const U8 *value, S32 size, con } if (!bBufferFull) { - numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(), "\n"); /* Flawfinder: ignore */ - if (numCopied > getBufferSize()-getCurrentSize()) + numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(), "\n"); /* Flawfinder: ignore */ + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::packBinaryDataFixed: newline truncated: " << llendl; } mCurBufferp += numCopied; @@ -762,21 +768,24 @@ BOOL LLDataPackerAsciiBuffer::packU8(const U8 value, const char *name) int numCopied = 0; if (mWriteEnabled) { - numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /*Flawfinder: ignore*/ + numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /* Flawfinder: ignore */ } else { // just do the write to a temp buffer to get the length - numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%d\n", value); /* Flawfinder: ignore */ + numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%d\n", value); /* Flawfinder: ignore */ } - // snprintf returns number of bytes that would have been written had the - // output not being truncated. In that case, it will retuen >= passed in size value. - // so a check needs to be added to detect truncation, and if there is any, - // only account for the actual number of bytes written..and not what could have been written. - if (numCopied > getBufferSize()-getCurrentSize()) + // snprintf returns number of bytes that would have been written + // had the output not being truncated. In that case, it will + // return either -1 or value >= passed in size value . So a check needs to be added + // to detect truncation, and if there is any, only account for the + // actual number of bytes written..and not what could have been + // written. + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::packU8: val truncated: " << llendl; } mCurBufferp += numCopied; @@ -807,20 +816,23 @@ BOOL LLDataPackerAsciiBuffer::packU16(const U16 value, const char *name) int numCopied = 0; if (mWriteEnabled) { - numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /*Flawfinder: ignore*/ + numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /* Flawfinder: ignore */ } else { - numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%d\n", value); /* Flawfinder: ignore */ + numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%d\n", value); /* Flawfinder: ignore */ } - // snprintf returns number of bytes that would have been written had the - // output not being truncated. In that case, it will retuen >= passed in size value. - // so a check needs to be added to detect truncation, and if there is any, - // only account for the actual number of bytes written..and not what could have been written. - if (numCopied > getBufferSize()-getCurrentSize()) + // snprintf returns number of bytes that would have been written + // had the output not being truncated. In that case, it will + // return either -1 or value >= passed in size value . So a check needs to be added + // to detect truncation, and if there is any, only account for the + // actual number of bytes written..and not what could have been + // written. + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::packU16: val truncated: " << llendl; } mCurBufferp += numCopied; @@ -852,19 +864,22 @@ BOOL LLDataPackerAsciiBuffer::packU32(const U32 value, const char *name) int numCopied = 0; if (mWriteEnabled) { - numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%u\n", value); /* Flawfinder: ignore */ + numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%u\n", value); /* Flawfinder: ignore */ } else { - numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%u\n", value); /* Flawfinder: ignore */ + numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%u\n", value); /* Flawfinder: ignore */ } - // snprintf returns number of bytes that would have been written had the - // output not being truncated. In that case, it will retuen >= passed in size value. - // so a check needs to be added to detect truncation, and if there is any, - // only account for the actual number of bytes written..and not what could have been written. - if (numCopied > getBufferSize()-getCurrentSize()) + // snprintf returns number of bytes that would have been written + // had the output not being truncated. In that case, it will + // return either -1 or value >= passed in size value . So a check needs to be added + // to detect truncation, and if there is any, only account for the + // actual number of bytes written..and not what could have been + // written. + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::packU32: val truncated: " << llendl; } mCurBufferp += numCopied; @@ -893,19 +908,22 @@ BOOL LLDataPackerAsciiBuffer::packS32(const S32 value, const char *name) int numCopied = 0; if (mWriteEnabled) { - numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /* Flawfinder: ignore */ + numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /* Flawfinder: ignore */ } else { numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%d\n", value); /* Flawfinder: ignore */ } - // snprintf returns number of bytes that would have been written had the - // output not being truncated. In that case, it will retuen >= passed in size value. - // so a check needs to be added to detect truncation, and if there is any, - // only account for the actual number of bytes written..and not what could have been written. - if (numCopied > getBufferSize()-getCurrentSize()) + // snprintf returns number of bytes that would have been written + // had the output not being truncated. In that case, it will + // return either -1 or value >= passed in size value . So a check needs to be added + // to detect truncation, and if there is any, only account for the + // actual number of bytes written..and not what could have been + // written. + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::packS32: val truncated: " << llendl; } mCurBufferp += numCopied; @@ -934,19 +952,22 @@ BOOL LLDataPackerAsciiBuffer::packF32(const F32 value, const char *name) int numCopied = 0; if (mWriteEnabled) { - numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%g\n", value); /* Flawfinder: ignore */ + numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%g\n", value); /* Flawfinder: ignore */ } else { - numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%g\n", value); /* Flawfinder: ignore */ + numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%g\n", value); /* Flawfinder: ignore */ } - // snprintf returns number of bytes that would have been written had the - // output not being truncated. In that case, it will retuen >= passed in size value. - // so a check needs to be added to detect truncation, and if there is any, - // only account for the actual number of bytes written..and not what could have been written. - if (numCopied > getBufferSize()-getCurrentSize()) + // snprintf returns number of bytes that would have been written + // had the output not being truncated. In that case, it will + // return either -1 or value >= passed in size value . So a check needs to be added + // to detect truncation, and if there is any, only account for the + // actual number of bytes written..and not what could have been + // written. + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::packF32: val truncated: " << llendl; } mCurBufferp += numCopied; @@ -975,19 +996,22 @@ BOOL LLDataPackerAsciiBuffer::packColor4(const LLColor4 &value, const char *name int numCopied = 0; if (mWriteEnabled) { - numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%g %g %g %g\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ + numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%g %g %g %g\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ } else { numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%g %g %g %g\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ } - // snprintf returns number of bytes that would have been written had the - // output not being truncated. In that case, it will retuen >= passed in size value. - // so a check needs to be added to detect truncation, and if there is any, - // only account for the actual number of bytes written..and not what could have been written. - if (numCopied > getBufferSize()-getCurrentSize()) + // snprintf returns number of bytes that would have been written + // had the output not being truncated. In that case, it will + // return either -1 or value >= passed in size value . So a check needs to be added + // to detect truncation, and if there is any, only account for the + // actual number of bytes written..and not what could have been + // written. + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::packColor4: truncated: " << llendl; } mCurBufferp += numCopied; @@ -1015,19 +1039,22 @@ BOOL LLDataPackerAsciiBuffer::packColor4U(const LLColor4U &value, const char *na int numCopied = 0; if (mWriteEnabled) { - numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d %d %d %d\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ + numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d %d %d %d\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ } else { numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%d %d %d %d\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ } - // snprintf returns number of bytes that would have been written had the - // output not being truncated. In that case, it will retuen >= passed in size value. - // so a check needs to be added to detect truncation, and if there is any, - // only account for the actual number of bytes written..and not what could have been written. - if (numCopied > getBufferSize()-getCurrentSize()) + // snprintf returns number of bytes that would have been written + // had the output not being truncated. In that case, it will + // return either -1 or value >= passed in size value . So a check needs to be added + // to detect truncation, and if there is any, only account for the + // actual number of bytes written..and not what could have been + // written. + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::packColor4U: truncated: " << llendl; } mCurBufferp += numCopied; @@ -1066,15 +1093,18 @@ BOOL LLDataPackerAsciiBuffer::packVector2(const LLVector2 &value, const char *na } else { - numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%g %g\n", value.mV[0], value.mV[1]); /* Flawfinder: ignore */ + numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%g %g\n", value.mV[0], value.mV[1]); /* Flawfinder: ignore */ } - // snprintf returns number of bytes that would have been written had the - // output not being truncated. In that case, it will retuen >= passed in size value. - // so a check needs to be added to detect truncation, and if there is any, - // only account for the actual number of bytes written..and not what could have been written. - if (numCopied > getBufferSize()-getCurrentSize()) + // snprintf returns number of bytes that would have been written + // had the output not being truncated. In that case, it will + // return either -1 or value >= passed in size value . So a check needs to be added + // to detect truncation, and if there is any, only account for the + // actual number of bytes written..and not what could have been + // written. + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::packVector2: truncated: " << llendl; } mCurBufferp += numCopied; @@ -1109,13 +1139,16 @@ BOOL LLDataPackerAsciiBuffer::packVector3(const LLVector3 &value, const char *na { numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%g %g %g\n", value.mV[0], value.mV[1], value.mV[2]); /* Flawfinder: ignore */ } - // snprintf returns number of bytes that would have been written had the - // output not being truncated. In that case, it will retuen >= passed in size value. - // so a check needs to be added to detect truncation, and if there is any, - // only account for the actual number of bytes written..and not what could have been written. - if (numCopied > getBufferSize()-getCurrentSize()) + // snprintf returns number of bytes that would have been written + // had the output not being truncated. In that case, it will + // return either -1 or value >= passed in size value . So a check needs to be added + // to detect truncation, and if there is any, only account for the + // actual number of bytes written..and not what could have been + // written. + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::packVector3: truncated: " << llendl; } mCurBufferp += numCopied; @@ -1149,13 +1182,16 @@ BOOL LLDataPackerAsciiBuffer::packVector4(const LLVector4 &value, const char *na { numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%g %g %g %g\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ } - // snprintf returns number of bytes that would have been written had the - // output not being truncated. In that case, it will retuen >= passed in size value. - // so a check needs to be added to detect truncation, and if there is any, - // only account for the actual number of bytes written..and not what could have been written. - if (numCopied > getBufferSize()-getCurrentSize()) + // snprintf returns number of bytes that would have been written + // had the output not being truncated. In that case, it will + // return either -1 or value >= passed in size value . So a check needs to be added + // to detect truncation, and if there is any, only account for the + // actual number of bytes written..and not what could have been + // written. + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::packVector4: truncated: " << llendl; } mCurBufferp += numCopied; @@ -1193,13 +1229,16 @@ BOOL LLDataPackerAsciiBuffer::packUUID(const LLUUID &value, const char *name) { numCopied = 64 + 1; // UUID + newline } - // snprintf returns number of bytes that would have been written had the - // output not being truncated. In that case, it will retuen >= passed in size value. - // so a check needs to be added to detect truncation, and if there is any, - // only account for the actual number of bytes written..and not what could have been written. - if (numCopied > getBufferSize()-getCurrentSize()) + // snprintf returns number of bytes that would have been written + // had the output not being truncated. In that case, it will + // return either -1 or value >= passed in size value . So a check needs to be added + // to detect truncation, and if there is any, only account for the + // actual number of bytes written..and not what could have been + // written. + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::packUUID: truncated: " << llendl; success = FALSE; } mCurBufferp += numCopied; @@ -1235,21 +1274,26 @@ void LLDataPackerAsciiBuffer::writeIndentedName(const char *name) int numCopied = 0; if (mWriteEnabled) { - numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\t", name); /* Flawfinder: ignore */ + numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\t", name); /* Flawfinder: ignore */ } else { numCopied = (S32)strlen(name) + 1; /* Flawfinder: ignore */ //name + tab } - // snprintf returns number of bytes that would have been written had the - // output not being truncated. In that case, it will retuen >= passed in size value. - // so a check needs to be added to detect truncation, and if there is any, - // only account for the actual number of bytes written..and not what could have been written. - if (numCopied > getBufferSize()-getCurrentSize()) + // snprintf returns number of bytes that would have been written + // had the output not being truncated. In that case, it will + // return either -1 or value >= passed in size value . So a check needs to be added + // to detect truncation, and if there is any, only account for the + // actual number of bytes written..and not what could have been + // written. + if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); + llwarns << "LLDataPackerAsciiBuffer::writeIndentedName: truncated: " << llendl; } + + mCurBufferp += numCopied; } } @@ -1405,7 +1449,7 @@ BOOL LLDataPackerAsciiFile::packBinaryDataFixed(const U8 *value, S32 size, const S32 i; for (i = 0; i < size; i++) { - snprintf(buffer, sizeof(buffer), "%02x ", value[i]); /*Flawfinder: ignore*/ + snprintf(buffer, sizeof(buffer), "%02x ", value[i]); /* Flawfinder: ignore */ *mOutputStream << buffer; } *mOutputStream << "\n"; diff --git a/indra/llmessage/llhost.cpp b/indra/llmessage/llhost.cpp index 66203321ef..d395188b72 100644 --- a/indra/llmessage/llhost.cpp +++ b/indra/llmessage/llhost.cpp @@ -51,7 +51,7 @@ void LLHost::getString(char* buffer, S32 length) const return; } - snprintf(buffer, length, "%s:%u", u32_to_ip_string(mIP), mPort); /*Flawfinder: ignore*/ + snprintf(buffer, length, "%s:%u", u32_to_ip_string(mIP), mPort); /* Flawfinder: ignore */ } void LLHost::getIPString(char* buffer, S32 length) const @@ -62,7 +62,7 @@ void LLHost::getIPString(char* buffer, S32 length) const return; } - snprintf(buffer, length, "%s", u32_to_ip_string(mIP)); /*Flawfinder: ignore*/ + snprintf(buffer, length, "%s", u32_to_ip_string(mIP)); /* Flawfinder: ignore */ } diff --git a/indra/llmessage/llhttpassetstorage.cpp b/indra/llmessage/llhttpassetstorage.cpp index e786cf64b3..a4eebed504 100644 --- a/indra/llmessage/llhttpassetstorage.cpp +++ b/indra/llmessage/llhttpassetstorage.cpp @@ -672,7 +672,7 @@ void LLHTTPAssetStorage::checkForTimeouts() char uuid_str[UUID_STR_LENGTH]; /*Flawfinder: ignore*/ req->getUUID().toString(uuid_str); std::string base_url = getBaseURL(req->getUUID(), req->getType()); - snprintf(tmp_url, sizeof(tmp_url), "%s/%36s.%s", base_url.c_str() , uuid_str, LLAssetType::lookup(req->getType())); /*Flawfinder: ignore*/ + snprintf(tmp_url, sizeof(tmp_url), "%s/%36s.%s", base_url.c_str() , uuid_str, LLAssetType::lookup(req->getType())); /* Flawfinder: ignore */ LLHTTPAssetRequest *new_req = new LLHTTPAssetRequest(this, req->getUUID(), req->getType(), RT_DOWNLOAD, tmp_url, mCurlMultiHandle); @@ -707,7 +707,7 @@ void LLHTTPAssetStorage::checkForTimeouts() char tmp_url[MAX_STRING];/*Flawfinder: ignore*/ char uuid_str[UUID_STR_LENGTH];/*Flawfinder: ignore*/ req->getUUID().toString(uuid_str); - snprintf(tmp_url, sizeof(tmp_url), /*Flawfinder: ignore*/ + snprintf(tmp_url, sizeof(tmp_url), /* Flawfinder: ignore */ do_compress ? "%s/%s.%s.gz" : "%s/%s.%s", mBaseURL.c_str(), uuid_str, LLAssetType::lookup(req->getType())); @@ -762,7 +762,7 @@ void LLHTTPAssetStorage::checkForTimeouts() req->getUUID().toString(uuid_str); // KLW - All temporary uploads are saved locally "http://localhost:12041/asset" - snprintf(tmp_url, sizeof(tmp_url), "%s/%36s.%s", mLocalBaseURL.c_str(), uuid_str, LLAssetType::lookup(req->getType())); /*Flawfinder: ignore*/ + snprintf(tmp_url, sizeof(tmp_url), "%s/%36s.%s", mLocalBaseURL.c_str(), uuid_str, LLAssetType::lookup(req->getType())); /* Flawfinder: ignore */ LLHTTPAssetRequest *new_req = new LLHTTPAssetRequest(this, req->getUUID(), req->getType(), RT_LOCALUPLOAD, tmp_url, mCurlMultiHandle); diff --git a/indra/llmessage/llinstantmessage.cpp b/indra/llmessage/llinstantmessage.cpp index ecdc9e6dc3..944785c3a5 100644 --- a/indra/llmessage/llinstantmessage.cpp +++ b/indra/llmessage/llinstantmessage.cpp @@ -207,8 +207,21 @@ void pack_instant_message_block( S32 bytes_left = MTUBYTES; if(message) { - char buffer[MTUBYTES]; /*Flawfinder: ignore*/ - bytes_left -= snprintf(buffer, MTUBYTES, "%s", message); /*Flawfinder: ignore*/ + char buffer[MTUBYTES]; + int num_written = snprintf(buffer, MTUBYTES, "%s", message); /* Flawfinder: ignore */ + // snprintf returns number of bytes that would have been written + // had the output not being truncated. In that case, it will + // return either -1 or value >= passed in size value . So a check needs to be added + // to detect truncation, and if there is any, only account for the + // actual number of bytes written..and not what could have been + // written. + if (num_written < 0 || num_written >= MTUBYTES) + { + num_written = MTUBYTES - 1; + llwarns << "pack_instant_message_block: message truncated: " << message << llendl; + } + + bytes_left -= num_written; bytes_left = llmax(0, bytes_left); msg->addStringFast(_PREHASH_Message, buffer); } diff --git a/indra/llmessage/llxfer_file.cpp b/indra/llmessage/llxfer_file.cpp index 46d31685e3..14c266950d 100644 --- a/indra/llmessage/llxfer_file.cpp +++ b/indra/llmessage/llxfer_file.cpp @@ -114,7 +114,7 @@ S32 LLXfer_File::initializeRequest(U64 xfer_id, mRemoteHost = remote_host; mDeleteRemoteOnCompletion = delete_remote_on_completion; - snprintf(mTempFilename, sizeof(mTempFilename), "%s",gDirUtilp->getTempFilename().c_str()); /* Flawfinder : ignore */ + snprintf(mTempFilename, sizeof(mTempFilename), "%s",gDirUtilp->getTempFilename().c_str()); /* Flawfinder: ignore */ mCallback = callback; mCallbackDataHandle = user_data; diff --git a/indra/llmessage/message.cpp b/indra/llmessage/message.cpp index ec2f0cd20a..099b6a0a5b 100644 --- a/indra/llmessage/message.cpp +++ b/indra/llmessage/message.cpp @@ -1950,7 +1950,7 @@ BOOL LLMessageSystem::checkMessages( S64 frame_count ) std::ostringstream str; str << "MSG: <- " << host; char buffer[MAX_STRING]; /* Flawfinder: ignore*/ - snprintf(buffer, MAX_STRING, "\t%6d\t%6d\t%6d ", mReceiveSize, (mIncomingCompressedSize ? mIncomingCompressedSize : mReceiveSize), mCurrentRecvPacketID);/* Flawfinder: ignore*/ + snprintf(buffer, MAX_STRING, "\t%6d\t%6d\t%6d ", mReceiveSize, (mIncomingCompressedSize ? mIncomingCompressedSize : mReceiveSize), mCurrentRecvPacketID); /* Flawfinder: ignore */ str << buffer << "(unknown)" << (recv_reliable ? " reliable" : "") << " resent " @@ -3224,7 +3224,7 @@ void LLMessageSystem::logMsgFromInvalidCircuit( const LLHost& host, BOOL recv_re std::ostringstream str; str << "MSG: <- " << host; char buffer[MAX_STRING]; /* Flawfinder: ignore */ - snprintf(buffer, MAX_STRING, "\t%6d\t%6d\t%6d ", mReceiveSize, (mIncomingCompressedSize ? mIncomingCompressedSize: mReceiveSize), mCurrentRecvPacketID); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "\t%6d\t%6d\t%6d ", mReceiveSize, (mIncomingCompressedSize ? mIncomingCompressedSize: mReceiveSize), mCurrentRecvPacketID); /* Flawfinder: ignore */ str << buffer << mCurrentRMessageTemplate->mName << (recv_reliable ? " reliable" : "") @@ -4771,75 +4771,75 @@ void LLMessageSystem::summarizeLogs(std::ostream& str) char tmp_str[MAX_STRING]; /* Flawfinder: ignore */ F32 run_time = mMessageSystemTimer.getElapsedTimeF32(); str << "START MESSAGE LOG SUMMARY" << std::endl; - snprintf(buffer, MAX_STRING, "Run time: %12.3f seconds", run_time); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Run time: %12.3f seconds", run_time); /* Flawfinder: ignore */ // Incoming str << buffer << std::endl << "Incoming:" << std::endl; U64_to_str(mTotalBytesIn, tmp_str, sizeof(tmp_str)); - snprintf(buffer, MAX_STRING, "Total bytes received: %20s (%5.2f kbits per second)", tmp_str, ((F32)mTotalBytesIn * 0.008f) / run_time); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Total bytes received: %20s (%5.2f kbits per second)", tmp_str, ((F32)mTotalBytesIn * 0.008f) / run_time); /* Flawfinder: ignore */ str << buffer << std::endl; U64_to_str(mPacketsIn, tmp_str, sizeof(tmp_str)); - snprintf(buffer, MAX_STRING, "Total packets received: %20s (%5.2f packets per second)", tmp_str, ((F32) mPacketsIn / run_time)); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Total packets received: %20s (%5.2f packets per second)", tmp_str, ((F32) mPacketsIn / run_time)); /* Flawfinder: ignore */ str << buffer << std::endl; - snprintf(buffer, MAX_STRING, "Average packet size: %20.0f bytes", (F32)mTotalBytesIn / (F32)mPacketsIn); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Average packet size: %20.0f bytes", (F32)mTotalBytesIn / (F32)mPacketsIn); /* Flawfinder: ignore */ str << buffer << std::endl; U64_to_str(mReliablePacketsIn, tmp_str, sizeof(tmp_str)); - snprintf(buffer, MAX_STRING, "Total reliable packets: %20s (%5.2f%%)", tmp_str, 100.f * ((F32) mReliablePacketsIn)/((F32) mPacketsIn + 1)); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Total reliable packets: %20s (%5.2f%%)", tmp_str, 100.f * ((F32) mReliablePacketsIn)/((F32) mPacketsIn + 1)); /* Flawfinder: ignore */ str << buffer << std::endl; U64_to_str(mCompressedPacketsIn, tmp_str, sizeof(tmp_str)); - snprintf(buffer, MAX_STRING, "Total compressed packets: %20s (%5.2f%%)", tmp_str, 100.f * ((F32) mCompressedPacketsIn)/((F32) mPacketsIn + 1)); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Total compressed packets: %20s (%5.2f%%)", tmp_str, 100.f * ((F32) mCompressedPacketsIn)/((F32) mPacketsIn + 1)); /* Flawfinder: ignore */ str << buffer << std::endl; S64 savings = mUncompressedBytesIn - mCompressedBytesIn; U64_to_str(savings, tmp_str, sizeof(tmp_str)); - snprintf(buffer, MAX_STRING, "Total compression savings: %20s bytes", tmp_str); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Total compression savings: %20s bytes", tmp_str); /* Flawfinder: ignore */ str << buffer << std::endl; U64_to_str(savings/(mCompressedPacketsIn +1), tmp_str, sizeof(tmp_str)); - snprintf(buffer, MAX_STRING, "Avg comp packet savings: %20s (%5.2f : 1)", tmp_str, ((F32) mUncompressedBytesIn)/((F32) mCompressedBytesIn+1)); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Avg comp packet savings: %20s (%5.2f : 1)", tmp_str, ((F32) mUncompressedBytesIn)/((F32) mCompressedBytesIn+1)); /* Flawfinder: ignore */ str << buffer << std::endl; U64_to_str(savings/(mPacketsIn+1), tmp_str, sizeof(tmp_str)); - snprintf(buffer, MAX_STRING, "Avg overall comp savings: %20s (%5.2f : 1)", tmp_str, ((F32) mTotalBytesIn + (F32) savings)/((F32) mTotalBytesIn + 1.f)); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Avg overall comp savings: %20s (%5.2f : 1)", tmp_str, ((F32) mTotalBytesIn + (F32) savings)/((F32) mTotalBytesIn + 1.f)); /* Flawfinder: ignore */ // Outgoing str << buffer << std::endl << std::endl << "Outgoing:" << std::endl; U64_to_str(mTotalBytesOut, tmp_str, sizeof(tmp_str)); - snprintf(buffer, MAX_STRING, "Total bytes sent: %20s (%5.2f kbits per second)", tmp_str, ((F32)mTotalBytesOut * 0.008f) / run_time ); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Total bytes sent: %20s (%5.2f kbits per second)", tmp_str, ((F32)mTotalBytesOut * 0.008f) / run_time ); /* Flawfinder: ignore */ str << buffer << std::endl; U64_to_str(mPacketsOut, tmp_str, sizeof(tmp_str)); - snprintf(buffer, MAX_STRING, "Total packets sent: %20s (%5.2f packets per second)", tmp_str, ((F32)mPacketsOut / run_time)); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Total packets sent: %20s (%5.2f packets per second)", tmp_str, ((F32)mPacketsOut / run_time)); /* Flawfinder: ignore */ str << buffer << std::endl; - snprintf(buffer, MAX_STRING, "Average packet size: %20.0f bytes", (F32)mTotalBytesOut / (F32)mPacketsOut); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Average packet size: %20.0f bytes", (F32)mTotalBytesOut / (F32)mPacketsOut); /* Flawfinder: ignore */ str << buffer << std::endl; U64_to_str(mReliablePacketsOut, tmp_str, sizeof(tmp_str)); - snprintf(buffer, MAX_STRING, "Total reliable packets: %20s (%5.2f%%)", tmp_str, 100.f * ((F32) mReliablePacketsOut)/((F32) mPacketsOut + 1)); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Total reliable packets: %20s (%5.2f%%)", tmp_str, 100.f * ((F32) mReliablePacketsOut)/((F32) mPacketsOut + 1)); /* Flawfinder: ignore */ str << buffer << std::endl; U64_to_str(mCompressedPacketsOut, tmp_str, sizeof(tmp_str)); - snprintf(buffer, MAX_STRING, "Total compressed packets: %20s (%5.2f%%)", tmp_str, 100.f * ((F32) mCompressedPacketsOut)/((F32) mPacketsOut + 1)); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Total compressed packets: %20s (%5.2f%%)", tmp_str, 100.f * ((F32) mCompressedPacketsOut)/((F32) mPacketsOut + 1)); /* Flawfinder: ignore */ str << buffer << std::endl; savings = mUncompressedBytesOut - mCompressedBytesOut; U64_to_str(savings, tmp_str, sizeof(tmp_str)); - snprintf(buffer, MAX_STRING, "Total compression savings: %20s bytes", tmp_str); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Total compression savings: %20s bytes", tmp_str); /* Flawfinder: ignore */ str << buffer << std::endl; U64_to_str(savings/(mCompressedPacketsOut +1), tmp_str, sizeof(tmp_str)); - snprintf(buffer, MAX_STRING, "Avg comp packet savings: %20s (%5.2f : 1)", tmp_str, ((F32) mUncompressedBytesOut)/((F32) mCompressedBytesOut+1)); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Avg comp packet savings: %20s (%5.2f : 1)", tmp_str, ((F32) mUncompressedBytesOut)/((F32) mCompressedBytesOut+1)); /* Flawfinder: ignore */ str << buffer << std::endl; U64_to_str(savings/(mPacketsOut+1), tmp_str, sizeof(tmp_str)); - snprintf(buffer, MAX_STRING, "Avg overall comp savings: %20s (%5.2f : 1)", tmp_str, ((F32) mTotalBytesOut + (F32) savings)/((F32) mTotalBytesOut + 1.f)); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Avg overall comp savings: %20s (%5.2f : 1)", tmp_str, ((F32) mTotalBytesOut + (F32) savings)/((F32) mTotalBytesOut + 1.f)); /* Flawfinder: ignore */ str << buffer << std::endl << std::endl; - snprintf(buffer, MAX_STRING, "SendPacket failures: %20d", mSendPacketFailureCount); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "SendPacket failures: %20d", mSendPacketFailureCount); /* Flawfinder: ignore */ str << buffer << std::endl; - snprintf(buffer, MAX_STRING, "Dropped packets: %20d", mDroppedPackets); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Dropped packets: %20d", mDroppedPackets); /* Flawfinder: ignore */ str << buffer << std::endl; - snprintf(buffer, MAX_STRING, "Resent packets: %20d", mResentPackets); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Resent packets: %20d", mResentPackets); /* Flawfinder: ignore */ str << buffer << std::endl; - snprintf(buffer, MAX_STRING, "Failed reliable resends: %20d", mFailedResendPackets); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Failed reliable resends: %20d", mFailedResendPackets); /* Flawfinder: ignore */ str << buffer << std::endl; - snprintf(buffer, MAX_STRING, "Off-circuit rejected packets: %17d", mOffCircuitPackets); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "Off-circuit rejected packets: %17d", mOffCircuitPackets); /* Flawfinder: ignore */ str << buffer << std::endl; - snprintf(buffer, MAX_STRING, "On-circuit invalid packets: %17d", mInvalidOnCircuitPackets); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "On-circuit invalid packets: %17d", mInvalidOnCircuitPackets); /* Flawfinder: ignore */ str << buffer << std::endl << std::endl; str << "Decoding: " << std::endl; - snprintf(buffer, MAX_STRING, "%35s%10s%10s%10s%10s", "Message", "Count", "Time", "Max", "Avg"); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "%35s%10s%10s%10s%10s", "Message", "Count", "Time", "Max", "Avg"); /* Flawfinder: ignore */ str << buffer << std:: endl; F32 avg; for (message_template_name_map_t::iterator iter = mMessageTemplates.begin(), @@ -4850,7 +4850,7 @@ void LLMessageSystem::summarizeLogs(std::ostream& str) if(mt->mTotalDecoded > 0) { avg = mt->mTotalDecodeTime / (F32)mt->mTotalDecoded; - snprintf(buffer, MAX_STRING, "%35s%10u%10f%10f%10f", mt->mName, mt->mTotalDecoded, mt->mTotalDecodeTime, mt->mMaxDecodeTimePerMsg, avg); /* Flawfinder: ignore */ + snprintf(buffer, MAX_STRING, "%35s%10u%10f%10f%10f", mt->mName, mt->mTotalDecoded, mt->mTotalDecodeTime, mt->mMaxDecodeTimePerMsg, avg); /* Flawfinder: ignore */ str << buffer << std::endl; } } @@ -5565,7 +5565,7 @@ bool LLMessageSystem::generateDigestForNumberAndUUIDs( d.update((const unsigned char *) colon, (U32)strlen(colon)); /* Flawfinder: ignore */ - snprintf(tbuf, sizeof(tbuf),"%i", number); /* Flawfinder: ignore */ + snprintf(tbuf, sizeof(tbuf),"%i", number); /* Flawfinder: ignore */ d.update((unsigned char *) tbuf, (U32)strlen(tbuf)); /* Flawfinder: ignore */ d.update((const unsigned char *) colon, (U32)strlen(colon)); /* Flawfinder: ignore */ @@ -5824,7 +5824,7 @@ void LLMessageSystem::dumpPacketToLog() S32 cur_line = 0; for (i = 0; i < mTrueReceiveSize; i++) { - snprintf(line_buffer + cur_line_pos*3, sizeof(line_buffer),"%02x ", mTrueReceiveBuffer[i]); /* Flawfinder: ignore */ + snprintf(line_buffer + cur_line_pos*3, sizeof(line_buffer),"%02x ", mTrueReceiveBuffer[i]); /* Flawfinder: ignore */ cur_line_pos++; if (cur_line_pos >= 16) { |