https://git.reactos.org/?p=reactos.git;a=commitdiff;h=28ed2347ef8b382c0062e…
commit 28ed2347ef8b382c0062e7001765ba3a9b5b7a3e
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Jun 16 01:00:40 2019 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sun Jun 16 01:00:40 2019 +0200
[HOSTNAME] Retrieve the DNS *host name* of the computer, and not the computer name.
CORE-16095, ROSTESTS-326
---
base/applications/cmdutils/hostname/hostname.c | 69 ++++++++++++++------------
1 file changed, 36 insertions(+), 33 deletions(-)
diff --git a/base/applications/cmdutils/hostname/hostname.c b/base/applications/cmdutils/hostname/hostname.c
index 4e49c5d4182..00ded61f1bf 100644
--- a/base/applications/cmdutils/hostname/hostname.c
+++ b/base/applications/cmdutils/hostname/hostname.c
@@ -1,28 +1,12 @@
/*
- * ReactOS Win32 Applications
- * Copyright (C) 2005 ReactOS Team
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-/*
- * COPYRIGHT : See COPYING in the top level directory
- * PROJECT : ReactOS/Win32 get host name
- * FILE : subsys/system/hostname/hostname.c
- * PROGRAMMER: Emanuele Aliberti (ea(a)reactos.com)
+ * PROJECT: ReactOS Hostname Command
+ * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
+ * PURPOSE: Retrieves the current DNS host name of the computer.
+ * COPYRIGHT: Copyright 2005-2019 Emanuele Aliberti (ea(a)reactos.com)
+ * Copyright 2019 Hermes Belusca-Maito
*/
+#include <stdlib.h>
#include <conio.h>
#include <windef.h>
@@ -35,35 +19,54 @@ int wmain(int argc, WCHAR* argv[])
{
WCHAR Msg[100];
- if (1 == argc)
+ if (argc == 1)
{
- WCHAR ComputerName[MAX_COMPUTERNAME_LENGTH + 1] = L"";
- DWORD ComputerNameSize = sizeof(ComputerName) / sizeof(ComputerName[0]);
+ BOOL bSuccess;
+ WCHAR LocalHostName[256] = L""; // MAX_COMPUTERNAME_LENGTH + 1 for NetBIOS name.
+ DWORD HostNameSize = _countof(LocalHostName);
+ PWSTR HostName = LocalHostName;
+
+ /* Try to retrieve the host name using the local buffer */
+ bSuccess = GetComputerNameExW(ComputerNameDnsHostname, HostName, &HostNameSize);
+ if (!bSuccess && (GetLastError() == ERROR_MORE_DATA))
+ {
+ /* Retry with a larger buffer since the local buffer was too small */
+ HostName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, HostNameSize * sizeof(WCHAR));
+ if (HostName)
+ bSuccess = GetComputerNameExW(ComputerNameDnsHostname, HostName, &HostNameSize);
+ }
- if (!GetComputerName(ComputerName, &ComputerNameSize))
+ if (bSuccess)
+ {
+ /* Print out the host name */
+ _cwprintf(L"%s\n", HostName);
+ }
+
+ /* If a larger buffer has been allocated, free it */
+ if (HostName && (HostName != LocalHostName))
+ HeapFree(GetProcessHeap(), 0, HostName);
+
+ if (!bSuccess)
{
/* Fail in case of error */
- LoadStringW(GetModuleHandle(NULL), IDS_ERROR, Msg, 100);
+ LoadStringW(GetModuleHandle(NULL), IDS_ERROR, Msg, _countof(Msg));
_cwprintf(L"%s %lu.\n", Msg, GetLastError());
return 1;
}
-
- /* Print out the computer's name */
- _cwprintf(L"%s\n", ComputerName);
}
else
{
if ((wcsicmp(argv[1], L"-s") == 0) || (wcsicmp(argv[1], L"/s") == 0))
{
- /* The program doesn't allow the user to set the computer's name */
- LoadStringW(GetModuleHandle(NULL), IDS_NOSET, Msg, 100);
+ /* The program doesn't allow the user to set the host name */
+ LoadStringW(GetModuleHandle(NULL), IDS_NOSET, Msg, _countof(Msg));
_cwprintf(L"%s\n", Msg);
return 1;
}
else
{
/* Let the user know what the program does */
- LoadStringW(GetModuleHandle(NULL), IDS_USAGE, Msg, 100);
+ LoadStringW(GetModuleHandle(NULL), IDS_USAGE, Msg, _countof(Msg));
_cwprintf(L"\n%s\n\n", Msg);
}
}
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=9ade0e7b04ede20a13a51…
commit 9ade0e7b04ede20a13a512780ada2631fd645416
Author: Bișoc George <fraizeraust99(a)gmail.com>
AuthorDate: Fri Jun 14 20:52:41 2019 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Jun 15 18:12:54 2019 +0200
[MAGNIFY] Fix a string buffer misuage that led to division by zero exception. (#1655)
The iZoom variable was wrongly initialized to zero because the _ttoi()
called failed due to the fact the temporary string buffer was too small.
---
base/applications/magnify/magnifier.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/base/applications/magnify/magnifier.c b/base/applications/magnify/magnifier.c
index cfca2519914..13a0a3cd190 100644
--- a/base/applications/magnify/magnifier.c
+++ b/base/applications/magnify/magnifier.c
@@ -931,7 +931,7 @@ INT_PTR CALLBACK OptionsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar
if (HIWORD(wParam) == CBN_SELCHANGE)
{
HWND hCombo = GetDlgItem(hDlg,IDC_ZOOM);
- LPCTSTR currentZoomValue = TEXT("");
+ TCHAR currentZoomValue[2] = TEXT("");
/* Get index of current selection and the text of that selection */
int currentSelectionIndex = ComboBox_GetCurSel(hCombo);