]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add enum for use with isc_base64_tobuffer and isc_hex_tobuffer
authorMark Andrews <marka@isc.org>
Fri, 23 Jan 2026 03:53:18 +0000 (14:53 +1100)
committerMark Andrews <marka@isc.org>
Tue, 27 Jan 2026 12:57:34 +0000 (23:57 +1100)
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.

lib/isc/base64.c
lib/isc/hex.c
lib/isc/include/isc/base64.h
lib/isc/include/isc/hex.h
lib/isc/include/isc/types.h

index ba4ee7148fddc461706757663579c1acfcabd17e..3b2d19af7062a6a9fb89b6387b1104731da56419 100644 (file)
@@ -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') {
index 7f63df7aa64634288e7c1b7167222e907b77b399..e063d2fc2b36251f24779b236df1a579d439972f 100644 (file)
@@ -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') {
index 8eba7826ab6acf5094794f1ec9fa081cae552d06..a8e93bb6504a797ad0a5dbe52d5cb90e087dce39 100644 (file)
@@ -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.
index 76675c7fad991f4d1c1bead90225a3328a983623..ebe042cb74e824a7871c13dd348ddc07375272f7 100644 (file)
@@ -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
index 3ab5f5d771761b2fadc6498ef27f84c18923d64d..74ba9ff946d25f65c65d46dc4ea5324c4a5ebb41 100644 (file)
@@ -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,