commit cb5be5c38471eec19e519ace0bc569176317ea92
Author: Matthias Andree <matthias.andree@gmx.de>
Date:   Sat Jun 27 00:35:13 2026 +0200

    SMB/NTLM: check remaining buffer capacity before memcpy
    
    The AddBytes macro now checks if the buffer has sufficient
    remaining capacity.  If not, "goto err_buffer_full", which
    every function using the AddBytes macro directly or indirectly
    through AddString or AddUnicodeString, would have to provide
    as label.

diff --git a/smbutil.c b/smbutil.c
index 66f5d565..c8751893 100644
--- a/smbutil.c
+++ b/smbutil.c
@@ -31,6 +31,8 @@ if (buf != NULL && count != 0) \
   SSVAL(&ptr->header.len,0,count); \
   SSVAL(&ptr->header.maxlen,0,count); \
   SIVAL(&ptr->header.offset,0,((ptr->buffer - ((uint8*)ptr)) + ptr->bufIndex)); \
+  if (ptr->bufIndex > sizeof(ptr->buffer) \
+     || (count) > sizeof(ptr->buffer) - ptr->bufIndex) { goto err_buffer_full; } else {} \
   memcpy(ptr->buffer+ptr->bufIndex, buf, count); \
   ptr->bufIndex += count; \
   } \
@@ -196,6 +198,8 @@ void buildSmbNtlmAuthRequest(tSmbNtlmAuthRequest *request, char *user, char *dom
     SIVAL(&request->flags,0,0x0000b207);  /* have to figure out what these mean */
     AddString(request,user,u);
     AddString(request,domain,domain);
+
+err_buffer_full: // AddBytes (via AddString) might goto here
     free(u);
   }
 
@@ -230,6 +234,7 @@ void buildSmbNtlmAuthResponse(tSmbNtlmAuthChallenge *challenge, tSmbNtlmAuthResp
   
     response->flags = challenge->flags;
     
+err_buffer_full: // AddBytes, AddUnicodeString, AddString might goto here
     free(d);
     free(u);
   }
