torture4: Use strlcpy() with size check instead of snprintf()
authorVolker Lendecke <vl@samba.org>
Mon, 10 Feb 2020 20:45:00 +0000 (21:45 +0100)
committerMartin Schwenke <martins@samba.org>
Wed, 19 Feb 2020 09:38:39 +0000 (09:38 +0000)
It's just test code, but we should give good examples where possible

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Martin Schwenke <martin@meltin.net>
source4/torture/libsmbclient/libsmbclient.c

index 586e17724256356f9adb1c5ae5137149d5be9f2b..d29de06a4948ecd82842ab7b6327ebbea4db7153 100644 (file)
@@ -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();
+               }
        }
 };