datasets: explicitly errors on too long string

Also avoids stack allocation

Ticket: 8110
(cherry picked from commit 0eff242137)
pull/14600/head
Philippe Antoine 5 months ago committed by Shivani Bhardwaj
parent 01caba469a
commit 32609e6896

@ -49,12 +49,13 @@ int StringAsBase64(const void *s, char *out, size_t out_size)
const StringType *str = s;
unsigned long len = Base64EncodeBufferSize(str->len);
uint8_t encoded_data[len];
if (Base64Encode((unsigned char *)str->ptr, str->len,
encoded_data, &len) != SC_BASE64_OK)
if (len + 2 > out_size) {
// linefeed and final zero
return 0;
}
if (Base64Encode((unsigned char *)str->ptr, str->len, (uint8_t *)out, &len) != SC_BASE64_OK)
return 0;
strlcpy(out, (const char *)encoded_data, out_size);
strlcat(out, "\n", out_size);
return strlen(out);
}

Loading…
Cancel
Save