Fixed GetComputerNameEx last error.
@@ -394,6 +394,12 @@ BOOL GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
int length;
char hostname[256];
+ if (!lpnSize)
+ {
+ SetLastError(ERROR_BAD_ARGUMENTS);
+ return FALSE;
+ }
+
if (gethostname(hostname, sizeof(hostname)) == -1)
return FALSE;
@@ -424,8 +430,24 @@ BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD l
int length;
char hostname[256];
+ if (!lpnSize)
+ {
+ SetLastError(ERROR_BAD_ARGUMENTS);
+ return FALSE;
+ }
+
if ((NameType == ComputerNameNetBIOS) || (NameType == ComputerNamePhysicalNetBIOS))
- return GetComputerNameA(lpBuffer, lpnSize);
+ {
+ BOOL rc = GetComputerNameA(lpBuffer, lpnSize);
+
+ if (!rc)
+ {
+ if (GetLastError() == ERROR_BUFFER_OVERFLOW)
+ SetLastError(ERROR_MORE_DATA);
+ }
+
+ return rc;
+ }
if (gethostname(hostname, sizeof(hostname)) == -1)
return FALSE;
@@ -461,12 +483,34 @@ BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD l
return TRUE;
}
-BOOL GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD nSize)
+BOOL GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD lpnSize)
+{
+ BOOL rc;
+ LPSTR lpABuffer = NULL;
+
+ if (!lpnSize)
{
- WLog_ERR(TAG, "GetComputerNameExW unimplemented");
+ SetLastError(ERROR_BAD_ARGUMENTS);
return FALSE;
}
+ if (*lpnSize > 0)
+ {
+ lpABuffer = calloc(*lpnSize, sizeof(CHAR));
+
+ if (!lpABuffer)
+ return FALSE;
+ }
+
+ rc = GetComputerNameExA(NameType, lpABuffer, lpnSize);
+
+ if (rc && (*lpnSize > 0))
+ ConvertToUnicode(CP_UTF8, 0, lpABuffer, *lpnSize, &lpBuffer, *lpnSize);
+
+ free(lpABuffer);
+ return rc;
+}
+
#endif
#if defined(_UWP)
