#include <stdio.h>
#include <string.h>
#include "internal/cryptlib.h"
+#include "internal/sizes.h"
#include "crypto/asn1.h"
#include <openssl/crypto.h>
#include <openssl/x509.h>
if (lflags & ASN1_STRFLGS_SHOW_TYPE) {
const char *tagname;
+
tagname = ASN1_tag2str(type);
- outlen += strlen(tagname);
+ /* We can directly cast here as tagname will never be too large. */
+ outlen += (int)strlen(tagname);
if (!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1))
return -1;
outlen++;
if (type == -1) {
len = do_dump(lflags, io_ch, arg, str);
- if (len < 0)
+ if (len < 0 || len > INT_MAX - outlen)
return -1;
outlen += len;
return outlen;
}
len = do_buf(str->data, str->length, type, flags, "es, io_ch, NULL);
- if (len < 0)
+ if (len < 0 || len > INT_MAX - 2 - outlen)
return -1;
outlen += len;
if (quotes)