From 8dd0fd4acbcf489f4040da6db6d211a598ac7b2c Mon Sep 17 00:00:00 2001 From: defanor Date: Mon, 25 Jan 2021 23:52:54 +0300 Subject: Use getline(3) for examples/basic.c password reading It's not great, but a little less awkward than gets(3). May be nicer to use pinentry, or at least to disable echoing, but those come with additional dependencies, which are undesirable for a basic example. --- examples/basic.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/basic.c b/examples/basic.c index cd3d6e3..123225a 100644 --- a/examples/basic.c +++ b/examples/basic.c @@ -30,10 +30,17 @@ void my_logger (rexmpp_t *s, int priority, const char *fmt, va_list args) { initial JID. */ int my_sasl_property_cb (rexmpp_t *s, Gsasl_property prop) { if (prop == GSASL_PASSWORD) { - char buf[4096]; + char *buf = NULL; + size_t buf_len = 4096; printf("password: "); - gets(buf); - gsasl_property_set (s->sasl_session, GSASL_PASSWORD, buf); + getline(&buf, &buf_len, stdin); + if (buf != NULL) { + if (buf[strlen(buf) - 1] == '\n') { + buf[strlen(buf) - 1] = '\0'; + } + gsasl_property_set (s->sasl_session, GSASL_PASSWORD, buf); + free(buf); + } return GSASL_OK; } if (prop == GSASL_AUTHID) { -- cgit v1.2.3