]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Fix leak in KDC NDR encoding
authorGreg Hudson <ghudson@mit.edu>
Tue, 5 Mar 2024 22:38:49 +0000 (17:38 -0500)
committerGreg Hudson <ghudson@mit.edu>
Tue, 19 Mar 2024 01:32:27 +0000 (21:32 -0400)
If the KDC tries to encode a principal containing encode invalid UTF-8
sequences for inclusion in a PAC delegation info buffer, it will leak
a small amount of memory in enc_wchar_pointer() before failing.  Fix
the leak.

ticket: 9115 (new)
tags: pullup
target_version: 1.21-next

src/kdc/ndr.c

index 48395abe52698f5fe6b516e066ab188b0404ab01..d438408ee274a7e309318c9905060bd76b9c1ed5 100644 (file)
@@ -96,14 +96,13 @@ enc_wchar_pointer(const char *utf8, struct encoded_wchars *encoded_out)
     size_t utf16len, num_wchars;
     uint8_t *utf16;
 
-    k5_buf_init_dynamic(&b);
-
     ret = k5_utf8_to_utf16le(utf8, &utf16, &utf16len);
     if (ret)
         return ret;
 
     num_wchars = utf16len / 2;
 
+    k5_buf_init_dynamic(&b);
     k5_buf_add_uint32_le(&b, num_wchars + 1);
     k5_buf_add_uint32_le(&b, 0);
     k5_buf_add_uint32_le(&b, num_wchars);