Fixed FQDN hostname limit in minimal hostnport implementation (#1263)

This commit is contained in:
Steve Karg
2026-03-16 17:16:27 -05:00
committed by GitHub
parent a755a8db4d
commit 1c9af1632b
4 changed files with 118 additions and 6 deletions
+35 -5
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include "bacnet/hostnport.h"
#include "bacnet/bacdcode.h"
@@ -441,6 +440,37 @@ int host_n_port_minimal_encode(
return apdu_len;
}
/**
* @brief Encode a context encoded BACnetHostNPort_Minimal complex data type
* @param apdu - the APDU buffer, or NULL for length
* @param tag_number - context tag number to be encoded
* @param host - BACnetHostNPort_Minimal SEQUENCE
* @return length of the encoded APDU buffer
*/
int host_n_port_minimal_context_encode(
uint8_t *apdu, uint8_t tag_number, const BACNET_HOST_N_PORT_MINIMAL *host)
{
int len = 0;
int apdu_len = 0;
if (host) {
len = encode_opening_tag(apdu, tag_number);
apdu_len += len;
if (apdu) {
apdu += len;
}
len = host_n_port_minimal_encode(apdu, host);
apdu_len += len;
if (apdu) {
apdu += len;
}
len = encode_closing_tag(apdu, tag_number);
apdu_len += len;
}
return apdu_len;
}
/**
* @brief Decode the BACnetHostAddress
* @param apdu - the APDU buffer
@@ -694,7 +724,7 @@ void host_n_port_minimal_ip_init(
const uint8_t *address,
size_t address_len)
{
unsigned i, imax;
uint8_t i, imax;
if (host) {
host->tag = BACNET_HOST_ADDRESS_TAG_IP_ADDRESS;
@@ -722,7 +752,7 @@ void host_n_port_minimal_ip_init(
void host_n_port_minimal_hostname_init(
BACNET_HOST_N_PORT_MINIMAL *host, uint16_t port, const char *hostname)
{
unsigned i;
uint8_t i;
if (host) {
host->tag = BACNET_HOST_ADDRESS_TAG_NAME;
@@ -753,7 +783,7 @@ bool host_n_port_minimal_copy(
BACNET_HOST_N_PORT_MINIMAL *dest, const BACNET_HOST_N_PORT_MINIMAL *src)
{
bool status = false;
int i;
uint8_t i;
if (dest && src) {
dest->tag = src->tag;
@@ -873,7 +903,7 @@ bool host_n_port_minimal_same(
const BACNET_HOST_N_PORT_MINIMAL *src)
{
bool status = false;
int i;
uint8_t i;
if (dst && src) {
if (dst->tag == src->tag) {
+15 -1
View File
@@ -42,6 +42,9 @@ typedef struct BACnetHostNPort {
#define BACNET_HOST_ADDRESS_TAG_NONE 0
#define BACNET_HOST_ADDRESS_TAG_IP_ADDRESS 1
#define BACNET_HOST_ADDRESS_TAG_NAME 2
/* RFC 1035 255-octet total limit and 63-octet label limit
including dots and null terminator */
#define BACNET_HOST_NAME_MAX 255
/* BACnetHostNPort with smaller RAM footprint using C datatypes */
typedef struct BACnetHostNPort_Minimal {
uint8_t tag;
@@ -51,13 +54,19 @@ typedef struct BACnetHostNPort_Minimal {
uint8_t length;
} ip_address;
struct BACnetHostCharacterString {
char fqdn[256];
char fqdn[BACNET_HOST_NAME_MAX];
uint8_t length;
} name;
} host;
uint16_t port;
} BACNET_HOST_N_PORT_MINIMAL;
/* Structure to hold the host IP address and hostname for lookup */
typedef struct BACnetHostAddressPair {
struct BACnetHostOctetString ip_address;
struct BACnetHostCharacterString name;
} BACNET_HOST_ADDRESS_PAIR;
/**
* BACnetBDTEntry ::= SEQUENCE {
* bbmd-address [0] BACnetHostNPort,
@@ -158,6 +167,11 @@ int host_n_port_minimal_decode(
BACNET_ERROR_CODE *error_code,
BACNET_HOST_N_PORT_MINIMAL *address);
BACNET_STACK_EXPORT
int host_n_port_minimal_context_encode(
uint8_t *apdu,
uint8_t tag_number,
const BACNET_HOST_N_PORT_MINIMAL *address);
BACNET_STACK_EXPORT
int host_n_port_minimal_context_decode(
const uint8_t *apdu,
uint32_t apdu_size,