From: Mark Andrews Date: Fri, 23 Jan 2026 03:53:18 +0000 (+1100) Subject: Add enum for use with isc_base64_tobuffer and isc_hex_tobuffer X-Git-Tag: v9.21.18~6^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07610f8566daf532f3dbb312526422cd154b5ceb;p=thirdparty%2Fbind9.git Add enum for use with isc_base64_tobuffer and isc_hex_tobuffer This adds the following enum isc_one_or_more and isc_zero_or_more which specify if one or more or zeror or more bytes are required when reading the unbounded base64 / hex encoded data. --- diff --git a/lib/isc/base64.c b/lib/isc/base64.c index ba4ee7148fd..3b2d19af706 100644 --- a/lib/isc/base64.c +++ b/lib/isc/base64.c @@ -179,7 +179,7 @@ isc_base64_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length) { isc_token_t token; bool eol; - REQUIRE(length >= -2); + REQUIRE(length >= isc_one_or_more); base64_decode_init(&ctx, length, target); @@ -207,7 +207,7 @@ isc_base64_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length) { isc_lex_ungettoken(lexer, &token); } RETERR(base64_decode_finish(&ctx)); - if (length == -2 && before == after) { + if (length == isc_one_or_more && before == after) { return ISC_R_UNEXPECTEDEND; } return ISC_R_SUCCESS; @@ -217,7 +217,7 @@ isc_result_t isc_base64_decodestring(const char *cstr, isc_buffer_t *target) { base64_decode_ctx_t ctx; - base64_decode_init(&ctx, -1, target); + base64_decode_init(&ctx, isc_zero_or_more, target); for (;;) { int c = *cstr++; if (c == '\0') { diff --git a/lib/isc/hex.c b/lib/isc/hex.c index 7f63df7aa64..e063d2fc2b3 100644 --- a/lib/isc/hex.c +++ b/lib/isc/hex.c @@ -128,7 +128,7 @@ isc_hex_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length) { isc_token_t token; bool eol; - REQUIRE(length >= -2); + REQUIRE(length >= isc_one_or_more); isc_hex_decodeinit(&ctx, length, target); @@ -156,7 +156,7 @@ isc_hex_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length) { isc_lex_ungettoken(lexer, &token); } RETERR(isc_hex_decodefinish(&ctx)); - if (length == -2 && before == after) { + if (length == isc_one_or_more && before == after) { return ISC_R_UNEXPECTEDEND; } return ISC_R_SUCCESS; @@ -166,7 +166,7 @@ isc_result_t isc_hex_decodestring(const char *cstr, isc_buffer_t *target) { isc_hex_decodectx_t ctx; - isc_hex_decodeinit(&ctx, -1, target); + isc_hex_decodeinit(&ctx, isc_zero_or_more, target); for (;;) { int c = *cstr++; if (c == '\0') { diff --git a/lib/isc/include/isc/base64.h b/lib/isc/include/isc/base64.h index 8eba7826ab6..a8e93bb6504 100644 --- a/lib/isc/include/isc/base64.h +++ b/lib/isc/include/isc/base64.h @@ -72,8 +72,11 @@ isc_base64_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length); * `target`. If 'length' is non-negative, it is the expected number of * encoded octets to convert. * - * If 'length' is -1 then 0 or more encoded octets are expected. - * If 'length' is -2 then 1 or more encoded octets are expected. + * If 'length' is isc_zero_or_more then 0 or more encoded octets are + * expected. + * + * If 'length' is isc_one_or_more then 1 or more encoded octets are + * expected. * * Returns: *\li #ISC_R_BADBASE64 -- invalid base64 encoding. diff --git a/lib/isc/include/isc/hex.h b/lib/isc/include/isc/hex.h index 76675c7fad9..ebe042cb74e 100644 --- a/lib/isc/include/isc/hex.h +++ b/lib/isc/include/isc/hex.h @@ -143,8 +143,11 @@ isc_hex_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length); * `target`. If 'length' is non-negative, it is the expected number of * encoded octets to convert. * - * If 'length' is -1 then 0 or more encoded octets are expected. - * If 'length' is -2 then 1 or more encoded octets are expected. + * If 'length' is isc_zero_or_more then 0 or more encoded octets are + * expected. + * + * If 'length' is isc_one_or_more then 1 or more encoded octets are + * expected. * * Returns: *\li #ISC_R_BADHEX -- invalid hex encoding diff --git a/lib/isc/include/isc/types.h b/lib/isc/include/isc/types.h index 3ab5f5d7717..74ba9ff946d 100644 --- a/lib/isc/include/isc/types.h +++ b/lib/isc/include/isc/types.h @@ -80,6 +80,12 @@ typedef struct isc_nm_http_endpoints isc_nm_http_endpoints_t; /*%< HTTP endpoints set */ #endif /* HAVE_LIBNGHTTP2 */ +/*% Used by isc_base64 and isc_hex for expected lower bound */ +enum { + isc_zero_or_more = -1, + isc_one_or_more = -2, +}; + /*% Statistics formats (text file or XML) */ typedef enum { isc_statsformat_file,