From b058c6d3ed1bcc28ac02265d345cbda9a1df66a4 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 10 Feb 2020 21:45:00 +0100 Subject: torture4: Use strlcpy() with size check instead of snprintf() It's just test code, but we should give good examples where possible Signed-off-by: Volker Lendecke Reviewed-by: Martin Schwenke --- source4/torture/libsmbclient/libsmbclient.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/source4/torture/libsmbclient/libsmbclient.c b/source4/torture/libsmbclient/libsmbclient.c index 586e1772425..d29de06a494 100644 --- a/source4/torture/libsmbclient/libsmbclient.c +++ b/source4/torture/libsmbclient/libsmbclient.c @@ -53,17 +53,27 @@ static void auth_callback(const char *srv, cli_credentials_get_username(popt_get_cmdline_credentials()); const char *password = cli_credentials_get_password(popt_get_cmdline_credentials()); + ssize_t ret; if (workgroup != NULL) { - snprintf(wg, wglen, "%s", workgroup); + ret = strlcpy(wg, workgroup, wglen); + if (ret >= wglen) { + abort(); + } } if (username != NULL) { - snprintf(un, unlen, "%s", username); + ret = strlcpy(un, username, unlen); + if (ret >= unlen) { + abort(); + } } if (password != NULL) { - snprintf(pw, pwlen, "%s", password); + ret = strlcpy(pw, password, pwlen); + if (ret >= pwlen) { + abort(); + } } }; -- cgit v1.2.1