From: Douglas Bagnall Date: Tue, 6 Apr 2021 18:53:16 +0000 (+1200) Subject: util/base64: decode_data_blob_talloc catches talloc error X-Git-Tag: talloc-2.3.4~185 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eddefe3c62a537ed0b94d3d5f4ab58ae10d00828;p=thirdparty%2Fsamba.git util/base64: decode_data_blob_talloc catches talloc error Signed-off-by: Douglas Bagnall Reviewed-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- diff --git a/lib/util/base64.c b/lib/util/base64.c index e9906f16e47..842c22ffdb0 100644 --- a/lib/util/base64.c +++ b/lib/util/base64.c @@ -28,7 +28,11 @@ 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))) {