diff --git a/lib/isc/base64.c b/lib/isc/base64.c index ba4ee7148f..3b2d19af70 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 7f63df7aa6..e063d2fc2b 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 8eba7826ab..a8e93bb650 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 76675c7fad..ebe042cb74 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 3ab5f5d771..74ba9ff946 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,