[CABMAN] Fix GCC13 buffer format overflow warning (#7408)

CORE-19724

sdk/tools/cabman/dfp.cxx:1136:36: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
 1136 |             sprintf(InfLine, "%s=%s", GetFileName(SrcName).c_str(), DstName);
      |                                    ^
sdk/tools/cabman/dfp.cxx:1136:20: note: 'sprintf' output 2 or more bytes (assuming 4097) into a destination of size 4096
This commit is contained in:
Hermès Bélusca-Maïto 2024-09-29 16:08:20 +02:00
parent 10b08aa2bb
commit a0f8b40d5a
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
2 changed files with 10 additions and 4 deletions

View file

@ -36,10 +36,15 @@
#define C_ASSERT(expr) extern char (*c_assert(void)) [(expr) ? 1 : -1]
#endif
#ifndef _countof
#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
#endif
#if defined(_WIN32)
#define DIR_SEPARATOR_CHAR '\\'
#define DIR_SEPARATOR_STRING "\\"
#define snprintf _snprintf
#define strcasecmp _stricmp
#define strdup _strdup
#else

View file

@ -1031,7 +1031,7 @@ ULONG CDFParser::PerformFileCopy()
char ch;
char SrcName[PATH_MAX];
char DstName[PATH_MAX];
char InfLine[PATH_MAX];
char InfLine[PATH_MAX*2+1]; // To hold: GetFileName(SrcName) "=" DstName
char Options[128];
char BaseFilename[PATH_MAX];
@ -1076,7 +1076,7 @@ ULONG CDFParser::PerformFileCopy()
}
// options (it may be empty)
SkipSpaces ();
SkipSpaces();
if (CurrentToken != TokenEnd)
{
@ -1133,12 +1133,13 @@ ULONG CDFParser::PerformFileCopy()
switch (Status)
{
case CAB_STATUS_SUCCESS:
sprintf(InfLine, "%s=%s", GetFileName(SrcName).c_str(), DstName);
snprintf(InfLine, _countof(InfLine) - 1,
"%s=%s", GetFileName(SrcName).c_str(), DstName);
WriteInfLine(InfLine);
break;
case CAB_STATUS_CANNOT_OPEN:
if (strstr(Options,"optional"))
if (strstr(Options, "optional"))
{
Status = CAB_STATUS_SUCCESS;
printf("Optional file skipped (does not exist): %s.\n", SrcName);