From 412166bc7d3b4be04408ec82475fb7bd7e04aadb Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Fri, 29 Nov 2024 09:21:55 -0500 Subject: [PATCH] ensure cbor_guess_type() always returns a type and push error messages to that function --- src/lib/util/cbor.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/lib/util/cbor.c b/src/lib/util/cbor.c index b5799105b637..d9d44a383f40 100644 --- a/src/lib/util/cbor.c +++ b/src/lib/util/cbor.c @@ -1001,14 +1001,7 @@ ssize_t fr_cbor_decode_value_box(TALLOC_CTX *ctx, fr_value_box_t *vb, fr_dbuff_t if (type == FR_TYPE_NULL) { type = cbor_guess_type(&work_dbuff, false); - if (type < 0) { - fr_strerror_printf("Invalid cbor - insufficient data"); - return type; - } - if (type == FR_TYPE_NULL) { - fr_strerror_printf("Invalid cbor - unable to determine data type"); - return 0; - } + if (type == FR_TYPE_NULL) return 0; } fr_value_box_init(vb, type, enumv, tainted); @@ -1537,7 +1530,12 @@ static fr_type_t cbor_guess_type(fr_dbuff_t *dbuff, bool pair) /* * get the next byte, which is a CBOR header. */ - FR_DBUFF_OUT_RETURN(&major, &work_dbuff); + slen = fr_dbuff_out(&major, &work_dbuff); + if (slen <= 0) { + no_data: + fr_strerror_const("Invalid cbor - insufficient data"); + return FR_TYPE_NULL; + } info = major & 0x1f; major >>= 5; @@ -1581,7 +1579,8 @@ static fr_type_t cbor_guess_type(fr_dbuff_t *dbuff, bool pair) return FR_TYPE_ETHERNET; case 52: - FR_DBUFF_OUT_RETURN(&major, &work_dbuff); + slen = fr_dbuff_out(&major, &work_dbuff); + if (slen <= 0) goto no_data; major >>= 5; @@ -1627,6 +1626,7 @@ static fr_type_t cbor_guess_type(fr_dbuff_t *dbuff, bool pair) * converted to data type 'octets'. This work involves mostly parsing the cbor data, which isn't * trivial. */ + fr_strerror_const("Invalid cbor - unable to determine data type"); return FR_TYPE_NULL; } @@ -1675,10 +1675,7 @@ ssize_t fr_cbor_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dbuff_t *db fr_type_t type; type = cbor_guess_type(&work_dbuff, true); - if (type == FR_TYPE_NULL) { - fr_strerror_printf("Invalid cbor - unable to determine data type"); - return -fr_dbuff_used(&work_dbuff); - } + if (type == FR_TYPE_NULL) return -fr_dbuff_used(&work_dbuff); /* * @todo - the value here isn't a cbor octets type, but is instead cbor data. Since cbor