pubkey_show: allocate buffer to fit any-size result

The loop condition was wrong so keys larger than 340 bits would overflow
the local stack-based buffer.
This commit is contained in:
Daniel Stenberg
2011-01-01 15:33:57 +01:00
parent cd045e24a0
commit ae29142198

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -1840,21 +1840,25 @@ static void pubkey_show(struct SessionHandle *data,
unsigned char *raw, unsigned char *raw,
int len) int len)
{ {
char buffer[1024]; size_t left;
size_t left = sizeof(buffer);
int i; int i;
char *ptr=buffer;
char namebuf[32]; char namebuf[32];
char *buffer;
snprintf(namebuf, sizeof(namebuf), "%s(%s)", type, name); left = sizeof(len*3 + 1);
buffer = malloc(left);
for(i=0; i< len; i++) { if(buffer) {
snprintf(ptr, left, "%02x:", raw[i]); char *ptr=buffer;
ptr += 3; snprintf(namebuf, sizeof(namebuf), "%s(%s)", type, name);
left -= 3; for(i=0; i< len; i++) {
snprintf(ptr, left, "%02x:", raw[i]);
ptr += 3;
left -= 3;
}
infof(data, " %s: %s\n", namebuf, buffer);
push_certinfo(data, num, namebuf, buffer);
free(buffer);
} }
infof(data, " %s: %s\n", namebuf, buffer);
push_certinfo(data, num, namebuf, buffer);
} }
#define print_pubkey_BN(_type, _name, _num) \ #define print_pubkey_BN(_type, _name, _num) \