Skip to content

Commit

Permalink
resolv: Add internal __res_binary_hnok function
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
fweimer-rh committed Aug 30, 2022
1 parent 87aa98a commit c79327b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions include/resolv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 9 additions & 5 deletions resolv/res-name-checking.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,22 @@ 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. */
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);
Expand Down

0 comments on commit c79327b

Please sign in to comment.