Skip to content

Commit 75f72c2

Browse files
committed
BUG/MEDIUM: resolvers: Fix test on dn label size in resolv_dn_label_to_str()
In resolv_dn_label_to_str(), size for a dn label was stored into an integer from a signed char without a cast to unsigned. So dn label with a size of 128 bytes or more become negative, skipping this way the copy loop and desynchronizing input vs output. In addition, the size of the destination string was only checked at the begining, against the dn string length. But it must also be checked for every dn label, to be sure. The dn string can be forged to copied more bytes than expected. This patch must be backported to all stable versions.
1 parent 1ed4ef6 commit 75f72c2

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/resolvers.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1855,7 +1855,12 @@ int resolv_dn_label_to_str(const char *dn, int dn_len, char *str, int str_len)
18551855

18561856
ptr = str;
18571857
for (i = 0; i < dn_len; ++i) {
1858-
sz = dn[i];
1858+
sz = (unsigned char)dn[i];
1859+
1860+
/* Check str_len adding 1 for the dot if (i!=0) */
1861+
if (str_len < sz+i+(!!i))
1862+
return -1;
1863+
18591864
if (i)
18601865
*ptr++ = '.';
18611866
/* copy the string at i+1 to lower case */

0 commit comments

Comments
 (0)