summaryrefslogtreecommitdiffstats
path: root/crypto/pem
diff options
context:
space:
mode:
authorPauli <paul.dale@oracle.com>2017-07-07 10:17:59 +1000
committerPauli <paul.dale@oracle.com>2017-07-07 13:37:06 +1000
commit86ba26c80a49aee3c588d286d91eb3843529f7e2 (patch)
tree36b8d1ee9730e7cd1cd95e976fd2d7b5816441f0 /crypto/pem
parentb4df712acad6514efc8753d9aa8b5fe3a721c811 (diff)
Address potential buffer overflows.
Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3878)
Diffstat (limited to 'crypto/pem')
-rw-r--r--crypto/pem/pem_lib.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/crypto/pem/pem_lib.c b/crypto/pem/pem_lib.c
index 7e5e3747b0..aacdad9e63 100644
--- a/crypto/pem/pem_lib.c
+++ b/crypto/pem/pem_lib.c
@@ -1,5 +1,5 @@
/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -71,6 +71,7 @@ int PEM_def_callback(char *buf, int num, int w, void *key)
void PEM_proc_type(char *buf, int type)
{
const char *str;
+ char *p = buf + strlen(buf);
if (type == PEM_TYPE_ENCRYPTED)
str = "ENCRYPTED";
@@ -81,27 +82,29 @@ void PEM_proc_type(char *buf, int type)
else
str = "BAD-TYPE";
- strcat(buf, "Proc-Type: 4,");
- strcat(buf, str);
- strcat(buf, "\n");
+ BIO_snprintf(p, PEM_BUFSIZE - (size_t)(p - buf), "Proc-Type: 4,%s\n", str);
}
void PEM_dek_info(char *buf, const char *type, int len, char *str)
{
- static const unsigned char map[17] = "0123456789ABCDEF";
long i;
- int j;
-
- strcat(buf, "DEK-Info: ");
- strcat(buf, type);
- strcat(buf, ",");
- j = strlen(buf);
- for (i = 0; i < len; i++) {
- buf[j + i * 2] = map[(str[i] >> 4) & 0x0f];
- buf[j + i * 2 + 1] = map[(str[i]) & 0x0f];
- }
- buf[j + i * 2] = '\n';
- buf[j + i * 2 + 1] = '\0';
+ char *p = buf + strlen(buf);
+ int j = PEM_BUFSIZE - (size_t)(p - buf), n;
+
+ n = BIO_snprintf(p, j, "DEK-Info: %s,", type);
+ if (n > 0) {
+ j -= n;
+ p += n;
+ for (i = 0; i < len; i++) {
+ n = BIO_snprintf(p, j, "%02X", 0xff & str[i]);
+ if (n <= 0)
+ return;
+ j -= n;
+ p += n;
+ }
+ if (j > 1)
+ strcpy(p, "\n");
+ }
}
#ifndef OPENSSL_NO_STDIO