winpr/sspi/ntlm: fix computer name len calculation
authorNorbert Federa <norbert.federa@thincast.com>
Thu, 30 Jun 2016 15:15:40 +0000 (17:15 +0200)
committerNorbert Federa <norbert.federa@thincast.com>
Thu, 30 Jun 2016 15:15:40 +0000 (17:15 +0200)
The lpnSize parameter for GetComputerNameEx specifies the total
size of the buffer (in characters).
However, the current code calculated the amount of bytes.
Since only GetComputerNameExA was used and because sizeof(CHAR) == 1
the result was correct but the math was wrong.
Credit goes to @byteboon

winpr/libwinpr/sspi/NTLM/ntlm.c
winpr/libwinpr/sspi/NTLM/ntlm_av_pairs.c

index 4803c40..1d56de1 100644 (file)
@@ -47,7 +47,7 @@ int ntlm_SetContextWorkstation(NTLM_CONTEXT* context, char* Workstation)
        int status;
        char* ws = Workstation;
        CHAR computerName[MAX_COMPUTERNAME_LENGTH + 1];
-       DWORD nSize = sizeof(computerName) * sizeof(CHAR);
+       DWORD nSize = sizeof(computerName) / sizeof(CHAR);
 
        if (!Workstation)
        {
@@ -108,12 +108,11 @@ int ntlm_SetContextTargetName(NTLM_CONTEXT* context, char* TargetName)
 {
        int status;
        CHAR computerName[MAX_COMPUTERNAME_LENGTH + 1];
-       DWORD nSize = sizeof(computerName) * sizeof(CHAR);
+       DWORD nSize = sizeof(computerName) / sizeof(CHAR);
        char* name = TargetName;
 
        if (!name)
        {
-
                if (!GetComputerNameExA(ComputerNameDnsHostname, computerName, &nSize))
                        return -1;
 
index 8e6ff8a..11657ca 100644 (file)
@@ -174,7 +174,7 @@ int ntlm_get_target_computer_name(PUNICODE_STRING pName, COMPUTER_NAME_FORMAT ty
        char* name;
        int status;
        CHAR computerName[MAX_COMPUTERNAME_LENGTH + 1];
-       DWORD nSize = sizeof(computerName) * sizeof(CHAR);
+       DWORD nSize = sizeof(computerName) / sizeof(CHAR);
 
        if (!GetComputerNameExA(type, computerName, &nSize))
                return -1;