summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Horman <nhorman@openssl.org>2024-04-07 08:42:51 -0400
committerNeil Horman <nhorman@openssl.org>2024-04-12 08:02:20 -0400
commit793a4056ad94e5f3076b7988ddee3af2aece09f2 (patch)
tree52c286b7e5943c7c4e1b10a0de079c861f767b82
parent4ad6e549fadde344cbbe9d7f4aafb4d3a2a67094 (diff)
Replace getline with fgets in sslecho demo
Windows doesn't support getline, so we need to use fgets here Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com> Reviewed-by: Tim Hudson <tjh@openssl.org> Reviewed-by: Paul Dale <ppzgs1@gmail.com> Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> (Merged from https://github.com/openssl/openssl/pull/24047)
-rw-r--r--demos/sslecho/main.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/demos/sslecho/main.c b/demos/sslecho/main.c
index 4973902cf5..41d4418c3f 100644
--- a/demos/sslecho/main.c
+++ b/demos/sslecho/main.c
@@ -133,6 +133,7 @@ static void usage(void)
exit(EXIT_FAILURE);
}
+#define BUFFERSIZE 1024
int main(int argc, char **argv)
{
bool isServer;
@@ -144,10 +145,9 @@ int main(int argc, char **argv)
int server_skt = -1;
int client_skt = -1;
- /* used by getline relying on realloc, can't be statically allocated */
- char *txbuf = NULL;
- size_t txcap = 0;
- int txlen;
+ /* used by fgets */
+ char buffer[BUFFERSIZE];
+ char *txbuf;
char rxbuf[128];
size_t rxcap = sizeof(rxbuf);
@@ -309,9 +309,11 @@ int main(int argc, char **argv)
/* Loop to send input from keyboard */
while (true) {
/* Get a line of input */
- txlen = getline(&txbuf, &txcap, stdin);
+ memset(buffer, 0, BUFFERSIZE);
+ txbuf = fgets(buffer, BUFFERSIZE, stdin);
+
/* Exit loop on error */
- if (txlen < 0 || txbuf == NULL) {
+ if (txbuf == NULL) {
break;
}
/* Exit loop if just a carriage return */
@@ -319,7 +321,7 @@ int main(int argc, char **argv)
break;
}
/* Send it to the server */
- if ((result = SSL_write(ssl, txbuf, txlen)) <= 0) {
+ if ((result = SSL_write(ssl, txbuf, strlen(txbuf))) <= 0) {
printf("Server closed connection\n");
ERR_print_errors_fp(stderr);
break;
@@ -358,9 +360,6 @@ exit:
if (server_skt != -1)
close(server_skt);
- if (txbuf != NULL && txcap > 0)
- free(txbuf);
-
printf("sslecho exiting\n");
return EXIT_SUCCESS;