mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-02-05 15:39:54 +00:00
Fix [bug #51520] Big endian bug in apps/snmp/snmp_asn1.c
Apply patch from Art Heers that does not need endianess checks
This commit is contained in:
parent
f5d7535323
commit
aa4d978448
@ -579,51 +579,25 @@ snmp_asn1_dec_u64t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t *value
|
|||||||
err_t
|
err_t
|
||||||
snmp_asn1_dec_s32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, s32_t *value)
|
snmp_asn1_dec_s32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, s32_t *value)
|
||||||
{
|
{
|
||||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
|
||||||
u8_t *lsb_ptr = (u8_t*)value;
|
|
||||||
#endif
|
|
||||||
#if BYTE_ORDER == BIG_ENDIAN
|
|
||||||
u8_t *lsb_ptr = (u8_t*)value + sizeof(s32_t) - 1;
|
|
||||||
#endif
|
|
||||||
u8_t sign;
|
|
||||||
u8_t data;
|
u8_t data;
|
||||||
|
|
||||||
if ((len > 0) && (len < 5)) {
|
if ((len > 0) && (len < 5)) {
|
||||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||||
len--;
|
|
||||||
|
|
||||||
if (data & 0x80) {
|
if (data & 0x80) {
|
||||||
/* negative, start from -1 */
|
/* negative, start from -1 */
|
||||||
*value = -1;
|
*value = (-1 << 8) | data;
|
||||||
sign = 1;
|
|
||||||
*lsb_ptr &= data;
|
|
||||||
} else {
|
} else {
|
||||||
/* positive, start from 0 */
|
/* positive, start from 0 */
|
||||||
*value = 0;
|
*value = data;
|
||||||
sign = 0;
|
|
||||||
*lsb_ptr |= data;
|
|
||||||
}
|
}
|
||||||
|
len--;
|
||||||
/* OR/AND octets with value */
|
/* shift in the remaining value */
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||||
|
*value = (*value << 8) | data;
|
||||||
len--;
|
len--;
|
||||||
|
|
||||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
|
||||||
*value <<= 8;
|
|
||||||
#endif
|
|
||||||
#if BYTE_ORDER == BIG_ENDIAN
|
|
||||||
*value >>= 8;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (sign) {
|
|
||||||
*lsb_ptr |= 255;
|
|
||||||
*lsb_ptr &= data;
|
|
||||||
} else {
|
|
||||||
*lsb_ptr |= data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user