s3/lib: use talloc_alpha_strcpy() in set_local_machine_name()
authorRalph Boehme <slow@samba.org>
Fri, 17 Jan 2020 18:28:54 +0000 (19:28 +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 b5e08e0aa55d729510e5eb4920e5afa4bc6a92d2..ee079dc229d2ea6f37d42c0c1c632843b4708863 100644 (file)
@@ -44,7 +44,6 @@ bool set_local_machine_name(const char *local_name, bool perm)
 {
        static bool already_perm = false;
        char *tmp_local_machine = NULL;
-       size_t len;
 
        if (already_perm) {
                return true;
@@ -57,15 +56,12 @@ bool set_local_machine_name(const char *local_name, bool perm)
        trim_char(tmp_local_machine,' ',' ');
 
        TALLOC_FREE(local_machine);
-       len = strlen(tmp_local_machine);
-       local_machine = (char *)TALLOC_ZERO(NULL, len+1);
-       if (!local_machine) {
-               TALLOC_FREE(tmp_local_machine);
+       local_machine = talloc_alpha_strcpy(NULL,
+                                           tmp_local_machine,
+                                           SAFE_NETBIOS_CHARS);
+       if (local_machine == NULL) {
                return false;
        }
-       /* alpha_strcpy includes the space for the terminating nul. */
-       alpha_strcpy(local_machine,tmp_local_machine,
-                       SAFE_NETBIOS_CHARS,len+1);
        if (!strlower_m(local_machine)) {
                TALLOC_FREE(tmp_local_machine);
                return false;