Merge pull request #6754 from symless/issue-6753-sprintf-vulnerability
Replaced sprintf with snprintf
This commit is contained in:
commit
4971d874db
6 changed files with 26 additions and 17 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
v1.12.x-snapshot
|
v1.12.x-snapshot
|
||||||
===========
|
===========
|
||||||
|
Bug fixes:
|
||||||
|
- #6753 Fixed a number of vulnerabilities detected by static analysis
|
||||||
|
|
||||||
Enhancements:
|
Enhancements:
|
||||||
- #6750 Integrate SonarCloud for static analysis and test coverage
|
- #6750 Integrate SonarCloud for static analysis and test coverage
|
||||||
|
|
|
||||||
|
|
@ -178,11 +178,12 @@ Log::print(const char* file, int line, const char* fmt, ...)
|
||||||
if (priority != kPRINT) {
|
if (priority != kPRINT) {
|
||||||
|
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
char timestamp[50];
|
static const int timestamp_size = 50;
|
||||||
|
char timestamp[timestamp_size];
|
||||||
time_t t;
|
time_t t;
|
||||||
time(&t);
|
time(&t);
|
||||||
tm = localtime(&t);
|
tm = localtime(&t);
|
||||||
sprintf(timestamp, "%04i-%02i-%02iT%02i:%02i:%02i", tm->tm_year + 1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
|
snprintf(timestamp, timestamp_size, "%04i-%02i-%02iT%02i:%02i:%02i", tm->tm_year + 1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
|
||||||
|
|
||||||
// square brackets, spaces, comma and null terminator take about 10
|
// square brackets, spaces, comma and null terminator take about 10
|
||||||
int size = 10;
|
int size = 10;
|
||||||
|
|
@ -197,9 +198,9 @@ Log::print(const char* file, int line, const char* fmt, ...)
|
||||||
char* message = new char[size];
|
char* message = new char[size];
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
sprintf(message, "[%s] %s: %s\n\t%s,%d", timestamp, g_priority[priority], buffer, file, line);
|
snprintf(message, size, "[%s] %s: %s\n\t%s,%d", timestamp, g_priority[priority], buffer, file, line);
|
||||||
#else
|
#else
|
||||||
sprintf(message, "[%s] %s: %s", timestamp, g_priority[priority], buffer);
|
snprintf(message, size, "[%s] %s: %s", timestamp, g_priority[priority], buffer);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
output(priority, message);
|
output(priority, message);
|
||||||
|
|
|
||||||
|
|
@ -710,8 +710,9 @@ XWindowsClipboard::motifFillCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the Motif item property from the root window
|
// get the Motif item property from the root window
|
||||||
char name[18 + 20];
|
static const int buffer_size = 18 + 20;
|
||||||
sprintf(name, "_MOTIF_CLIP_ITEM_%d", header.m_item);
|
char name[buffer_size];
|
||||||
|
snprintf(name, buffer_size, "_MOTIF_CLIP_ITEM_%d", header.m_item);
|
||||||
Atom atomItem = XInternAtom(m_display, name, False);
|
Atom atomItem = XInternAtom(m_display, name, False);
|
||||||
data = "";
|
data = "";
|
||||||
if (!XWindowsUtil::getWindowProperty(m_display, root,
|
if (!XWindowsUtil::getWindowProperty(m_display, root,
|
||||||
|
|
@ -740,7 +741,7 @@ XWindowsClipboard::motifFillCache()
|
||||||
MotifFormatMap motifFormats;
|
MotifFormatMap motifFormats;
|
||||||
for (SInt32 i = 0; i < numFormats; ++i) {
|
for (SInt32 i = 0; i < numFormats; ++i) {
|
||||||
// get Motif format property from the root window
|
// get Motif format property from the root window
|
||||||
sprintf(name, "_MOTIF_CLIP_ITEM_%d", formats[i]);
|
snprintf(name, buffer_size, "_MOTIF_CLIP_ITEM_%d", formats[i]);
|
||||||
Atom atomFormat = XInternAtom(m_display, name, False);
|
Atom atomFormat = XInternAtom(m_display, name, False);
|
||||||
String data;
|
String data;
|
||||||
if (!XWindowsUtil::getWindowProperty(m_display, root,
|
if (!XWindowsUtil::getWindowProperty(m_display, root,
|
||||||
|
|
@ -822,8 +823,9 @@ XWindowsClipboard::motifGetSelection(const MotifClipFormat* format,
|
||||||
// already stored on the root window and only if it fits in a
|
// already stored on the root window and only if it fits in a
|
||||||
// property. motif has some scheme for transferring part by
|
// property. motif has some scheme for transferring part by
|
||||||
// part that i don't know.
|
// part that i don't know.
|
||||||
char name[18 + 20];
|
static const int buffer_size = 18+20;
|
||||||
sprintf(name, "_MOTIF_CLIP_ITEM_%d", format->m_data);
|
char name[buffer_size];
|
||||||
|
snprintf(name, buffer_size, "_MOTIF_CLIP_ITEM_%d", format->m_data);
|
||||||
Atom target = XInternAtom(m_display, name, False);
|
Atom target = XInternAtom(m_display, name, False);
|
||||||
Window root = RootWindow(m_display, DefaultScreen(m_display));
|
Window root = RootWindow(m_display, DefaultScreen(m_display));
|
||||||
return XWindowsUtil::getWindowProperty(m_display, root,
|
return XWindowsUtil::getWindowProperty(m_display, root,
|
||||||
|
|
|
||||||
|
|
@ -83,9 +83,11 @@ App::~App()
|
||||||
void
|
void
|
||||||
App::version()
|
App::version()
|
||||||
{
|
{
|
||||||
char buffer[500];
|
static const int buffer_size = 500;
|
||||||
sprintf(
|
char buffer[buffer_size];
|
||||||
|
snprintf(
|
||||||
buffer,
|
buffer,
|
||||||
|
buffer_size,
|
||||||
"%s %s, protocol version %d.%d\n%s",
|
"%s %s, protocol version %d.%d\n%s",
|
||||||
argsBase().m_pname,
|
argsBase().m_pname,
|
||||||
kVersion,
|
kVersion,
|
||||||
|
|
|
||||||
|
|
@ -118,10 +118,11 @@ ClientApp::help()
|
||||||
# define WINAPI_ARG
|
# define WINAPI_ARG
|
||||||
# define WINAPI_INFO
|
# define WINAPI_INFO
|
||||||
#endif
|
#endif
|
||||||
|
static const int buffer_size = 2000;
|
||||||
char buffer[2000];
|
char buffer[buffer_size];
|
||||||
sprintf(
|
snprintf(
|
||||||
buffer,
|
buffer,
|
||||||
|
buffer_size,
|
||||||
"Usage: %s"
|
"Usage: %s"
|
||||||
" [--yscroll <delta>]"
|
" [--yscroll <delta>]"
|
||||||
WINAPI_ARG
|
WINAPI_ARG
|
||||||
|
|
|
||||||
|
|
@ -119,10 +119,11 @@ ServerApp::help()
|
||||||
# define WINAPI_ARGS
|
# define WINAPI_ARGS
|
||||||
# define WINAPI_INFO
|
# define WINAPI_INFO
|
||||||
#endif
|
#endif
|
||||||
|
static const int buffer_size = 3000;
|
||||||
char buffer[3000];
|
char buffer[buffer_size];
|
||||||
sprintf(
|
snprintf(
|
||||||
buffer,
|
buffer,
|
||||||
|
buffer_size,
|
||||||
"Usage: %s"
|
"Usage: %s"
|
||||||
" [--address <address>]"
|
" [--address <address>]"
|
||||||
" [--config <pathname>]"
|
" [--config <pathname>]"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue