Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/BERDecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int IntegerType::fromBuffer(const uint8_t *buf, size_t max_len){
break;
case 3:
if(tempVal & 0x00800000){
tempVal = tempVal |= 0xFF000000;
tempVal |= 0xFF000000;
}
_value = (int32_t)tempVal;
break;
Expand Down Expand Up @@ -133,7 +133,7 @@ int OIDType::fromBuffer(const uint8_t *buf, size_t max_len){
this->data.assign(dataPtr, dataPtr + _length);
this->valid = true;

return _length + 2;
return _length + j;
}

static inline void long_to_buf(char* buf, long l, short r = 0){
Expand Down Expand Up @@ -208,7 +208,7 @@ int Counter64::fromBuffer(const uint8_t *buf, size_t max_len){
_value = _value | *ptr++;
tempLength--;
}
return _length + 2;
return _length + i;
}

std::shared_ptr<BER_CONTAINER> ComplexType::createObjectForType(ASN_TYPE valueType){
Expand Down Expand Up @@ -290,5 +290,5 @@ int ComplexType::fromBuffer(const uint8_t *buf, size_t max_len){
ptr += used_length;
i += used_length;
}
return _length + 2;
return _length + j;
}
4 changes: 2 additions & 2 deletions src/BEREncode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static size_t encode_ber_length_integer(uint8_t* buf, size_t integer, int){
if(integer < 128){
*buf = integer & 0xFF;
} else {
if(integer > 256){
if(integer >= 256){
*buf++ = (2 | 0x80) & 0xFF;
*buf++ = integer/256;
bytes_used += 2;
Expand All @@ -37,7 +37,7 @@ static size_t encode_ber_length_integer(uint8_t* buf, size_t integer, int){
static size_t encode_ber_length_integer_count(size_t integer){
int bytes_used = 1;
if(integer >= 128){
if(integer > 256){
if(integer >= 256){
bytes_used += 2;
} else {
bytes_used++;
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ TEST_CASE( "Test handle failures when Encoding/Decoding", "[snmp]"){
char old[10] = {0};
memcpy(old, &buffer[i], 10);
long randomLong = random();
memcpy(&buffer[i], &randomLong, 10);
memcpy(&buffer[i], &randomLong, sizeof(randomLong));
// This may SOMETIMES fail if the random gets lucky and makes something valid
REQUIRE( readPacket->parseFrom(buffer, 200) != SNMP_ERROR_OK );

Expand Down
Loading