Fix BACnet IPv4 decode to allow for NULL (#72)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
@@ -1042,6 +1042,9 @@ int bvlc_bbmd_enabled_handler(BACNET_IP_ADDRESS *addr,
|
|||||||
bvlc_ip_address_to_bacnet_local(src, addr);
|
bvlc_ip_address_to_bacnet_local(src, addr);
|
||||||
offset = header_len + function_len - npdu_len;
|
offset = header_len + function_len - npdu_len;
|
||||||
debug_print_npdu("Original-Unicast-NPDU", offset, npdu_len);
|
debug_print_npdu("Original-Unicast-NPDU", offset, npdu_len);
|
||||||
|
} else {
|
||||||
|
debug_print_string(
|
||||||
|
"Original-Broadcast-NPDU: Unable to decode!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BVLC_ORIGINAL_BROADCAST_NPDU:
|
case BVLC_ORIGINAL_BROADCAST_NPDU:
|
||||||
@@ -1074,6 +1077,9 @@ int bvlc_bbmd_enabled_handler(BACNET_IP_ADDRESS *addr,
|
|||||||
bbmd_fdt_forward_npdu(addr, npdu, npdu_len, true);
|
bbmd_fdt_forward_npdu(addr, npdu, npdu_len, true);
|
||||||
bbmd_bdt_forward_npdu(addr, npdu, npdu_len, true);
|
bbmd_bdt_forward_npdu(addr, npdu, npdu_len, true);
|
||||||
debug_print_npdu("Original-Broadcast-NPDU", offset, npdu_len);
|
debug_print_npdu("Original-Broadcast-NPDU", offset, npdu_len);
|
||||||
|
} else {
|
||||||
|
debug_print_string(
|
||||||
|
"Original-Broadcast-NPDU: Unable to decode!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BVLC_SECURE_BVLL:
|
case BVLC_SECURE_BVLL:
|
||||||
@@ -1245,10 +1251,12 @@ void bvlc_disable_nat(void)
|
|||||||
|
|
||||||
void bvlc_init(void)
|
void bvlc_init(void)
|
||||||
{
|
{
|
||||||
debug_print_string("Initializing.");
|
|
||||||
#if BBMD_ENABLED
|
#if BBMD_ENABLED
|
||||||
|
debug_print_string("Initializing (BBMD Enabled).");
|
||||||
bvlc_broadcast_distribution_table_link_array(
|
bvlc_broadcast_distribution_table_link_array(
|
||||||
&BBMD_Table[0], MAX_BBMD_ENTRIES);
|
&BBMD_Table[0], MAX_BBMD_ENTRIES);
|
||||||
bvlc_foreign_device_table_link_array(&FD_Table[0], MAX_FD_ENTRIES);
|
bvlc_foreign_device_table_link_array(&FD_Table[0], MAX_FD_ENTRIES);
|
||||||
|
#else
|
||||||
|
debug_print_string("Initializing (BBMD Disabled).");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-40
@@ -1385,19 +1385,15 @@ int bvlc_decode_distribute_broadcast_to_network(uint8_t *pdu,
|
|||||||
int bytes_consumed = 0;
|
int bytes_consumed = 0;
|
||||||
uint16_t i = 0;
|
uint16_t i = 0;
|
||||||
|
|
||||||
if (pdu) {
|
if (pdu && npdu && (pdu_len > 0) && (pdu_len <= npdu_size)) {
|
||||||
if ((pdu_len > 0) && (pdu_len <= npdu_size)) {
|
for (i = 0; i < pdu_len; i++) {
|
||||||
if (npdu) {
|
npdu[i] = pdu[i];
|
||||||
for (i = 0; i < pdu_len; i++) {
|
|
||||||
npdu[i] = pdu[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (npdu_len) {
|
|
||||||
*npdu_len = pdu_len;
|
|
||||||
}
|
|
||||||
bytes_consumed = (int)pdu_len;
|
|
||||||
}
|
}
|
||||||
|
if (npdu_len) {
|
||||||
|
*npdu_len = pdu_len;
|
||||||
|
}
|
||||||
|
bytes_consumed = (int)pdu_len;
|
||||||
|
|
||||||
return bytes_consumed;
|
return bytes_consumed;
|
||||||
}
|
}
|
||||||
@@ -1464,17 +1460,15 @@ int bvlc_decode_original_unicast(uint8_t *pdu,
|
|||||||
int bytes_consumed = 0;
|
int bytes_consumed = 0;
|
||||||
uint16_t i = 0;
|
uint16_t i = 0;
|
||||||
|
|
||||||
if (pdu_len <= npdu_size) {
|
if (pdu && npdu && (pdu_len > 0) && (pdu_len <= npdu_size)) {
|
||||||
if (pdu && npdu) {
|
for (i = 0; i < pdu_len; i++) {
|
||||||
for (i = 0; i < pdu_len; i++) {
|
npdu[i] = pdu[i];
|
||||||
npdu[i] = pdu[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (npdu_len) {
|
|
||||||
*npdu_len = pdu_len;
|
|
||||||
}
|
|
||||||
bytes_consumed = (int)pdu_len;
|
|
||||||
}
|
}
|
||||||
|
if (npdu_len) {
|
||||||
|
*npdu_len = pdu_len;
|
||||||
|
}
|
||||||
|
bytes_consumed = (int)pdu_len;
|
||||||
|
|
||||||
return bytes_consumed;
|
return bytes_consumed;
|
||||||
}
|
}
|
||||||
@@ -1541,17 +1535,15 @@ int bvlc_decode_original_broadcast(uint8_t *pdu,
|
|||||||
int bytes_consumed = 0;
|
int bytes_consumed = 0;
|
||||||
uint16_t i = 0;
|
uint16_t i = 0;
|
||||||
|
|
||||||
if (pdu_len <= npdu_size) {
|
if (pdu && npdu && (pdu_len > 0) && (pdu_len <= npdu_size)) {
|
||||||
if (pdu && npdu) {
|
for (i = 0; i < pdu_len; i++) {
|
||||||
for (i = 0; i < pdu_len; i++) {
|
npdu[i] = pdu[i];
|
||||||
npdu[i] = pdu[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (npdu_len) {
|
|
||||||
*npdu_len = pdu_len;
|
|
||||||
}
|
|
||||||
bytes_consumed = (int)pdu_len;
|
|
||||||
}
|
}
|
||||||
|
if (npdu_len) {
|
||||||
|
*npdu_len = pdu_len;
|
||||||
|
}
|
||||||
|
bytes_consumed = (int)pdu_len;
|
||||||
|
|
||||||
return bytes_consumed;
|
return bytes_consumed;
|
||||||
}
|
}
|
||||||
@@ -1618,19 +1610,15 @@ int bvlc_decode_secure_bvll(uint8_t *pdu,
|
|||||||
int bytes_consumed = 0;
|
int bytes_consumed = 0;
|
||||||
uint16_t i = 0;
|
uint16_t i = 0;
|
||||||
|
|
||||||
if (pdu) {
|
if (pdu && sbuf && (pdu_len > 0) && (pdu_len <= sbuf_size)) {
|
||||||
if (sbuf_len) {
|
for (i = 0; i < pdu_len; i++) {
|
||||||
*sbuf_len = pdu_len;
|
sbuf[i] = pdu[i];
|
||||||
}
|
}
|
||||||
if (pdu_len) {
|
|
||||||
if (sbuf) {
|
|
||||||
for (i = 0; i < pdu_len; i++) {
|
|
||||||
sbuf[i] = pdu[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bytes_consumed = (int)pdu_len;
|
|
||||||
}
|
}
|
||||||
|
if (sbuf_len) {
|
||||||
|
*sbuf_len = pdu_len;
|
||||||
|
}
|
||||||
|
bytes_consumed = (int)pdu_len;
|
||||||
|
|
||||||
return bytes_consumed;
|
return bytes_consumed;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user