]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
resolv: Add internal __res_binary_hnok function
authorFlorian Weimer <fweimer@redhat.com>
Tue, 30 Aug 2022 08:02:49 +0000 (10:02 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Tue, 30 Aug 2022 08:02:49 +0000 (10:02 +0200)
During package parsing, only the binary representation is available,
and it is convenient to check that directly for conformance with host
name requirements.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
include/resolv.h
resolv/res-name-checking.c

index 3590b6f496d47710d08e0a8e37bb597853097f6f..4dbbac3800b7ef302c8c93eb1cb3855c5a1c3d83 100644 (file)
@@ -70,5 +70,8 @@ libc_hidden_proto (__libc_res_nameinquery)
 extern __typeof (__res_queriesmatch) __libc_res_queriesmatch;
 libc_hidden_proto (__libc_res_queriesmatch)
 
+/* Variant of res_hnok which operates on binary (but uncompressed) names.  */
+bool __res_binary_hnok (const unsigned char *dn) attribute_hidden;
+
 # endif /* _RESOLV_H_ && !_ISOMAC */
 #endif
index 07a412d8ff4da7423393325cc4627a9b2398d8bc..213edceaf3dc677bcfe56dd33d95fe8aa72a7152 100644 (file)
@@ -138,6 +138,12 @@ binary_leading_dash (const unsigned char *dn)
   return dn[0] > 0 && dn[1] == '-';
 }
 
+bool
+__res_binary_hnok (const unsigned char *dn)
+{
+  return !binary_leading_dash (dn) && binary_hnok (dn);
+}
+
 /* Return 1 if res_hnok is a valid host name.  Labels must only
    contain [0-9a-zA-Z_-] characters, and the name must not start with
    a '-'.  The latter is to avoid confusion with program options.  */
@@ -145,11 +151,9 @@ int
 ___res_hnok (const char *dn)
 {
   unsigned char buf[NS_MAXCDNAME];
-  if (!printable_string (dn)
-      || __ns_name_pton (dn, buf, sizeof (buf)) < 0
-      || binary_leading_dash (buf))
-    return 0;
-  return binary_hnok (buf);
+  return (printable_string (dn)
+         && __ns_name_pton (dn, buf, sizeof (buf)) >= 0
+         && __res_binary_hnok (buf));
 }
 versioned_symbol (libc, ___res_hnok, res_hnok, GLIBC_2_34);
 versioned_symbol (libc, ___res_hnok, __libc_res_hnok, GLIBC_PRIVATE);