Jelajahi Sumber

smb_ntlm: Do not append empty buffers

This clarifies the code, and prevents calling memcpy with a NULL src,
which is technically an undefined behavior
Hugo Beauzée-Luyssen 8 tahun lalu
induk
melakukan
03a571f346
1 mengubah file dengan 15 tambahan dan 9 penghapusan
  1. 15 9
      src/smb_ntlm.c

+ 15 - 9
src/smb_ntlm.c

@@ -386,15 +386,21 @@ void        smb_ntlmssp_response(uint64_t srv_challenge, uint64_t srv_ts,
         __AUTH_APPEND(lm, lm2, 24, cursor)
         __AUTH_APPEND(ntlm, ntlm2, blob_size + 16, cursor)
     }
-    utf_sz = smb_to_utf16(domain, strlen(domain), &utf);
-    __AUTH_APPEND(domain, utf, utf_sz, cursor)
-    free(utf);
-    utf_sz = smb_to_utf16(user, strlen(user), &utf);
-    __AUTH_APPEND(user, utf, utf_sz, cursor)
-    free(utf);
-    utf_sz = smb_to_utf16(host, strlen(host), &utf);
-    __AUTH_APPEND(host, utf, utf_sz, cursor)
-    free(utf);
+    if (*domain) {
+        utf_sz = smb_to_utf16(domain, strlen(domain), &utf);
+        __AUTH_APPEND(domain, utf, utf_sz, cursor)
+        free(utf);
+    }
+    if (*user) {
+        utf_sz = smb_to_utf16(user, strlen(user), &utf);
+        __AUTH_APPEND(user, utf, utf_sz, cursor)
+        free(utf);
+    }
+    if (*host) {
+        utf_sz = smb_to_utf16(host, strlen(host), &utf);
+        __AUTH_APPEND(host, utf, utf_sz, cursor)
+        free(utf);
+    }
 
     __AUTH_APPEND(session_key, &xkey_crypt, 16, cursor)