From 1a6aba01301cc5d72ad3e2f0a1bb3337ab25fa95 Mon Sep 17 00:00:00 2001 From: Martin Fleisz Date: Wed, 15 Jul 2015 11:47:01 +0200 Subject: [PATCH] winpr/tools: Fixed x509_get_default_name failing with long computer names --- winpr/tools/makecert/makecert.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/winpr/tools/makecert/makecert.c b/winpr/tools/makecert/makecert.c index 0c8ba032e..cfe642fe4 100644 --- a/winpr/tools/makecert/makecert.c +++ b/winpr/tools/makecert/makecert.c @@ -306,19 +306,24 @@ char* x509_name_parse(char* name, char* txt, int* length) char* x509_get_default_name() { - CHAR computerName[MAX_COMPUTERNAME_LENGTH + 1]; - DWORD nSize = MAX_COMPUTERNAME_LENGTH; + CHAR* computerName; + DWORD nSize = 0; - char* ret; - - if (!GetComputerNameExA(ComputerNameNetBIOS, computerName, &nSize)) + if (GetComputerNameExA(ComputerNamePhysicalNetBIOS, NULL, &nSize) || + GetLastError() != ERROR_MORE_DATA) return NULL; - ret = _strdup(computerName); - if (!ret) + computerName = (CHAR*)calloc(nSize, 1); + if (!computerName) return NULL; - return ret; + if (!GetComputerNameExA(ComputerNamePhysicalNetBIOS, computerName, &nSize)) + { + free(computerName); + return NULL; + } + + return computerName; } int command_line_pre_filter(MAKECERT_CONTEXT* context, int index, int argc, LPCSTR* argv)