summaryrefslogtreecommitdiffstats
path: root/demos
diff options
context:
space:
mode:
authorphilippe lhardy <pl@artisanlogiciel.net>2022-04-25 19:42:16 +0200
committerPauli <pauli@openssl.org>2022-05-06 11:16:21 +1000
commit3c0e8bc4a797d29b2152aebc6e687ddfa941160b (patch)
treec05384f90061de530ffc5c425dbe34995db4922a /demos
parent50d1d92de9a4cf62723a3c1ea2f39501feea7d6e (diff)
fix for sslecho in demos echoing garbage #18165
- getline does set &txbufp content at return, make sure it can be done. - fixes warning 'passing argument 1 of ‘getline’ from incompatible pointer type' - remove OPENSSL_free on non allocated fixed size array - fixes 'free(): invalid pointer' Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18177)
Diffstat (limited to 'demos')
-rw-r--r--demos/sslecho/main.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/demos/sslecho/main.c b/demos/sslecho/main.c
index c6f087c56f..588158e749 100644
--- a/demos/sslecho/main.c
+++ b/demos/sslecho/main.c
@@ -137,8 +137,9 @@ int main(int argc, char **argv)
int server_skt = -1;
int client_skt = -1;
- char txbuf[128];
- size_t txcap = sizeof(txbuf);
+ /* used by getline relying on realloc, can't be statically allocated */
+ char *txbuf = NULL;
+ size_t txcap = 0;
int txlen;
char rxbuf[128];
@@ -286,11 +287,14 @@ int main(int argc, char **argv)
while (true) {
/* Get a line of input */
txlen = getline(&txbuf, &txcap, stdin);
+ /* Exit loop on error */
+ if (txlen < 0 || txbuf == NULL) {
+ break;
+ }
/* Exit loop if just a carriage return */
if (txbuf[0] == '\n') {
break;
}
-
/* Send it to the server */
if ((result = SSL_write(ssl, txbuf, txlen)) <= 0) {
printf("Server closed connection\n");
@@ -331,8 +335,8 @@ int main(int argc, char **argv)
if (server_skt != -1)
close(server_skt);
- OPENSSL_free(txbuf);
- OPENSSL_free(rxbuf);
+ if (txbuf != NULL && txcap > 0)
+ free(txbuf);
printf("sslecho exiting\n");