Permalink
Browse files

Potentially fix segfaults on frontend startup

In nvctrl-util's GetNvidiaRates():
Initialise buf values to NULL, reduce it's size from 256 to 8 since
we're only interested in the first 8 tokens and actually check that we
parsed all 8 from the string before proceeding to use them.

While here change logging from VB_PLAYBACK to VB_GUI which makes more sense.

This may fix some frontend startup segfaults experienced by some
people since we ended up using an area of uninitialised memory in
strtol.

Coverity 746855
  • Loading branch information...
stuartm committed May 29, 2013
1 parent 0833b54 commit 516719ad7e750a258bd2f72f79eae099f79d303b
Showing with 19 additions and 8 deletions.
  1. +19 −8 mythtv/libs/libmythui/util-nvctrl.cpp
@@ -115,7 +115,7 @@ int GetNvidiaRates(t_screenrate& screenmap)
if (!XNVCTRLIsNvScreen(dpy, screen))
{
LOG(VB_PLAYBACK, LOG_INFO,
LOG(VB_GUI, LOG_INFO,
QString("The NV-CONTROL X extension is not available on screen %1 "
"of '%2'.")
.arg(screen) .arg(XDisplayName(NULL)));
@@ -126,7 +126,7 @@ int GetNvidiaRates(t_screenrate& screenmap)
ret = XNVCTRLQueryVersion(dpy, &major, &minor);
if (ret != True)
{
LOG(VB_PLAYBACK, LOG_INFO,
LOG(VB_GUI, LOG_INFO,
QString("The NV-CONTROL X extension does not exist on '%1'.")
.arg(XDisplayName(NULL)));
delete d;
@@ -137,14 +137,14 @@ int GetNvidiaRates(t_screenrate& screenmap)
if (!ret)
{
LOG(VB_PLAYBACK, LOG_ERR,
LOG(VB_GUI, LOG_ERR,
"Failed to query if Dynamic Twinview is enabled");
XCloseDisplay(dpy);
return -1;
}
if (!twinview)
{
LOG(VB_PLAYBACK, LOG_ERR, "Dynamic Twinview not enabled, ignoring");
LOG(VB_GUI, LOG_ERR, "Dynamic Twinview not enabled, ignoring");
delete d;
return 0;
}
@@ -159,7 +159,7 @@ int GetNvidiaRates(t_screenrate& screenmap)
if (!ret)
{
LOG(VB_PLAYBACK, LOG_ERR,
LOG(VB_GUI, LOG_ERR,
"Failed to query the enabled Display Devices.");
delete d;
return -1;
@@ -172,7 +172,7 @@ int GetNvidiaRates(t_screenrate& screenmap)
(unsigned char **)&pMetaModes, &MetaModeLen);
if (!ret)
{
LOG(VB_PLAYBACK, LOG_ERR,
LOG(VB_GUI, LOG_ERR,
"Failed to query the metamode on selected display device.");
delete d;
return -1;
@@ -194,7 +194,7 @@ int GetNvidiaRates(t_screenrate& screenmap)
(unsigned char **)&str, &len);
if (!ret)
{
LOG(VB_PLAYBACK, LOG_ERR,
LOG(VB_GUI, LOG_ERR,
"Unknown error. Failed to query the enabled Display Devices.");
// Free Memory currently allocated
for (j=0; j < nDisplayDevice; ++j)
@@ -274,7 +274,7 @@ int GetNvidiaRates(t_screenrate& screenmap)
{
int w, h, vfl, hfl, i, irate;
double dcl, r;
char *buf[256];
char *buf[8] = {NULL};
uint64_t key, key2;
// skip name
@@ -288,7 +288,18 @@ int GetNvidiaRates(t_screenrate& screenmap)
modeString = strtok_r(NULL, " ", &strtok_state))
{
buf[i++] = modeString;
if (i == 9) // We're only interested in the first 8 tokens
break;
}
if (i < 9)
{
LOG(VB_GUI, LOG_WARNING, "Invalid modeline string "
"received, skipping");
continue;
}
w = strtol(buf[1], NULL, 10);
h = strtol(buf[5], NULL, 10);
vfl = strtol(buf[8], NULL, 10);

0 comments on commit 516719a

Please sign in to comment.