s3/lib: use talloc_alpha_strcpy() in set_remote_machine_name()
authorRalph Boehme <slow@samba.org>
Fri, 17 Jan 2020 18:30:01 +0000 (19:30 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 6 Feb 2020 10:17:43 +0000 (10:17 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/lib/substitute.c

index ee079dc229d2ea6f37d42c0c1c632843b4708863..acddb7dd16553e6b57a0ced5178686ae7c943476 100644 (file)
@@ -94,7 +94,6 @@ bool set_remote_machine_name(const char *remote_name, bool perm)
 {
        static bool already_perm = False;
        char *tmp_remote_machine;
-       size_t len;
 
        if (already_perm) {
                return true;
@@ -107,16 +106,12 @@ bool set_remote_machine_name(const char *remote_name, bool perm)
        trim_char(tmp_remote_machine,' ',' ');
 
        TALLOC_FREE(remote_machine);
-       len = strlen(tmp_remote_machine);
-       remote_machine = (char *)TALLOC_ZERO(NULL, len+1);
-       if (!remote_machine) {
-               TALLOC_FREE(tmp_remote_machine);
+       remote_machine = talloc_alpha_strcpy(NULL,
+                                            tmp_remote_machine,
+                                            SAFE_NETBIOS_CHARS);
+       if (remote_machine == NULL) {
                return false;
        }
-
-       /* alpha_strcpy includes the space for the terminating nul. */
-       alpha_strcpy(remote_machine,tmp_remote_machine,
-                       SAFE_NETBIOS_CHARS,len+1);
        if (!strlower_m(remote_machine)) {
                TALLOC_FREE(tmp_remote_machine);
                return false;