[USETUP] Use _wcstoui64() instead of atoi() to convert the partition size in order to prevent unexpected misinterpretation of leading zeroes.

This commit is contained in:
Eric Kohl 2018-05-19 13:30:20 +02:00
parent 72ad0fe70b
commit de824808b7

View file

@ -1766,7 +1766,7 @@ ShowPartitionSizeInputBox(SHORT Left,
SHORT Right, SHORT Right,
SHORT Bottom, SHORT Bottom,
ULONG MaxSize, ULONG MaxSize,
PCHAR InputBuffer, PWSTR InputBuffer,
PBOOLEAN Quit, PBOOLEAN Quit,
PBOOLEAN Cancel) PBOOLEAN Cancel)
{ {
@ -1774,8 +1774,7 @@ ShowPartitionSizeInputBox(SHORT Left,
COORD coPos; COORD coPos;
DWORD Written; DWORD Written;
CHAR Buffer[128]; CHAR Buffer[128];
WCHAR PartitionSizeBuffer[100]; INT Length, Pos;
ULONG Length, Pos;
WCHAR ch; WCHAR ch;
SHORT iLeft; SHORT iLeft;
SHORT iTop; SHORT iTop;
@ -1810,13 +1809,13 @@ ShowPartitionSizeInputBox(SHORT Left,
coPos, coPos,
&Written); &Written);
swprintf(PartitionSizeBuffer, L"%lu", MaxSize); swprintf(InputBuffer, L"%lu", MaxSize);
Length = wcslen(PartitionSizeBuffer); Length = wcslen(InputBuffer);
Pos = Length; Pos = Length;
CONSOLE_SetInputTextXY(iLeft, CONSOLE_SetInputTextXY(iLeft,
iTop, iTop,
PARTITION_SIZE_INPUT_FIELD_LENGTH, PARTITION_SIZE_INPUT_FIELD_LENGTH,
PartitionSizeBuffer); InputBuffer);
CONSOLE_SetCursorXY(iLeft + Length, iTop); CONSOLE_SetCursorXY(iLeft + Length, iTop);
CONSOLE_SetCursorType(TRUE, TRUE); CONSOLE_SetCursorType(TRUE, TRUE);
@ -1830,7 +1829,7 @@ ShowPartitionSizeInputBox(SHORT Left,
if (Quit != NULL) if (Quit != NULL)
*Quit = TRUE; *Quit = TRUE;
PartitionSizeBuffer[0] = UNICODE_NULL; InputBuffer[0] = UNICODE_NULL;
CONSOLE_SetCursorType(TRUE, FALSE); CONSOLE_SetCursorType(TRUE, FALSE);
break; break;
} }
@ -1844,7 +1843,7 @@ ShowPartitionSizeInputBox(SHORT Left,
if (Cancel != NULL) if (Cancel != NULL)
*Cancel = TRUE; *Cancel = TRUE;
PartitionSizeBuffer[0] = UNICODE_NULL; InputBuffer[0] = UNICODE_NULL;
CONSOLE_SetCursorType(TRUE, FALSE); CONSOLE_SetCursorType(TRUE, FALSE);
break; break;
} }
@ -1883,16 +1882,16 @@ ShowPartitionSizeInputBox(SHORT Left,
{ {
if (Pos < Length) if (Pos < Length)
{ {
memmove(&PartitionSizeBuffer[Pos], memmove(&InputBuffer[Pos],
&PartitionSizeBuffer[Pos + 1], &InputBuffer[Pos + 1],
(Length - Pos - 1) * sizeof(WCHAR)); (Length - Pos - 1) * sizeof(WCHAR));
PartitionSizeBuffer[Length - 1] = UNICODE_NULL; InputBuffer[Length - 1] = UNICODE_NULL;
Length--; Length--;
CONSOLE_SetInputTextXY(iLeft, CONSOLE_SetInputTextXY(iLeft,
iTop, iTop,
PARTITION_SIZE_INPUT_FIELD_LENGTH, PARTITION_SIZE_INPUT_FIELD_LENGTH,
PartitionSizeBuffer); InputBuffer);
CONSOLE_SetCursorXY(iLeft + Pos, iTop); CONSOLE_SetCursorXY(iLeft + Pos, iTop);
} }
} }
@ -1901,17 +1900,17 @@ ShowPartitionSizeInputBox(SHORT Left,
if (Pos > 0) if (Pos > 0)
{ {
if (Pos < Length) if (Pos < Length)
memmove(&PartitionSizeBuffer[Pos - 1], memmove(&InputBuffer[Pos - 1],
&PartitionSizeBuffer[Pos], &InputBuffer[Pos],
(Length - Pos) * sizeof(WCHAR)); (Length - Pos) * sizeof(WCHAR));
PartitionSizeBuffer[Length - 1] = UNICODE_NULL; InputBuffer[Length - 1] = UNICODE_NULL;
Pos--; Pos--;
Length--; Length--;
CONSOLE_SetInputTextXY(iLeft, CONSOLE_SetInputTextXY(iLeft,
iTop, iTop,
PARTITION_SIZE_INPUT_FIELD_LENGTH, PARTITION_SIZE_INPUT_FIELD_LENGTH,
PartitionSizeBuffer); InputBuffer);
CONSOLE_SetCursorXY(iLeft + Pos, iTop); CONSOLE_SetCursorXY(iLeft + Pos, iTop);
} }
} }
@ -1924,26 +1923,23 @@ ShowPartitionSizeInputBox(SHORT Left,
if ((ch >= L'0') && (ch <= L'9')) if ((ch >= L'0') && (ch <= L'9'))
{ {
if (Pos < Length) if (Pos < Length)
memmove(&PartitionSizeBuffer[Pos + 1], memmove(&InputBuffer[Pos + 1],
&PartitionSizeBuffer[Pos], &InputBuffer[Pos],
(Length - Pos) * sizeof(WCHAR)); (Length - Pos) * sizeof(WCHAR));
PartitionSizeBuffer[Length + 1] = UNICODE_NULL; InputBuffer[Length + 1] = UNICODE_NULL;
PartitionSizeBuffer[Pos] = ch; InputBuffer[Pos] = ch;
Pos++; Pos++;
Length++; Length++;
CONSOLE_SetInputTextXY(iLeft, CONSOLE_SetInputTextXY(iLeft,
iTop, iTop,
PARTITION_SIZE_INPUT_FIELD_LENGTH, PARTITION_SIZE_INPUT_FIELD_LENGTH,
PartitionSizeBuffer); InputBuffer);
CONSOLE_SetCursorXY(iLeft + Pos, iTop); CONSOLE_SetCursorXY(iLeft + Pos, iTop);
} }
} }
} }
} }
/* Convert UNICODE --> ANSI the poor man's way */
sprintf(InputBuffer, "%S", PartitionSizeBuffer);
} }
@ -1965,7 +1961,7 @@ CreatePrimaryPartitionPage(PINPUT_RECORD Ir)
PPARTENTRY PartEntry; PPARTENTRY PartEntry;
BOOLEAN Quit; BOOLEAN Quit;
BOOLEAN Cancel; BOOLEAN Cancel;
CHAR InputBuffer[50]; WCHAR InputBuffer[50];
ULONG MaxSize; ULONG MaxSize;
ULONGLONG PartSize; ULONGLONG PartSize;
ULONGLONG DiskSize; ULONGLONG DiskSize;
@ -2061,7 +2057,7 @@ CreatePrimaryPartitionPage(PINPUT_RECORD Ir)
} }
else else
{ {
PartSize = atoi(InputBuffer); PartSize = _wcstoui64(InputBuffer, NULL, 10);
if (PartSize < 1) if (PartSize < 1)
{ {
@ -2122,7 +2118,7 @@ CreateExtendedPartitionPage(PINPUT_RECORD Ir)
PPARTENTRY PartEntry; PPARTENTRY PartEntry;
BOOLEAN Quit; BOOLEAN Quit;
BOOLEAN Cancel; BOOLEAN Cancel;
CHAR InputBuffer[50]; WCHAR InputBuffer[50];
ULONG MaxSize; ULONG MaxSize;
ULONGLONG PartSize; ULONGLONG PartSize;
ULONGLONG DiskSize; ULONGLONG DiskSize;
@ -2218,7 +2214,7 @@ CreateExtendedPartitionPage(PINPUT_RECORD Ir)
} }
else else
{ {
PartSize = atoi(InputBuffer); PartSize = _wcstoui64(InputBuffer, NULL, 10);
if (PartSize < 1) if (PartSize < 1)
{ {
@ -2278,7 +2274,7 @@ CreateLogicalPartitionPage(PINPUT_RECORD Ir)
PPARTENTRY PartEntry; PPARTENTRY PartEntry;
BOOLEAN Quit; BOOLEAN Quit;
BOOLEAN Cancel; BOOLEAN Cancel;
CHAR InputBuffer[50]; WCHAR InputBuffer[50];
ULONG MaxSize; ULONG MaxSize;
ULONGLONG PartSize; ULONGLONG PartSize;
ULONGLONG DiskSize; ULONGLONG DiskSize;
@ -2374,7 +2370,7 @@ CreateLogicalPartitionPage(PINPUT_RECORD Ir)
} }
else else
{ {
PartSize = atoi(InputBuffer); PartSize = _wcstoui64(InputBuffer, NULL, 10);
if (PartSize < 1) if (PartSize < 1)
{ {