[winpr,sysinfo] fix GetComputerNameA

* Trunctate to at most MAX_COMPUTERNAME_LENGTH characters
* Fix usage of function
This commit is contained in:
akallabeth
2024-12-13 11:22:06 +01:00
parent 586e84de29
commit e375556d07
6 changed files with 89 additions and 101 deletions

View File

@@ -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;