Skip to content

Commit 460ae51

Browse files
committed
apps: Fix printf overflow warnings
Newer versions of GCC complain when printf could possibly overflow and the return value is not checked. Convert to snprintf, and check the return value.
1 parent 8438101 commit 460ae51

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

apps/debug/client/armdis.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,19 +1964,28 @@ Return Value:
19641964
{
19651965

19661966
PSTR MnemonicSuffix;
1967+
INT Result;
19671968

19681969
MnemonicSuffix = DbgpArmGetLoadStoreTypeString(Context->Instruction);
19691970
sprintf(Context->Mnemonic, "%s%s", ARM_SRS_MNEMONIC, MnemonicSuffix);
19701971
DbgpArmPrintMode(Context->Operand2, Context->Instruction);
19711972
if ((Context->Instruction & ARM_WRITE_BACK_BIT) != 0) {
1972-
sprintf(Context->Operand1, "%s!, %s",
1973-
DbgArmRegisterNames[ARM_STACK_REGISTER],
1974-
Context->Operand2);
1973+
Result = snprintf(Context->Operand1,
1974+
sizeof(Context->Operand1),
1975+
"%s!, %s",
1976+
DbgArmRegisterNames[ARM_STACK_REGISTER],
1977+
Context->Operand2);
19751978

19761979
} else {
1977-
sprintf(Context->Operand1, "%s, %s",
1978-
DbgArmRegisterNames[ARM_STACK_REGISTER],
1979-
Context->Operand2);
1980+
Result = snprintf(Context->Operand1,
1981+
sizeof(Context->Operand1),
1982+
"%s, %s",
1983+
DbgArmRegisterNames[ARM_STACK_REGISTER],
1984+
Context->Operand2);
1985+
}
1986+
1987+
if (Result < 0) {
1988+
Context->Operand1[0] = '\0';
19801989
}
19811990

19821991
Context->Operand2[0] = '\0';

apps/lib/lzma/util/lzma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ Return Value:
609609
PSTR OutPathBuffer;
610610
size_t OutPathSize;
611611
ULONG Ratio;
612-
CHAR RatioString[6];
612+
CHAR RatioString[32];
613613
PCSTR Search;
614614
INT Status;
615615

apps/setup/uos/part.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,11 @@ Return Value:
264264

265265
Description = &(Results[ResultCount]);
266266
memset(Description, 0, sizeof(SETUP_PARTITION_DESCRIPTION));
267-
snprintf(Path, sizeof(Path), "/dev/%s", Device);
267+
Status = snprintf(Path, sizeof(Path), "/dev/%s", Device);
268+
if (Status < 0) {
269+
Status = EINVAL;
270+
goto OsEnumerateDevicesEnd;
271+
}
268272

269273
//
270274
// Figure out if this thing is a partition or a disk. If no entry is

0 commit comments

Comments
 (0)