mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
[winpr,sysinfo] fix GetComputerNameA
* Trunctate to at most MAX_COMPUTERNAME_LENGTH characters * Fix usage of function
This commit is contained in:
@@ -222,37 +222,22 @@ static char* x509_name_parse(char* name, char* txt, size_t* length)
|
||||
return entry;
|
||||
}
|
||||
|
||||
static char* x509_get_default_name(void)
|
||||
static char* get_name(COMPUTER_NAME_FORMAT type)
|
||||
{
|
||||
CHAR* computerName = NULL;
|
||||
DWORD nSize = 0;
|
||||
|
||||
if (GetComputerNameExA(ComputerNamePhysicalDnsFullyQualified, NULL, &nSize) ||
|
||||
GetLastError() != ERROR_MORE_DATA)
|
||||
goto fallback;
|
||||
|
||||
computerName = (CHAR*)calloc(1, nSize);
|
||||
|
||||
if (!computerName)
|
||||
goto fallback;
|
||||
|
||||
if (!GetComputerNameExA(ComputerNamePhysicalDnsFullyQualified, computerName, &nSize))
|
||||
goto fallback;
|
||||
|
||||
return computerName;
|
||||
fallback:
|
||||
free(computerName);
|
||||
|
||||
if (GetComputerNameExA(ComputerNamePhysicalNetBIOS, NULL, &nSize) ||
|
||||
GetLastError() != ERROR_MORE_DATA)
|
||||
if (GetComputerNameExA(type, NULL, &nSize))
|
||||
return NULL;
|
||||
|
||||
computerName = (CHAR*)calloc(1, nSize);
|
||||
if (GetLastError() != ERROR_MORE_DATA)
|
||||
return NULL;
|
||||
|
||||
char* computerName = calloc(1, nSize);
|
||||
|
||||
if (!computerName)
|
||||
return NULL;
|
||||
|
||||
if (!GetComputerNameExA(ComputerNamePhysicalNetBIOS, computerName, &nSize))
|
||||
if (!GetComputerNameExA(type, computerName, &nSize))
|
||||
{
|
||||
free(computerName);
|
||||
return NULL;
|
||||
@@ -261,6 +246,14 @@ fallback:
|
||||
return computerName;
|
||||
}
|
||||
|
||||
static char* x509_get_default_name(void)
|
||||
{
|
||||
char* computerName = get_name(ComputerNamePhysicalDnsFullyQualified);
|
||||
if (!computerName)
|
||||
computerName = get_name(ComputerNamePhysicalNetBIOS);
|
||||
return computerName;
|
||||
}
|
||||
|
||||
static int command_line_pre_filter(void* pvctx, int index, int argc, LPSTR* argv)
|
||||
{
|
||||
MAKECERT_CONTEXT* context = pvctx;
|
||||
|
||||
Reference in New Issue
Block a user