From e14934d06d9c02ba060fdf367b06476ae29cd359 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 22 Jul 2015 10:17:47 -0700 Subject: [PATCH] Check for invalid parameters in GetUserName --- src/impl/getusername.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/impl/getusername.cpp b/src/impl/getusername.cpp index 55ca9c93c..5e3aeb1c5 100644 --- a/src/impl/getusername.cpp +++ b/src/impl/getusername.cpp @@ -11,6 +11,7 @@ const string utf8 = "UTF-8"; // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724432(v=vs.85).aspx // Sets errno to: +// ERROR_INVALID_PARAMETER - parameter is not valid // ERROR_BAD_ENVIRONMENT - locale is not UTF-8 // ERROR_TOO_MANY_OPEN_FILES - already have the maximum allowed number of open files // ERROR_NO_ASSOCIATION - calling process has no controlling terminal @@ -23,10 +24,16 @@ const string utf8 = "UTF-8"; // Returns: // 1 - succeeded // 0 - failed -BOOL GetUserName(WCHAR_T* lpBuffer, LPDWORD lpnSize) +BOOL GetUserName(WCHAR_T *lpBuffer, LPDWORD lpnSize) { errno = 0; + // Check parameters + if (!lpBuffer || !lpnSize) { + errno = ERROR_INVALID_PARAMETER; + return 0; + } + // Select locale from environment setlocale(LC_ALL, ""); // Check that locale is UTF-8