From 29b66b00b7a9f4142fb200b502b840b869fc3596 Mon Sep 17 00:00:00 2001 From: Polshakov Dmitry Date: Sun, 10 Apr 2016 00:59:20 +0300 Subject: [PATCH] Fix several undefined behaviors --- hydra-imap.c | 6 +++++- hydra-nntp.c | 11 +++++++++-- hydra-pop3.c | 10 ++++++++-- hydra-smtp.c | 12 ++++++++++-- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/hydra-imap.c b/hydra-imap.c index 6f71c71..32d6fad 100644 --- a/hydra-imap.c +++ b/hydra-imap.c @@ -177,7 +177,11 @@ int start_imap(int s, char *ip, int port, unsigned char options, char *miscptr, break; } hydra_tobase64((unsigned char *) buffer, strlen(buffer), sizeof(buffer)); - sprintf(buffer, "%.250s\r\n", buffer); + + char tmp_buffer[sizeof(buffer)]; + sprintf(tmp_buffer, "%.250s\r\n", buffer); + strcpy(buffer, tmp_buffer); + free(preplogin); } break; diff --git a/hydra-nntp.c b/hydra-nntp.c index 3ea3840..f4c8e8f 100644 --- a/hydra-nntp.c +++ b/hydra-nntp.c @@ -113,7 +113,11 @@ int start_nntp(int s, char *ip, int port, unsigned char options, char *miscptr, memset(buffer, 0, sizeof(buffer)); sasl_plain(buffer, login, pass); - sprintf(buffer, "%.250s\r\n", buffer); + + char tmp_buffer[sizeof(buffer)]; + sprintf(tmp_buffer, "%.250s\r\n", buffer); + strcpy(buffer, tmp_buffer); + break; #ifdef LIBOPENSSL case AUTH_CRAMMD5:{ @@ -147,7 +151,10 @@ int start_nntp(int s, char *ip, int port, unsigned char options, char *miscptr, sprintf(buffer, "%s %.250s", preplogin, buffer2); hydra_tobase64((unsigned char *) buffer, strlen(buffer), sizeof(buffer)); - sprintf(buffer, "%.250s\r\n", buffer); + + char tmp_buffer[sizeof(buffer)]; + sprintf(tmp_buffer, "%.250s\r\n", buffer); + strcpy(buffer, tmp_buffer); free(preplogin); } break; diff --git a/hydra-pop3.c b/hydra-pop3.c index 52bf6e8..d232df9 100644 --- a/hydra-pop3.c +++ b/hydra-pop3.c @@ -205,7 +205,10 @@ int start_pop3(int s, char *ip, int port, unsigned char options, char *miscptr, memset(buffer, 0, sizeof(buffer)); sasl_plain(buffer, login, pass); - sprintf(buffer, "%.250s\r\n", buffer); + + char tmp_buffer[sizeof(buffer)]; + sprintf(tmp_buffer, "%.250s\r\n", buffer); + strcpy(buffer, tmp_buffer); } break; @@ -279,7 +282,10 @@ int start_pop3(int s, char *ip, int port, unsigned char options, char *miscptr, break; } hydra_tobase64((unsigned char *) buffer, strlen(buffer), sizeof(buffer)); - sprintf(buffer, "%.250s\r\n", buffer); + + char tmp_buffer[sizeof(buffer)]; + sprintf(tmp_buffer, "%.250s\r\n", buffer); + strcpy(buffer, tmp_buffer); free(preplogin); } break; diff --git a/hydra-smtp.c b/hydra-smtp.c index d268fbf..faa5186 100644 --- a/hydra-smtp.c +++ b/hydra-smtp.c @@ -69,7 +69,11 @@ int start_smtp(int s, char *ip, int port, unsigned char options, char *miscptr, memset(buffer, 0, sizeof(buffer)); sasl_plain(buffer, login, pass); - sprintf(buffer, "%.250s\r\n", buffer); + + char tmp_buffer[sizeof(buffer)]; + sprintf(tmp_buffer, "%.250s\r\n", buffer); + strcpy(buffer, tmp_buffer); + break; #ifdef LIBOPENSSL @@ -103,7 +107,11 @@ int start_smtp(int s, char *ip, int port, unsigned char options, char *miscptr, sprintf(buffer, "%s %.250s", preplogin, buffer2); hydra_tobase64((unsigned char *) buffer, strlen(buffer), sizeof(buffer)); - sprintf(buffer, "%.250s\r\n", buffer); + + char tmp_buffer[sizeof(buffer)]; + sprintf(tmp_buffer, "%.250s\r\n", buffer); + strcpy(buffer, tmp_buffer); + free(preplogin); } break;