]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ndr:dns: introduce and use MAX_COMP_LEN
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 19 Feb 2025 02:44:34 +0000 (15:44 +1300)
committerDouglas Bagnall <dbagnall@samba.org>
Thu, 16 Apr 2026 00:54:44 +0000 (00:54 +0000)
it means 63 or 0x3f, and is the maximum length of a DNS/NBT component.

We also simplify an error message that was fond of long hex
representations of small numbers.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14378

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
librpc/ndr/ndr_dns_utils.c

index 9b603b364f13f542c96d771cf7fda39a78bcc5f3..68d7800173ee761cd21162b89a52aa790aebd03b 100644 (file)
@@ -7,7 +7,7 @@
    plenty.
  */
 #define MAX_COMPONENTS 128
-
+#define MAX_COMP_LEN    63
 
 
 /*
@@ -87,7 +87,7 @@ static enum ndr_err_code ndr_pull_component(struct ndr_pull *ndr,
                                              err_name, (len &0xC));
                }
                if (*offset + len + 1 > ndr->data_size ||
-                   len > 63 /* impossible!, but we live in fear */ ) {
+                   len > MAX_COMP_LEN /* impossible!, but we live in fear */ ) {
                        return ndr_pull_error(ndr, NDR_ERR_STRING,
                                              "BAD %s NAME component, "\
                                              "length too long",
@@ -272,12 +272,11 @@ enum ndr_err_code ndr_push_dns_string_list(struct ndr_push *ndr,
                complen = strcspn(s, ".");
 
                /* the length must fit into 6 bits (i.e. <= 63) */
-               if (complen > 0x3F) {
+               if (complen > MAX_COMP_LEN) {
                        return ndr_push_error(ndr, NDR_ERR_STRING,
-                                             "component length %zu[%08zX] > " \
-                                             "0x0000003F",
+                                             "component length %zu > %u",
                                              complen,
-                                             complen);
+                                             MAX_COMP_LEN);
                }
 
                if (complen == 0 && s[complen] == '.') {