Skip to content

Commit

Permalink
parser: Fix error handling for HEX_STR parsing in UDP_CHECK
Browse files Browse the repository at this point in the history
Fixes an issue where HEX_STR values with a trailing 0xff were incorrectly
treated as errors. This HEX_STR is used in UDP_CHECK configuration,
particularly in the payload and require_reply fields.
  • Loading branch information
setoh2000 committed Dec 13, 2024
1 parent 91baa39 commit e7bf4d1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ read_hex_str(const char *str, uint8_t **data, uint8_t **data_mask)
uint8_t mask_val;
bool using_mask = false;
uint16_t len;
bool has_error = false;

/* The output octet string cannot be longer than (strlen(str) + 1)/2 */
str_len = (strlen(str) + 1) / 2;
Expand All @@ -745,8 +746,10 @@ read_hex_str(const char *str, uint8_t **data, uint8_t **data_mask)
break;

val = hex_val(*p++, !!data_mask);
if (val == 0xff)
if (val == 0xff) {
has_error = true;
break;
}
if (val == 0xfe) {
mask_val = 0x0f;
val = 0;
Expand All @@ -758,8 +761,10 @@ read_hex_str(const char *str, uint8_t **data, uint8_t **data_mask)
val1 = val << 4;
mask_val <<= 4;
val = hex_val(*p++, !!data_mask);
if (val == 0xff)
if (val == 0xff) {
has_error = true;
break;
}
if (val == 0xfe) {
mask_val |= 0x0f;
val = 0;
Expand All @@ -773,7 +778,7 @@ read_hex_str(const char *str, uint8_t **data, uint8_t **data_mask)
len++;
}

if (val == 0xff || !len) {
if (has_error || !len) {
FREE_ONLY(buf);
FREE_ONLY(mask);
return 0;
Expand Down

0 comments on commit e7bf4d1

Please sign in to comment.