Skip to content

Commit

Permalink
fix for sslecho in demos echoing garbage #18165
Browse files Browse the repository at this point in the history
- 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 #18177)

(cherry picked from commit 3c0e8bc)
  • Loading branch information
artlog authored and t8m committed Nov 21, 2022
1 parent 0c6bca7 commit a06a72f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions demos/sslecho/main.c
Expand Up @@ -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];
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");

Expand Down

0 comments on commit a06a72f

Please sign in to comment.