]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
util/base64: decode_data_blob_talloc catches talloc error
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Tue, 6 Apr 2021 18:53:16 +0000 (06:53 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 12 May 2022 02:22:35 +0000 (02:22 +0000)
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/util/base64.c

index e9906f16e478ea59fd1c04c7e5a43f2c39814b79..842c22ffdb04d1838d2a62a5d82641e57752ee4d 100644 (file)
 static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
 /**
- * Decode a base64 string into a DATA_BLOB - simple and slow algorithm
+ * Decode a base64 string into a DATA_BLOB - simple and slow algorithm.
+ *
+ * A DATA_BLOB like {.data = NULL, length = 0} indicates memory error.
+ *
+ * Decoding stops at the first invalid character.
  **/
 _PUBLIC_ DATA_BLOB base64_decode_data_blob_talloc(TALLOC_CTX *mem_ctx, const char *s)
 {
@@ -37,6 +41,11 @@ _PUBLIC_ DATA_BLOB base64_decode_data_blob_talloc(TALLOC_CTX *mem_ctx, const cha
        unsigned char *d = decoded.data;
        char *p;
 
+       if (decoded.data == NULL) {
+               decoded.length = 0;
+               return decoded;
+       }
+
        n=i=0;
 
        while (*s && (p=strchr(b64,*s))) {