#6755 Added a check to prevent buffer overflow
This commit is contained in:
parent
3ac4896b53
commit
0a5fbe6e3e
1 changed files with 37 additions and 29 deletions
|
|
@ -112,11 +112,13 @@ ProtocolUtil::vreadf(synergy::IStream* stream, const char* fmt, va_list args)
|
|||
switch (*fmt) {
|
||||
case 'i': {
|
||||
// check for valid length
|
||||
assert(len == 1 || len == 2 || len == 4);
|
||||
if (len == 4 || len == 2 || len == 1) {
|
||||
|
||||
static const int buffer_size = 4;
|
||||
// read the data
|
||||
UInt8 buffer[4];
|
||||
read(stream, buffer, len);
|
||||
UInt8 buffer[buffer_size];
|
||||
//Read the buffer till the len or buffers_size, which ever is smaller
|
||||
read(stream, buffer, len > buffer_size ? buffer_size : len);
|
||||
|
||||
// convert it
|
||||
void* v = va_arg(args, void*);
|
||||
|
|
@ -146,6 +148,12 @@ ProtocolUtil::vreadf(synergy::IStream* stream, const char* fmt, va_list args)
|
|||
LOG((CLOG_DEBUG2 "readf: read %d byte integer: %d (0x%x)", len, *static_cast<UInt32*>(v), *static_cast<UInt32*>(v)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
//the length is wrong
|
||||
LOG((CLOG_ERR "read: length to be read is wrong: '%d' should be 1,2, or 4", len));
|
||||
assert(false); //assert for debugging
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue