aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2017-04-21 11:12:10 +0200
committerAndreas Schneider <asn@cryptomilk.org>2017-04-21 11:12:10 +0200
commitc78c6c654222d8049d48ffb3f36f185e91f76789 (patch)
tree9465da08d95fc2d02f456e3c81765a41ddd660cc
parentd5d8349224ef0f2ef82d175b2fcac91d769eae3b (diff)
downloadlibssh-c78c6c654222d8049d48ffb3f36f185e91f76789.tar.gz
libssh-c78c6c654222d8049d48ffb3f36f185e91f76789.tar.xz
libssh-c78c6c654222d8049d48ffb3f36f185e91f76789.zip
messages: Do not leak memory if answered had been allocated previously
BUG: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=1184 Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--src/messages.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/messages.c b/src/messages.c
index 8568cbf8..199ec4cd 100644
--- a/src/messages.c
+++ b/src/messages.c
@@ -988,7 +988,9 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_info_response){
" mismatch: p=%u a=%u", session->kbdint->nprompts, nanswers);
}
session->kbdint->nanswers = nanswers;
- session->kbdint->answers = malloc(nanswers * sizeof(char *));
+
+ SAFE_FREE(session->kbdint->answers);
+ session->kbdint->answers = calloc(1, nanswers * sizeof(char *));
if (session->kbdint->answers == NULL) {
session->kbdint->nanswers = 0;
ssh_set_error_oom(session);
@@ -997,7 +999,6 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_info_response){
goto error;
}
- memset(session->kbdint->answers, 0, nanswers * sizeof(char *));
for (i = 0; i < nanswers; i++) {
tmp = ssh_buffer_get_ssh_string(packet);