Add 'const' when needed

Remove a string copy (an a possible buffer overflow)

svn path=/trunk/; revision=31682
This commit is contained in:
Hervé Poussineau 2008-01-09 09:40:47 +00:00
parent 76b039af9f
commit c21f0dc69a
3 changed files with 75 additions and 70 deletions

View file

@ -199,8 +199,8 @@ DrawBox(
} }
VOID VOID
PopupError(PCHAR Text, PopupError(PCCH Text,
PCHAR Status, PCCH Status,
PINPUT_RECORD Ir, PINPUT_RECORD Ir,
ULONG WaitEvent) ULONG WaitEvent)
{ {
@ -212,7 +212,7 @@ PopupError(PCHAR Text,
ULONG MaxLength; ULONG MaxLength;
ULONG Lines; ULONG Lines;
PCHAR p; PCHAR p;
PCHAR pnext; PCCH pnext;
BOOLEAN LastLine; BOOLEAN LastLine;
SHORT Width; SHORT Width;
SHORT Height; SHORT Height;
@ -560,14 +560,14 @@ CheckUnattendedSetup(VOID)
DPRINT("Running unattended setup\n"); DPRINT("Running unattended setup\n");
} }
void VOID
UpdateKBLayout() UpdateKBLayout(VOID)
{ {
PLIST_ENTRY Entry; PLIST_ENTRY Entry;
PGENERIC_LIST_ENTRY ListEntry; PGENERIC_LIST_ENTRY ListEntry;
WCHAR szNewLayout[20]; LPCWSTR pszNewLayout;
MUIDefaultKeyboardLayout(szNewLayout); pszNewLayout = MUIDefaultKeyboardLayout();
if (LayoutList == NULL) if (LayoutList == NULL)
{ {
@ -575,17 +575,22 @@ UpdateKBLayout()
} }
Entry = LayoutList->ListHead.Flink; Entry = LayoutList->ListHead.Flink;
while (Entry != &LayoutList->ListHead)
/* Search for default layout (if provided) */
if (pszNewLayout != NULL)
{ {
ListEntry = CONTAINING_RECORD (Entry, GENERIC_LIST_ENTRY, Entry); while (Entry != &LayoutList->ListHead)
if (!wcscmp(szNewLayout, ListEntry->UserData))
{ {
LayoutList->CurrentEntry = ListEntry; ListEntry = CONTAINING_RECORD (Entry, GENERIC_LIST_ENTRY, Entry);
break;
}
Entry = Entry->Flink; if (!wcscmp(pszNewLayout, ListEntry->UserData))
{
LayoutList->CurrentEntry = ListEntry;
break;
}
Entry = Entry->Flink;
}
} }
} }

View file

@ -42,7 +42,7 @@
#include "lang/sv-SE.h" #include "lang/sv-SE.h"
#include "lang/uk-UA.h" #include "lang/uk-UA.h"
static MUI_LANGUAGE LanguageList[] = static const MUI_LANGUAGE LanguageList[] =
{ {
{ {
L"00000409", /* The Language ID */ L"00000409", /* The Language ID */
@ -155,18 +155,18 @@ static MUI_LANGUAGE LanguageList[] =
extern extern
VOID VOID
PopupError(PCHAR Text, PopupError(IN PCCH Text,
PCHAR Status, IN PCCH Status,
PINPUT_RECORD Ir, IN PINPUT_RECORD Ir,
ULONG WaitEvent); IN ULONG WaitEvent);
static static
MUI_ENTRY * const MUI_ENTRY *
FindMUIEntriesOfPage (ULONG PageNumber) FindMUIEntriesOfPage(IN ULONG PageNumber)
{ {
ULONG muiIndex = 0; ULONG muiIndex = 0;
ULONG lngIndex = 0; ULONG lngIndex = 0;
MUI_PAGE * Pages = NULL; const MUI_PAGE * Pages = NULL;
do do
{ {
@ -195,8 +195,8 @@ FindMUIEntriesOfPage (ULONG PageNumber)
} }
static static
MUI_ERROR * const MUI_ERROR *
FindMUIErrorEntries () FindMUIErrorEntries(VOID)
{ {
ULONG lngIndex = 0; ULONG lngIndex = 0;
@ -216,8 +216,8 @@ FindMUIErrorEntries ()
return NULL; return NULL;
} }
VOID LPCWSTR
MUIDefaultKeyboardLayout(WCHAR * KeyboardLayout) MUIDefaultKeyboardLayout(VOID)
{ {
ULONG lngIndex = 0; ULONG lngIndex = 0;
do do
@ -225,26 +225,25 @@ MUIDefaultKeyboardLayout(WCHAR * KeyboardLayout)
/* First we search the language list till we find current selected language messages */ /* First we search the language list till we find current selected language messages */
if (_wcsicmp(LanguageList[lngIndex].LanguageID , SelectedLanguageId) == 0) if (_wcsicmp(LanguageList[lngIndex].LanguageID , SelectedLanguageId) == 0)
{ {
/* Get all available error messages for this language */ /* Return default keyboard layout */
wcscpy(KeyboardLayout, LanguageList[lngIndex].LanguageKeyboardLayoutID); return LanguageList[lngIndex].LanguageKeyboardLayoutID;
return;
} }
lngIndex++; lngIndex++;
} }
while (LanguageList[lngIndex].MuiPages != NULL); while (LanguageList[lngIndex].MuiPages != NULL);
KeyboardLayout[0] = L'\0'; return NULL;
} }
VOID VOID
MUIDisplayPage(ULONG page) MUIDisplayPage(IN ULONG page)
{ {
MUI_ENTRY * entry; const MUI_ENTRY * entry;
int index; int index;
int flags; int flags;
entry = FindMUIEntriesOfPage (page); entry = FindMUIEntriesOfPage(page);
if (!entry) if (!entry)
{ {
PopupError("Error: Failed to find translated page", PopupError("Error: Failed to find translated page",
@ -281,13 +280,13 @@ MUIDisplayPage(ULONG page)
} }
VOID VOID
MUIDisplayError(ULONG ErrorNum, PINPUT_RECORD Ir, ULONG WaitEvent) MUIDisplayError(IN ULONG ErrorNum, OUT PINPUT_RECORD Ir, IN ULONG WaitEvent)
{ {
MUI_ERROR * entry; const MUI_ERROR * entry;
if (ErrorNum >= ERROR_LAST_ERROR_CODE) if (ErrorNum >= ERROR_LAST_ERROR_CODE)
{ {
PopupError("Pnvalid error number provided", PopupError("Invalid error number provided",
"Press ENTER to continue", "Press ENTER to continue",
Ir, Ir,
POPUP_WAIT_ENTER); POPUP_WAIT_ENTER);
@ -295,7 +294,7 @@ MUIDisplayError(ULONG ErrorNum, PINPUT_RECORD Ir, ULONG WaitEvent)
return; return;
} }
entry = FindMUIErrorEntries (); entry = FindMUIErrorEntries();
if (!entry) if (!entry)
{ {
PopupError("Error: Failed to find translated error message", PopupError("Error: Failed to find translated error message",
@ -312,7 +311,7 @@ MUIDisplayError(ULONG ErrorNum, PINPUT_RECORD Ir, ULONG WaitEvent)
} }
static BOOLEAN static BOOLEAN
AddCodepageToRegistry(PWCHAR ACPage, PWCHAR OEMCPage, PWCHAR MACCPage) AddCodepageToRegistry(IN LPCWSTR ACPage, IN LPCWSTR OEMCPage, IN LPCWSTR MACCPage)
{ {
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING KeyName; UNICODE_STRING KeyName;
@ -322,15 +321,15 @@ AddCodepageToRegistry(PWCHAR ACPage, PWCHAR OEMCPage, PWCHAR MACCPage)
// Open the nls codepage key // Open the nls codepage key
RtlInitUnicodeString(&KeyName, RtlInitUnicodeString(&KeyName,
L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage"); L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage");
InitializeObjectAttributes(&ObjectAttributes, InitializeObjectAttributes(&ObjectAttributes,
&KeyName, &KeyName,
OBJ_CASE_INSENSITIVE, OBJ_CASE_INSENSITIVE,
NULL, NULL,
NULL); NULL);
Status = NtOpenKey(&KeyHandle, Status = NtOpenKey(&KeyHandle,
KEY_ALL_ACCESS, KEY_WRITE,
&ObjectAttributes); &ObjectAttributes);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("NtOpenKey() failed (Status %lx)\n", Status); DPRINT1("NtOpenKey() failed (Status %lx)\n", Status);
@ -340,11 +339,11 @@ AddCodepageToRegistry(PWCHAR ACPage, PWCHAR OEMCPage, PWCHAR MACCPage)
// Set ANSI codepage // Set ANSI codepage
RtlInitUnicodeString(&ValueName, L"ACP"); RtlInitUnicodeString(&ValueName, L"ACP");
Status = NtSetValueKey(KeyHandle, Status = NtSetValueKey(KeyHandle,
&ValueName, &ValueName,
0, 0,
REG_SZ, REG_SZ,
(PVOID)ACPage, (PVOID)ACPage,
4 * sizeof(PWCHAR)); wcslen(ACPage) * sizeof(PWCHAR));
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status); DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
@ -355,11 +354,11 @@ AddCodepageToRegistry(PWCHAR ACPage, PWCHAR OEMCPage, PWCHAR MACCPage)
// Set OEM codepage // Set OEM codepage
RtlInitUnicodeString(&ValueName, L"OEMCP"); RtlInitUnicodeString(&ValueName, L"OEMCP");
Status = NtSetValueKey(KeyHandle, Status = NtSetValueKey(KeyHandle,
&ValueName, &ValueName,
0, 0,
REG_SZ, REG_SZ,
(PVOID)OEMCPage, (PVOID)OEMCPage,
3 * sizeof(PWCHAR)); wcslen(OEMCPage) * sizeof(PWCHAR));
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status); DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
@ -370,11 +369,11 @@ AddCodepageToRegistry(PWCHAR ACPage, PWCHAR OEMCPage, PWCHAR MACCPage)
// Set MAC codepage // Set MAC codepage
RtlInitUnicodeString(&ValueName, L"MACCP"); RtlInitUnicodeString(&ValueName, L"MACCP");
Status = NtSetValueKey(KeyHandle, Status = NtSetValueKey(KeyHandle,
&ValueName, &ValueName,
0, 0,
REG_SZ, REG_SZ,
(PVOID)MACCPage, (PVOID)MACCPage,
5 * sizeof(PWCHAR)); wcslen(MACCPage) * sizeof(PWCHAR));
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status); DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
@ -403,7 +402,8 @@ AddCodePage(VOID)
lngIndex++; lngIndex++;
} }
while (LanguageList[lngIndex].MuiPages != NULL); while (LanguageList[lngIndex].MuiPages != NULL);
return FALSE;
return FALSE;
} }
/* EOF */ /* EOF */

View file

@ -5,19 +5,19 @@ typedef struct
{ {
BYTE X; BYTE X;
BYTE Y; BYTE Y;
CHAR * Buffer; LPCSTR Buffer;
BYTE Flags; BYTE Flags;
}MUI_ENTRY, *PMUI_ENTRY; }MUI_ENTRY, *PMUI_ENTRY;
typedef struct typedef struct
{ {
CHAR * ErrorText; LPCSTR ErrorText;
CHAR * ErrorStatus; LPCSTR ErrorStatus;
}MUI_ERROR; }MUI_ERROR;
typedef struct typedef struct
{ {
long Number; LONG Number;
MUI_ENTRY * MuiEntry; MUI_ENTRY * MuiEntry;
}MUI_PAGE; }MUI_PAGE;
@ -29,8 +29,8 @@ typedef struct
PWCHAR OEMCPage; PWCHAR OEMCPage;
PWCHAR MACCPage; PWCHAR MACCPage;
PWCHAR LanguageDescriptor; PWCHAR LanguageDescriptor;
MUI_PAGE * MuiPages; const MUI_PAGE * MuiPages;
MUI_ERROR * MuiErrors; const MUI_ERROR * MuiErrors;
}MUI_LANGUAGE; }MUI_LANGUAGE;
@ -50,8 +50,8 @@ MUIDisplayPage (ULONG PageNumber);
VOID VOID
MUIDisplayError (ULONG ErrorNum, PINPUT_RECORD Ir, ULONG WaitEvent); MUIDisplayError (ULONG ErrorNum, PINPUT_RECORD Ir, ULONG WaitEvent);
VOID LPCWSTR
MUIDefaultKeyboardLayout(WCHAR * KeyboardLayout); MUIDefaultKeyboardLayout(VOID);
BOOLEAN BOOLEAN
AddCodePage(VOID); AddCodePage(VOID);