idx
int64 | func_before
string | Vulnerability Classification
string | vul
int64 | func_after
string | patch
string | CWE ID
string | lines_before
string | lines_after
string |
|---|---|---|---|---|---|---|---|---|
6,600
|
XRRScreenSize *XRRConfigSizes(XRRScreenConfiguration *config, int *nsizes)
{
*nsizes = config->nsizes;
return config->sizes;
}
| null | 0
|
XRRScreenSize *XRRConfigSizes(XRRScreenConfiguration *config, int *nsizes)
{
*nsizes = config->nsizes;
return config->sizes;
}
|
@@ -29,6 +29,7 @@
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
@@ -272,23 +273,30 @@ static XRRScreenConfiguration *_XRRGetScreenInfo (Display *dpy,
rep.rate = 0;
rep.nrateEnts = 0;
}
+ if (rep.length < INT_MAX >> 2) {
+ nbytes = (long) rep.length << 2;
- nbytes = (long) rep.length << 2;
+ nbytesRead = (long) (rep.nSizes * SIZEOF (xScreenSizes) +
+ ((rep.nrateEnts + 1)& ~1) * 2 /* SIZEOF(CARD16) */);
- nbytesRead = (long) (rep.nSizes * SIZEOF (xScreenSizes) +
- ((rep.nrateEnts + 1)& ~1) * 2 /* SIZEOF (CARD16) */);
+ /*
+ * first we must compute how much space to allocate for
+ * randr library's use; we'll allocate the structures in a single
+ * allocation, on cleanlyness grounds.
+ */
- /*
- * first we must compute how much space to allocate for
- * randr library's use; we'll allocate the structures in a single
- * allocation, on cleanlyness grounds.
- */
+ rbytes = sizeof (XRRScreenConfiguration) +
+ (rep.nSizes * sizeof (XRRScreenSize) +
+ rep.nrateEnts * sizeof (int));
- rbytes = sizeof (XRRScreenConfiguration) +
- (rep.nSizes * sizeof (XRRScreenSize) +
- rep.nrateEnts * sizeof (int));
+ scp = (struct _XRRScreenConfiguration *) Xmalloc(rbytes);
+ } else {
+ nbytes = 0;
+ nbytesRead = 0;
+ rbytes = 0;
+ scp = NULL;
+ }
- scp = (struct _XRRScreenConfiguration *) Xmalloc(rbytes);
if (scp == NULL) {
_XEatData (dpy, (unsigned long) nbytes);
return NULL;
|
CWE-787
| null | null |
6,601
|
Time XRRConfigTimes (XRRScreenConfiguration *config, Time *config_timestamp)
{
*config_timestamp = config->config_timestamp;
return config->timestamp;
}
| null | 0
|
Time XRRConfigTimes (XRRScreenConfiguration *config, Time *config_timestamp)
{
*config_timestamp = config->config_timestamp;
return config->timestamp;
}
|
@@ -29,6 +29,7 @@
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
@@ -272,23 +273,30 @@ static XRRScreenConfiguration *_XRRGetScreenInfo (Display *dpy,
rep.rate = 0;
rep.nrateEnts = 0;
}
+ if (rep.length < INT_MAX >> 2) {
+ nbytes = (long) rep.length << 2;
- nbytes = (long) rep.length << 2;
+ nbytesRead = (long) (rep.nSizes * SIZEOF (xScreenSizes) +
+ ((rep.nrateEnts + 1)& ~1) * 2 /* SIZEOF(CARD16) */);
- nbytesRead = (long) (rep.nSizes * SIZEOF (xScreenSizes) +
- ((rep.nrateEnts + 1)& ~1) * 2 /* SIZEOF (CARD16) */);
+ /*
+ * first we must compute how much space to allocate for
+ * randr library's use; we'll allocate the structures in a single
+ * allocation, on cleanlyness grounds.
+ */
- /*
- * first we must compute how much space to allocate for
- * randr library's use; we'll allocate the structures in a single
- * allocation, on cleanlyness grounds.
- */
+ rbytes = sizeof (XRRScreenConfiguration) +
+ (rep.nSizes * sizeof (XRRScreenSize) +
+ rep.nrateEnts * sizeof (int));
- rbytes = sizeof (XRRScreenConfiguration) +
- (rep.nSizes * sizeof (XRRScreenSize) +
- rep.nrateEnts * sizeof (int));
+ scp = (struct _XRRScreenConfiguration *) Xmalloc(rbytes);
+ } else {
+ nbytes = 0;
+ nbytesRead = 0;
+ rbytes = 0;
+ scp = NULL;
+ }
- scp = (struct _XRRScreenConfiguration *) Xmalloc(rbytes);
if (scp == NULL) {
_XEatData (dpy, (unsigned long) nbytes);
return NULL;
|
CWE-787
| null | null |
6,602
|
short *XRRRates (Display *dpy, int screen, int sizeID, int *nrates)
{
XRRScreenConfiguration *config;
XExtDisplayInfo *info = XRRFindDisplay(dpy);
short *rates;
LockDisplay(dpy);
if ((config = _XRRValidateCache(dpy, info, screen))) {
rates = XRRConfigRates (config, sizeID, nrates);
UnlockDisplay(dpy);
return rates;
}
else {
UnlockDisplay(dpy);
*nrates = 0;
return NULL;
}
}
| null | 0
|
short *XRRRates (Display *dpy, int screen, int sizeID, int *nrates)
{
XRRScreenConfiguration *config;
XExtDisplayInfo *info = XRRFindDisplay(dpy);
short *rates;
LockDisplay(dpy);
if ((config = _XRRValidateCache(dpy, info, screen))) {
rates = XRRConfigRates (config, sizeID, nrates);
UnlockDisplay(dpy);
return rates;
}
else {
UnlockDisplay(dpy);
*nrates = 0;
return NULL;
}
}
|
@@ -29,6 +29,7 @@
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
@@ -272,23 +273,30 @@ static XRRScreenConfiguration *_XRRGetScreenInfo (Display *dpy,
rep.rate = 0;
rep.nrateEnts = 0;
}
+ if (rep.length < INT_MAX >> 2) {
+ nbytes = (long) rep.length << 2;
- nbytes = (long) rep.length << 2;
+ nbytesRead = (long) (rep.nSizes * SIZEOF (xScreenSizes) +
+ ((rep.nrateEnts + 1)& ~1) * 2 /* SIZEOF(CARD16) */);
- nbytesRead = (long) (rep.nSizes * SIZEOF (xScreenSizes) +
- ((rep.nrateEnts + 1)& ~1) * 2 /* SIZEOF (CARD16) */);
+ /*
+ * first we must compute how much space to allocate for
+ * randr library's use; we'll allocate the structures in a single
+ * allocation, on cleanlyness grounds.
+ */
- /*
- * first we must compute how much space to allocate for
- * randr library's use; we'll allocate the structures in a single
- * allocation, on cleanlyness grounds.
- */
+ rbytes = sizeof (XRRScreenConfiguration) +
+ (rep.nSizes * sizeof (XRRScreenSize) +
+ rep.nrateEnts * sizeof (int));
- rbytes = sizeof (XRRScreenConfiguration) +
- (rep.nSizes * sizeof (XRRScreenSize) +
- rep.nrateEnts * sizeof (int));
+ scp = (struct _XRRScreenConfiguration *) Xmalloc(rbytes);
+ } else {
+ nbytes = 0;
+ nbytesRead = 0;
+ rbytes = 0;
+ scp = NULL;
+ }
- scp = (struct _XRRScreenConfiguration *) Xmalloc(rbytes);
if (scp == NULL) {
_XEatData (dpy, (unsigned long) nbytes);
return NULL;
|
CWE-787
| null | null |
6,603
|
Rotation XRRRotations(Display *dpy, int screen, Rotation *current_rotation)
{
XRRScreenConfiguration *config;
XExtDisplayInfo *info = XRRFindDisplay(dpy);
Rotation cr;
LockDisplay(dpy);
if ((config = _XRRValidateCache(dpy, info, screen))) {
*current_rotation = config->current_rotation;
cr = config->rotations;
UnlockDisplay(dpy);
return cr;
}
else {
UnlockDisplay(dpy);
*current_rotation = RR_Rotate_0;
return 0; /* no rotations supported */
}
}
| null | 0
|
Rotation XRRRotations(Display *dpy, int screen, Rotation *current_rotation)
{
XRRScreenConfiguration *config;
XExtDisplayInfo *info = XRRFindDisplay(dpy);
Rotation cr;
LockDisplay(dpy);
if ((config = _XRRValidateCache(dpy, info, screen))) {
*current_rotation = config->current_rotation;
cr = config->rotations;
UnlockDisplay(dpy);
return cr;
}
else {
UnlockDisplay(dpy);
*current_rotation = RR_Rotate_0;
return 0; /* no rotations supported */
}
}
|
@@ -29,6 +29,7 @@
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
@@ -272,23 +273,30 @@ static XRRScreenConfiguration *_XRRGetScreenInfo (Display *dpy,
rep.rate = 0;
rep.nrateEnts = 0;
}
+ if (rep.length < INT_MAX >> 2) {
+ nbytes = (long) rep.length << 2;
- nbytes = (long) rep.length << 2;
+ nbytesRead = (long) (rep.nSizes * SIZEOF (xScreenSizes) +
+ ((rep.nrateEnts + 1)& ~1) * 2 /* SIZEOF(CARD16) */);
- nbytesRead = (long) (rep.nSizes * SIZEOF (xScreenSizes) +
- ((rep.nrateEnts + 1)& ~1) * 2 /* SIZEOF (CARD16) */);
+ /*
+ * first we must compute how much space to allocate for
+ * randr library's use; we'll allocate the structures in a single
+ * allocation, on cleanlyness grounds.
+ */
- /*
- * first we must compute how much space to allocate for
- * randr library's use; we'll allocate the structures in a single
- * allocation, on cleanlyness grounds.
- */
+ rbytes = sizeof (XRRScreenConfiguration) +
+ (rep.nSizes * sizeof (XRRScreenSize) +
+ rep.nrateEnts * sizeof (int));
- rbytes = sizeof (XRRScreenConfiguration) +
- (rep.nSizes * sizeof (XRRScreenSize) +
- rep.nrateEnts * sizeof (int));
+ scp = (struct _XRRScreenConfiguration *) Xmalloc(rbytes);
+ } else {
+ nbytes = 0;
+ nbytesRead = 0;
+ rbytes = 0;
+ scp = NULL;
+ }
- scp = (struct _XRRScreenConfiguration *) Xmalloc(rbytes);
if (scp == NULL) {
_XEatData (dpy, (unsigned long) nbytes);
return NULL;
|
CWE-787
| null | null |
6,604
|
XRRScreenSize *XRRSizes(Display *dpy, int screen, int *nsizes)
{
XRRScreenConfiguration *config;
XExtDisplayInfo *info = XRRFindDisplay(dpy);
XRRScreenSize *sizes;
LockDisplay(dpy);
if ((config = _XRRValidateCache(dpy, info, screen))) {
*nsizes = config->nsizes;
sizes = config->sizes;
UnlockDisplay(dpy);
return sizes;
}
else {
UnlockDisplay(dpy);
*nsizes = 0;
return NULL;
}
}
| null | 0
|
XRRScreenSize *XRRSizes(Display *dpy, int screen, int *nsizes)
{
XRRScreenConfiguration *config;
XExtDisplayInfo *info = XRRFindDisplay(dpy);
XRRScreenSize *sizes;
LockDisplay(dpy);
if ((config = _XRRValidateCache(dpy, info, screen))) {
*nsizes = config->nsizes;
sizes = config->sizes;
UnlockDisplay(dpy);
return sizes;
}
else {
UnlockDisplay(dpy);
*nsizes = 0;
return NULL;
}
}
|
@@ -29,6 +29,7 @@
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
@@ -272,23 +273,30 @@ static XRRScreenConfiguration *_XRRGetScreenInfo (Display *dpy,
rep.rate = 0;
rep.nrateEnts = 0;
}
+ if (rep.length < INT_MAX >> 2) {
+ nbytes = (long) rep.length << 2;
- nbytes = (long) rep.length << 2;
+ nbytesRead = (long) (rep.nSizes * SIZEOF (xScreenSizes) +
+ ((rep.nrateEnts + 1)& ~1) * 2 /* SIZEOF(CARD16) */);
- nbytesRead = (long) (rep.nSizes * SIZEOF (xScreenSizes) +
- ((rep.nrateEnts + 1)& ~1) * 2 /* SIZEOF (CARD16) */);
+ /*
+ * first we must compute how much space to allocate for
+ * randr library's use; we'll allocate the structures in a single
+ * allocation, on cleanlyness grounds.
+ */
- /*
- * first we must compute how much space to allocate for
- * randr library's use; we'll allocate the structures in a single
- * allocation, on cleanlyness grounds.
- */
+ rbytes = sizeof (XRRScreenConfiguration) +
+ (rep.nSizes * sizeof (XRRScreenSize) +
+ rep.nrateEnts * sizeof (int));
- rbytes = sizeof (XRRScreenConfiguration) +
- (rep.nSizes * sizeof (XRRScreenSize) +
- rep.nrateEnts * sizeof (int));
+ scp = (struct _XRRScreenConfiguration *) Xmalloc(rbytes);
+ } else {
+ nbytes = 0;
+ nbytesRead = 0;
+ rbytes = 0;
+ scp = NULL;
+ }
- scp = (struct _XRRScreenConfiguration *) Xmalloc(rbytes);
if (scp == NULL) {
_XEatData (dpy, (unsigned long) nbytes);
return NULL;
|
CWE-787
| null | null |
6,605
|
Time XRRTimes (Display *dpy, int screen, Time *config_timestamp)
{
XRRScreenConfiguration *config;
XExtDisplayInfo *info = XRRFindDisplay(dpy);
Time ts;
LockDisplay(dpy);
if ((config = _XRRValidateCache(dpy, info, screen))) {
*config_timestamp = config->config_timestamp;
ts = config->timestamp;
UnlockDisplay(dpy);
return ts;
} else {
UnlockDisplay(dpy);
return CurrentTime;
}
}
| null | 0
|
Time XRRTimes (Display *dpy, int screen, Time *config_timestamp)
{
XRRScreenConfiguration *config;
XExtDisplayInfo *info = XRRFindDisplay(dpy);
Time ts;
LockDisplay(dpy);
if ((config = _XRRValidateCache(dpy, info, screen))) {
*config_timestamp = config->config_timestamp;
ts = config->timestamp;
UnlockDisplay(dpy);
return ts;
} else {
UnlockDisplay(dpy);
return CurrentTime;
}
}
|
@@ -29,6 +29,7 @@
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
@@ -272,23 +273,30 @@ static XRRScreenConfiguration *_XRRGetScreenInfo (Display *dpy,
rep.rate = 0;
rep.nrateEnts = 0;
}
+ if (rep.length < INT_MAX >> 2) {
+ nbytes = (long) rep.length << 2;
- nbytes = (long) rep.length << 2;
+ nbytesRead = (long) (rep.nSizes * SIZEOF (xScreenSizes) +
+ ((rep.nrateEnts + 1)& ~1) * 2 /* SIZEOF(CARD16) */);
- nbytesRead = (long) (rep.nSizes * SIZEOF (xScreenSizes) +
- ((rep.nrateEnts + 1)& ~1) * 2 /* SIZEOF (CARD16) */);
+ /*
+ * first we must compute how much space to allocate for
+ * randr library's use; we'll allocate the structures in a single
+ * allocation, on cleanlyness grounds.
+ */
- /*
- * first we must compute how much space to allocate for
- * randr library's use; we'll allocate the structures in a single
- * allocation, on cleanlyness grounds.
- */
+ rbytes = sizeof (XRRScreenConfiguration) +
+ (rep.nSizes * sizeof (XRRScreenSize) +
+ rep.nrateEnts * sizeof (int));
- rbytes = sizeof (XRRScreenConfiguration) +
- (rep.nSizes * sizeof (XRRScreenSize) +
- rep.nrateEnts * sizeof (int));
+ scp = (struct _XRRScreenConfiguration *) Xmalloc(rbytes);
+ } else {
+ nbytes = 0;
+ nbytesRead = 0;
+ rbytes = 0;
+ scp = NULL;
+ }
- scp = (struct _XRRScreenConfiguration *) Xmalloc(rbytes);
if (scp == NULL) {
_XEatData (dpy, (unsigned long) nbytes);
return NULL;
|
CWE-787
| null | null |
6,606
|
XRRAllocateMonitor(Display *dpy, int noutput)
{
XRRMonitorInfo *monitor = calloc(1, sizeof (XRRMonitorInfo) + noutput * sizeof (RROutput));
if (!monitor)
return NULL;
monitor->outputs = (RROutput *) (monitor + 1);
monitor->noutput = noutput;
return monitor;
}
| null | 0
|
XRRAllocateMonitor(Display *dpy, int noutput)
{
XRRMonitorInfo *monitor = calloc(1, sizeof (XRRMonitorInfo) + noutput * sizeof (RROutput));
if (!monitor)
return NULL;
monitor->outputs = (RROutput *) (monitor + 1);
monitor->noutput = noutput;
return monitor;
}
|
@@ -24,6 +24,7 @@
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
@@ -65,6 +66,15 @@ XRRGetMonitors(Display *dpy, Window window, Bool get_active, int *nmonitors)
return NULL;
}
+ if (rep.length > INT_MAX >> 2 ||
+ rep.nmonitors > INT_MAX / SIZEOF(xRRMonitorInfo) ||
+ rep.noutputs > INT_MAX / 4 ||
+ rep.nmonitors * SIZEOF(xRRMonitorInfo) > INT_MAX - rep.noutputs * 4) {
+ _XEatData (dpy, rep.length);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
nbytes = (long) rep.length << 2;
nmon = rep.nmonitors;
noutput = rep.noutputs;
@@ -111,6 +121,14 @@ XRRGetMonitors(Display *dpy, Window window, Bool get_active, int *nmonitors)
mon[m].outputs = output;
buf += SIZEOF (xRRMonitorInfo);
xoutput = (CARD32 *) buf;
+ if (xmon->noutput > rep.noutputs) {
+ Xfree(buf);
+ Xfree(mon);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+ rep.noutputs -= xmon->noutput;
for (o = 0; o < xmon->noutput; o++)
output[o] = xoutput[o];
output += xmon->noutput;
|
CWE-787
| null | null |
6,607
|
XRRDeleteMonitor(Display *dpy, Window window, Atom name)
{
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRDeleteMonitorReq *req;
RRSimpleCheckExtension (dpy, info);
LockDisplay(dpy);
GetReq (RRDeleteMonitor, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRDeleteMonitor;
req->window = window;
req->name = name;
UnlockDisplay (dpy);
SyncHandle ();
}
| null | 0
|
XRRDeleteMonitor(Display *dpy, Window window, Atom name)
{
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRDeleteMonitorReq *req;
RRSimpleCheckExtension (dpy, info);
LockDisplay(dpy);
GetReq (RRDeleteMonitor, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRDeleteMonitor;
req->window = window;
req->name = name;
UnlockDisplay (dpy);
SyncHandle ();
}
|
@@ -24,6 +24,7 @@
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
@@ -65,6 +66,15 @@ XRRGetMonitors(Display *dpy, Window window, Bool get_active, int *nmonitors)
return NULL;
}
+ if (rep.length > INT_MAX >> 2 ||
+ rep.nmonitors > INT_MAX / SIZEOF(xRRMonitorInfo) ||
+ rep.noutputs > INT_MAX / 4 ||
+ rep.nmonitors * SIZEOF(xRRMonitorInfo) > INT_MAX - rep.noutputs * 4) {
+ _XEatData (dpy, rep.length);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
nbytes = (long) rep.length << 2;
nmon = rep.nmonitors;
noutput = rep.noutputs;
@@ -111,6 +121,14 @@ XRRGetMonitors(Display *dpy, Window window, Bool get_active, int *nmonitors)
mon[m].outputs = output;
buf += SIZEOF (xRRMonitorInfo);
xoutput = (CARD32 *) buf;
+ if (xmon->noutput > rep.noutputs) {
+ Xfree(buf);
+ Xfree(mon);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+ rep.noutputs -= xmon->noutput;
for (o = 0; o < xmon->noutput; o++)
output[o] = xoutput[o];
output += xmon->noutput;
|
CWE-787
| null | null |
6,608
|
XRRFreeMonitors(XRRMonitorInfo *monitors)
{
Xfree(monitors);
}
| null | 0
|
XRRFreeMonitors(XRRMonitorInfo *monitors)
{
Xfree(monitors);
}
|
@@ -24,6 +24,7 @@
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
@@ -65,6 +66,15 @@ XRRGetMonitors(Display *dpy, Window window, Bool get_active, int *nmonitors)
return NULL;
}
+ if (rep.length > INT_MAX >> 2 ||
+ rep.nmonitors > INT_MAX / SIZEOF(xRRMonitorInfo) ||
+ rep.noutputs > INT_MAX / 4 ||
+ rep.nmonitors * SIZEOF(xRRMonitorInfo) > INT_MAX - rep.noutputs * 4) {
+ _XEatData (dpy, rep.length);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
nbytes = (long) rep.length << 2;
nmon = rep.nmonitors;
noutput = rep.noutputs;
@@ -111,6 +121,14 @@ XRRGetMonitors(Display *dpy, Window window, Bool get_active, int *nmonitors)
mon[m].outputs = output;
buf += SIZEOF (xRRMonitorInfo);
xoutput = (CARD32 *) buf;
+ if (xmon->noutput > rep.noutputs) {
+ Xfree(buf);
+ Xfree(mon);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+ rep.noutputs -= xmon->noutput;
for (o = 0; o < xmon->noutput; o++)
output[o] = xoutput[o];
output += xmon->noutput;
|
CWE-787
| null | null |
6,609
|
XRRSetMonitor(Display *dpy, Window window, XRRMonitorInfo *monitor)
{
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRSetMonitorReq *req;
RRSimpleCheckExtension (dpy, info);
LockDisplay(dpy);
GetReq (RRSetMonitor, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRSetMonitor;
req->length += monitor->noutput;
req->window = window;
req->monitor.name = monitor->name;
req->monitor.primary = monitor->primary;
req->monitor.automatic = False;
req->monitor.noutput = monitor->noutput;
req->monitor.x = monitor->x;
req->monitor.y = monitor->y;
req->monitor.width = monitor->width;
req->monitor.height = monitor->height;
req->monitor.widthInMillimeters = monitor->mwidth;
req->monitor.heightInMillimeters = monitor->mheight;
Data32 (dpy, monitor->outputs, monitor->noutput * 4);
UnlockDisplay (dpy);
SyncHandle ();
}
| null | 0
|
XRRSetMonitor(Display *dpy, Window window, XRRMonitorInfo *monitor)
{
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRSetMonitorReq *req;
RRSimpleCheckExtension (dpy, info);
LockDisplay(dpy);
GetReq (RRSetMonitor, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRSetMonitor;
req->length += monitor->noutput;
req->window = window;
req->monitor.name = monitor->name;
req->monitor.primary = monitor->primary;
req->monitor.automatic = False;
req->monitor.noutput = monitor->noutput;
req->monitor.x = monitor->x;
req->monitor.y = monitor->y;
req->monitor.width = monitor->width;
req->monitor.height = monitor->height;
req->monitor.widthInMillimeters = monitor->mwidth;
req->monitor.heightInMillimeters = monitor->mheight;
Data32 (dpy, monitor->outputs, monitor->noutput * 4);
UnlockDisplay (dpy);
SyncHandle ();
}
|
@@ -24,6 +24,7 @@
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
@@ -65,6 +66,15 @@ XRRGetMonitors(Display *dpy, Window window, Bool get_active, int *nmonitors)
return NULL;
}
+ if (rep.length > INT_MAX >> 2 ||
+ rep.nmonitors > INT_MAX / SIZEOF(xRRMonitorInfo) ||
+ rep.noutputs > INT_MAX / 4 ||
+ rep.nmonitors * SIZEOF(xRRMonitorInfo) > INT_MAX - rep.noutputs * 4) {
+ _XEatData (dpy, rep.length);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
nbytes = (long) rep.length << 2;
nmon = rep.nmonitors;
noutput = rep.noutputs;
@@ -111,6 +121,14 @@ XRRGetMonitors(Display *dpy, Window window, Bool get_active, int *nmonitors)
mon[m].outputs = output;
buf += SIZEOF (xRRMonitorInfo);
xoutput = (CARD32 *) buf;
+ if (xmon->noutput > rep.noutputs) {
+ Xfree(buf);
+ Xfree(mon);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+ rep.noutputs -= xmon->noutput;
for (o = 0; o < xmon->noutput; o++)
output[o] = xoutput[o];
output += xmon->noutput;
|
CWE-787
| null | null |
6,610
|
XRRFreeOutputInfo (XRROutputInfo *outputInfo)
{
Xfree (outputInfo);
}
| null | 0
|
XRRFreeOutputInfo (XRROutputInfo *outputInfo)
{
Xfree (outputInfo);
}
|
@@ -25,6 +25,7 @@
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
@@ -60,6 +61,16 @@ XRRGetOutputInfo (Display *dpy, XRRScreenResources *resources, RROutput output)
return NULL;
}
+ if (rep.length > INT_MAX >> 2 || rep.length < (OutputInfoExtra >> 2))
+ {
+ if (rep.length > (OutputInfoExtra >> 2))
+ _XEatDataWords (dpy, rep.length - (OutputInfoExtra >> 2));
+ else
+ _XEatDataWords (dpy, rep.length);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
nbytes = ((long) (rep.length) << 2) - OutputInfoExtra;
nbytesRead = (long) (rep.nCrtcs * 4 +
|
CWE-787
| null | null |
6,611
|
XRRGetOutputPrimary(Display *dpy, Window window)
{
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRGetOutputPrimaryReq *req;
xRRGetOutputPrimaryReply rep;
int major_version, minor_version;
RRCheckExtension (dpy, info, 0);
if (!XRRQueryVersion (dpy, &major_version, &minor_version) ||
!_XRRHasOutputPrimary (major_version, minor_version))
return None;
LockDisplay(dpy);
GetReq (RRGetOutputPrimary, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRGetOutputPrimary;
req->window = window;
if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))
rep.output = None;
UnlockDisplay(dpy);
SyncHandle();
return rep.output;
}
| null | 0
|
XRRGetOutputPrimary(Display *dpy, Window window)
{
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRGetOutputPrimaryReq *req;
xRRGetOutputPrimaryReply rep;
int major_version, minor_version;
RRCheckExtension (dpy, info, 0);
if (!XRRQueryVersion (dpy, &major_version, &minor_version) ||
!_XRRHasOutputPrimary (major_version, minor_version))
return None;
LockDisplay(dpy);
GetReq (RRGetOutputPrimary, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRGetOutputPrimary;
req->window = window;
if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))
rep.output = None;
UnlockDisplay(dpy);
SyncHandle();
return rep.output;
}
|
@@ -25,6 +25,7 @@
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
@@ -60,6 +61,16 @@ XRRGetOutputInfo (Display *dpy, XRRScreenResources *resources, RROutput output)
return NULL;
}
+ if (rep.length > INT_MAX >> 2 || rep.length < (OutputInfoExtra >> 2))
+ {
+ if (rep.length > (OutputInfoExtra >> 2))
+ _XEatDataWords (dpy, rep.length - (OutputInfoExtra >> 2));
+ else
+ _XEatDataWords (dpy, rep.length);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
nbytes = ((long) (rep.length) << 2) - OutputInfoExtra;
nbytesRead = (long) (rep.nCrtcs * 4 +
|
CWE-787
| null | null |
6,612
|
XRRSetOutputPrimary(Display *dpy, Window window, RROutput output)
{
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRSetOutputPrimaryReq *req;
int major_version, minor_version;
RRSimpleCheckExtension (dpy, info);
if (!XRRQueryVersion (dpy, &major_version, &minor_version) ||
!_XRRHasOutputPrimary (major_version, minor_version))
return;
LockDisplay(dpy);
GetReq (RRSetOutputPrimary, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRSetOutputPrimary;
req->window = window;
req->output = output;
UnlockDisplay (dpy);
SyncHandle ();
}
| null | 0
|
XRRSetOutputPrimary(Display *dpy, Window window, RROutput output)
{
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRSetOutputPrimaryReq *req;
int major_version, minor_version;
RRSimpleCheckExtension (dpy, info);
if (!XRRQueryVersion (dpy, &major_version, &minor_version) ||
!_XRRHasOutputPrimary (major_version, minor_version))
return;
LockDisplay(dpy);
GetReq (RRSetOutputPrimary, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRSetOutputPrimary;
req->window = window;
req->output = output;
UnlockDisplay (dpy);
SyncHandle ();
}
|
@@ -25,6 +25,7 @@
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
@@ -60,6 +61,16 @@ XRRGetOutputInfo (Display *dpy, XRRScreenResources *resources, RROutput output)
return NULL;
}
+ if (rep.length > INT_MAX >> 2 || rep.length < (OutputInfoExtra >> 2))
+ {
+ if (rep.length > (OutputInfoExtra >> 2))
+ _XEatDataWords (dpy, rep.length - (OutputInfoExtra >> 2));
+ else
+ _XEatDataWords (dpy, rep.length);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
nbytes = ((long) (rep.length) << 2) - OutputInfoExtra;
nbytesRead = (long) (rep.nCrtcs * 4 +
|
CWE-787
| null | null |
6,613
|
_XRRHasOutputPrimary (int major, int minor)
{
return major > 1 || (major == 1 && minor >= 3);
}
| null | 0
|
_XRRHasOutputPrimary (int major, int minor)
{
return major > 1 || (major == 1 && minor >= 3);
}
|
@@ -25,6 +25,7 @@
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
@@ -60,6 +61,16 @@ XRRGetOutputInfo (Display *dpy, XRRScreenResources *resources, RROutput output)
return NULL;
}
+ if (rep.length > INT_MAX >> 2 || rep.length < (OutputInfoExtra >> 2))
+ {
+ if (rep.length > (OutputInfoExtra >> 2))
+ _XEatDataWords (dpy, rep.length - (OutputInfoExtra >> 2));
+ else
+ _XEatDataWords (dpy, rep.length);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
nbytes = ((long) (rep.length) << 2) - OutputInfoExtra;
nbytesRead = (long) (rep.nCrtcs * 4 +
|
CWE-787
| null | null |
6,614
|
XRRFreeProviderInfo(XRRProviderInfo *provider)
{
free(provider);
}
| null | 0
|
XRRFreeProviderInfo(XRRProviderInfo *provider)
{
free(provider);
}
|
@@ -25,6 +25,7 @@
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
@@ -59,12 +60,20 @@ XRRGetProviderResources(Display *dpy, Window window)
return NULL;
}
- nbytes = (long) rep.length << 2;
+ if (rep.length < INT_MAX >> 2) {
+ nbytes = (long) rep.length << 2;
- nbytesRead = (long) (rep.nProviders * 4);
+ nbytesRead = (long) (rep.nProviders * 4);
- rbytes = (sizeof(XRRProviderResources) + rep.nProviders * sizeof(RRProvider));
- xrpr = (XRRProviderResources *) Xmalloc(rbytes);
+ rbytes = (sizeof(XRRProviderResources) + rep.nProviders *
+ sizeof(RRProvider));
+ xrpr = (XRRProviderResources *) Xmalloc(rbytes);
+ } else {
+ nbytes = 0;
+ nbytesRead = 0;
+ rbytes = 0;
+ xrpr = NULL;
+ }
if (xrpr == NULL) {
_XEatDataWords (dpy, rep.length);
@@ -121,6 +130,17 @@ XRRGetProviderInfo(Display *dpy, XRRScreenResources *resources, RRProvider provi
return NULL;
}
+ if (rep.length > INT_MAX >> 2 || rep.length < ProviderInfoExtra >> 2)
+ {
+ if (rep.length < ProviderInfoExtra >> 2)
+ _XEatDataWords (dpy, rep.length);
+ else
+ _XEatDataWords (dpy, rep.length - (ProviderInfoExtra >> 2));
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+
nbytes = ((long) rep.length << 2) - ProviderInfoExtra;
nbytesRead = (long)(rep.nCrtcs * 4 +
|
CWE-787
| null | null |
6,615
|
XRRSetProviderOffloadSink(Display *dpy, XID provider,
XID sink_provider)
{
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRSetProviderOffloadSinkReq *req;
RRCheckExtension (dpy, info, 0);
LockDisplay (dpy);
GetReq (RRSetProviderOffloadSink, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRSetProviderOffloadSink;
req->provider = provider;
req->sink_provider = sink_provider;
UnlockDisplay (dpy);
SyncHandle ();
return 0;
}
| null | 0
|
XRRSetProviderOffloadSink(Display *dpy, XID provider,
XID sink_provider)
{
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRSetProviderOffloadSinkReq *req;
RRCheckExtension (dpy, info, 0);
LockDisplay (dpy);
GetReq (RRSetProviderOffloadSink, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRSetProviderOffloadSink;
req->provider = provider;
req->sink_provider = sink_provider;
UnlockDisplay (dpy);
SyncHandle ();
return 0;
}
|
@@ -25,6 +25,7 @@
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
@@ -59,12 +60,20 @@ XRRGetProviderResources(Display *dpy, Window window)
return NULL;
}
- nbytes = (long) rep.length << 2;
+ if (rep.length < INT_MAX >> 2) {
+ nbytes = (long) rep.length << 2;
- nbytesRead = (long) (rep.nProviders * 4);
+ nbytesRead = (long) (rep.nProviders * 4);
- rbytes = (sizeof(XRRProviderResources) + rep.nProviders * sizeof(RRProvider));
- xrpr = (XRRProviderResources *) Xmalloc(rbytes);
+ rbytes = (sizeof(XRRProviderResources) + rep.nProviders *
+ sizeof(RRProvider));
+ xrpr = (XRRProviderResources *) Xmalloc(rbytes);
+ } else {
+ nbytes = 0;
+ nbytesRead = 0;
+ rbytes = 0;
+ xrpr = NULL;
+ }
if (xrpr == NULL) {
_XEatDataWords (dpy, rep.length);
@@ -121,6 +130,17 @@ XRRGetProviderInfo(Display *dpy, XRRScreenResources *resources, RRProvider provi
return NULL;
}
+ if (rep.length > INT_MAX >> 2 || rep.length < ProviderInfoExtra >> 2)
+ {
+ if (rep.length < ProviderInfoExtra >> 2)
+ _XEatDataWords (dpy, rep.length);
+ else
+ _XEatDataWords (dpy, rep.length - (ProviderInfoExtra >> 2));
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+
nbytes = ((long) rep.length << 2) - ProviderInfoExtra;
nbytesRead = (long)(rep.nCrtcs * 4 +
|
CWE-787
| null | null |
6,616
|
XRRSetProviderOutputSource(Display *dpy, XID provider,
XID source_provider)
{
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRSetProviderOutputSourceReq *req;
RRCheckExtension (dpy, info, 0);
LockDisplay (dpy);
GetReq (RRSetProviderOutputSource, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRSetProviderOutputSource;
req->provider = provider;
req->source_provider = source_provider;
UnlockDisplay (dpy);
SyncHandle ();
return 0;
}
| null | 0
|
XRRSetProviderOutputSource(Display *dpy, XID provider,
XID source_provider)
{
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRSetProviderOutputSourceReq *req;
RRCheckExtension (dpy, info, 0);
LockDisplay (dpy);
GetReq (RRSetProviderOutputSource, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRSetProviderOutputSource;
req->provider = provider;
req->source_provider = source_provider;
UnlockDisplay (dpy);
SyncHandle ();
return 0;
}
|
@@ -25,6 +25,7 @@
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
@@ -59,12 +60,20 @@ XRRGetProviderResources(Display *dpy, Window window)
return NULL;
}
- nbytes = (long) rep.length << 2;
+ if (rep.length < INT_MAX >> 2) {
+ nbytes = (long) rep.length << 2;
- nbytesRead = (long) (rep.nProviders * 4);
+ nbytesRead = (long) (rep.nProviders * 4);
- rbytes = (sizeof(XRRProviderResources) + rep.nProviders * sizeof(RRProvider));
- xrpr = (XRRProviderResources *) Xmalloc(rbytes);
+ rbytes = (sizeof(XRRProviderResources) + rep.nProviders *
+ sizeof(RRProvider));
+ xrpr = (XRRProviderResources *) Xmalloc(rbytes);
+ } else {
+ nbytes = 0;
+ nbytesRead = 0;
+ rbytes = 0;
+ xrpr = NULL;
+ }
if (xrpr == NULL) {
_XEatDataWords (dpy, rep.length);
@@ -121,6 +130,17 @@ XRRGetProviderInfo(Display *dpy, XRRScreenResources *resources, RRProvider provi
return NULL;
}
+ if (rep.length > INT_MAX >> 2 || rep.length < ProviderInfoExtra >> 2)
+ {
+ if (rep.length < ProviderInfoExtra >> 2)
+ _XEatDataWords (dpy, rep.length);
+ else
+ _XEatDataWords (dpy, rep.length - (ProviderInfoExtra >> 2));
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+
nbytes = ((long) rep.length << 2) - ProviderInfoExtra;
nbytesRead = (long)(rep.nCrtcs * 4 +
|
CWE-787
| null | null |
6,617
|
XFixesCopyRegion (Display *dpy, XserverRegion dst, XserverRegion src)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesCopyRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesCopyRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesCopyRegion;
req->source = src;
req->destination = dst;
UnlockDisplay (dpy);
SyncHandle();
}
|
Overflow +Priv
| 0
|
XFixesCopyRegion (Display *dpy, XserverRegion dst, XserverRegion src)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesCopyRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesCopyRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesCopyRegion;
req->source = src;
req->destination = dst;
UnlockDisplay (dpy);
SyncHandle();
}
|
@@ -23,6 +23,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xfixesint.h"
XserverRegion
@@ -333,9 +334,17 @@ XFixesFetchRegionAndBounds (Display *dpy,
bounds->y = rep.y;
bounds->width = rep.width;
bounds->height = rep.height;
- nbytes = (long) rep.length << 2;
- nrects = rep.length >> 1;
- rects = Xmalloc (nrects * sizeof (XRectangle));
+
+ if (rep.length < (INT_MAX >> 2)) {
+ nbytes = (long) rep.length << 2;
+ nrects = rep.length >> 1;
+ rects = Xmalloc (nrects * sizeof (XRectangle));
+ } else {
+ nbytes = 0;
+ nrects = 0;
+ rects = NULL;
+ }
+
if (!rects)
{
_XEatDataWords(dpy, rep.length);
|
CWE-190
| null | null |
6,618
|
XFixesCreateRegionFromBitmap (Display *dpy, Pixmap bitmap)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesCreateRegionFromBitmapReq *req;
XserverRegion region;
XFixesCheckExtension (dpy, info, 0);
LockDisplay (dpy);
GetReq (XFixesCreateRegionFromBitmap, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesCreateRegionFromBitmap;
region = req->region = XAllocID (dpy);
req->bitmap = bitmap;
UnlockDisplay (dpy);
SyncHandle();
return region;
}
|
Overflow +Priv
| 0
|
XFixesCreateRegionFromBitmap (Display *dpy, Pixmap bitmap)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesCreateRegionFromBitmapReq *req;
XserverRegion region;
XFixesCheckExtension (dpy, info, 0);
LockDisplay (dpy);
GetReq (XFixesCreateRegionFromBitmap, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesCreateRegionFromBitmap;
region = req->region = XAllocID (dpy);
req->bitmap = bitmap;
UnlockDisplay (dpy);
SyncHandle();
return region;
}
|
@@ -23,6 +23,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xfixesint.h"
XserverRegion
@@ -333,9 +334,17 @@ XFixesFetchRegionAndBounds (Display *dpy,
bounds->y = rep.y;
bounds->width = rep.width;
bounds->height = rep.height;
- nbytes = (long) rep.length << 2;
- nrects = rep.length >> 1;
- rects = Xmalloc (nrects * sizeof (XRectangle));
+
+ if (rep.length < (INT_MAX >> 2)) {
+ nbytes = (long) rep.length << 2;
+ nrects = rep.length >> 1;
+ rects = Xmalloc (nrects * sizeof (XRectangle));
+ } else {
+ nbytes = 0;
+ nrects = 0;
+ rects = NULL;
+ }
+
if (!rects)
{
_XEatDataWords(dpy, rep.length);
|
CWE-190
| null | null |
6,619
|
XFixesCreateRegionFromGC (Display *dpy, GC gc)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesCreateRegionFromGCReq *req;
XserverRegion region;
XFixesCheckExtension (dpy, info, 0);
LockDisplay (dpy);
GetReq (XFixesCreateRegionFromGC, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesCreateRegionFromGC;
region = req->region = XAllocID (dpy);
req->gc = gc->gid;
UnlockDisplay (dpy);
SyncHandle();
return region;
}
|
Overflow +Priv
| 0
|
XFixesCreateRegionFromGC (Display *dpy, GC gc)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesCreateRegionFromGCReq *req;
XserverRegion region;
XFixesCheckExtension (dpy, info, 0);
LockDisplay (dpy);
GetReq (XFixesCreateRegionFromGC, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesCreateRegionFromGC;
region = req->region = XAllocID (dpy);
req->gc = gc->gid;
UnlockDisplay (dpy);
SyncHandle();
return region;
}
|
@@ -23,6 +23,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xfixesint.h"
XserverRegion
@@ -333,9 +334,17 @@ XFixesFetchRegionAndBounds (Display *dpy,
bounds->y = rep.y;
bounds->width = rep.width;
bounds->height = rep.height;
- nbytes = (long) rep.length << 2;
- nrects = rep.length >> 1;
- rects = Xmalloc (nrects * sizeof (XRectangle));
+
+ if (rep.length < (INT_MAX >> 2)) {
+ nbytes = (long) rep.length << 2;
+ nrects = rep.length >> 1;
+ rects = Xmalloc (nrects * sizeof (XRectangle));
+ } else {
+ nbytes = 0;
+ nrects = 0;
+ rects = NULL;
+ }
+
if (!rects)
{
_XEatDataWords(dpy, rep.length);
|
CWE-190
| null | null |
6,620
|
XFixesCreateRegionFromPicture (Display *dpy, XID picture)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesCreateRegionFromPictureReq *req;
XserverRegion region;
XFixesCheckExtension (dpy, info, 0);
LockDisplay (dpy);
GetReq (XFixesCreateRegionFromPicture, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesCreateRegionFromPicture;
region = req->region = XAllocID (dpy);
req->picture = picture;
UnlockDisplay (dpy);
SyncHandle();
return region;
}
|
Overflow +Priv
| 0
|
XFixesCreateRegionFromPicture (Display *dpy, XID picture)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesCreateRegionFromPictureReq *req;
XserverRegion region;
XFixesCheckExtension (dpy, info, 0);
LockDisplay (dpy);
GetReq (XFixesCreateRegionFromPicture, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesCreateRegionFromPicture;
region = req->region = XAllocID (dpy);
req->picture = picture;
UnlockDisplay (dpy);
SyncHandle();
return region;
}
|
@@ -23,6 +23,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xfixesint.h"
XserverRegion
@@ -333,9 +334,17 @@ XFixesFetchRegionAndBounds (Display *dpy,
bounds->y = rep.y;
bounds->width = rep.width;
bounds->height = rep.height;
- nbytes = (long) rep.length << 2;
- nrects = rep.length >> 1;
- rects = Xmalloc (nrects * sizeof (XRectangle));
+
+ if (rep.length < (INT_MAX >> 2)) {
+ nbytes = (long) rep.length << 2;
+ nrects = rep.length >> 1;
+ rects = Xmalloc (nrects * sizeof (XRectangle));
+ } else {
+ nbytes = 0;
+ nrects = 0;
+ rects = NULL;
+ }
+
if (!rects)
{
_XEatDataWords(dpy, rep.length);
|
CWE-190
| null | null |
6,621
|
XFixesCreateRegionFromWindow (Display *dpy, Window window, int kind)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesCreateRegionFromWindowReq *req;
XserverRegion region;
XFixesCheckExtension (dpy, info, 0);
LockDisplay (dpy);
GetReq (XFixesCreateRegionFromWindow, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesCreateRegionFromWindow;
region = req->region = XAllocID (dpy);
req->window = window;
req->kind = kind;
UnlockDisplay (dpy);
SyncHandle();
return region;
}
|
Overflow +Priv
| 0
|
XFixesCreateRegionFromWindow (Display *dpy, Window window, int kind)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesCreateRegionFromWindowReq *req;
XserverRegion region;
XFixesCheckExtension (dpy, info, 0);
LockDisplay (dpy);
GetReq (XFixesCreateRegionFromWindow, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesCreateRegionFromWindow;
region = req->region = XAllocID (dpy);
req->window = window;
req->kind = kind;
UnlockDisplay (dpy);
SyncHandle();
return region;
}
|
@@ -23,6 +23,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xfixesint.h"
XserverRegion
@@ -333,9 +334,17 @@ XFixesFetchRegionAndBounds (Display *dpy,
bounds->y = rep.y;
bounds->width = rep.width;
bounds->height = rep.height;
- nbytes = (long) rep.length << 2;
- nrects = rep.length >> 1;
- rects = Xmalloc (nrects * sizeof (XRectangle));
+
+ if (rep.length < (INT_MAX >> 2)) {
+ nbytes = (long) rep.length << 2;
+ nrects = rep.length >> 1;
+ rects = Xmalloc (nrects * sizeof (XRectangle));
+ } else {
+ nbytes = 0;
+ nrects = 0;
+ rects = NULL;
+ }
+
if (!rects)
{
_XEatDataWords(dpy, rep.length);
|
CWE-190
| null | null |
6,622
|
XFixesDestroyRegion (Display *dpy, XserverRegion region)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesDestroyRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesDestroyRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesDestroyRegion;
req->region = region;
UnlockDisplay (dpy);
SyncHandle();
}
|
Overflow +Priv
| 0
|
XFixesDestroyRegion (Display *dpy, XserverRegion region)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesDestroyRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesDestroyRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesDestroyRegion;
req->region = region;
UnlockDisplay (dpy);
SyncHandle();
}
|
@@ -23,6 +23,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xfixesint.h"
XserverRegion
@@ -333,9 +334,17 @@ XFixesFetchRegionAndBounds (Display *dpy,
bounds->y = rep.y;
bounds->width = rep.width;
bounds->height = rep.height;
- nbytes = (long) rep.length << 2;
- nrects = rep.length >> 1;
- rects = Xmalloc (nrects * sizeof (XRectangle));
+
+ if (rep.length < (INT_MAX >> 2)) {
+ nbytes = (long) rep.length << 2;
+ nrects = rep.length >> 1;
+ rects = Xmalloc (nrects * sizeof (XRectangle));
+ } else {
+ nbytes = 0;
+ nrects = 0;
+ rects = NULL;
+ }
+
if (!rects)
{
_XEatDataWords(dpy, rep.length);
|
CWE-190
| null | null |
6,623
|
XFixesFetchRegion (Display *dpy, XserverRegion region, int *nrectanglesRet)
{
XRectangle bounds;
return XFixesFetchRegionAndBounds (dpy, region, nrectanglesRet, &bounds);
}
|
Overflow +Priv
| 0
|
XFixesFetchRegion (Display *dpy, XserverRegion region, int *nrectanglesRet)
{
XRectangle bounds;
return XFixesFetchRegionAndBounds (dpy, region, nrectanglesRet, &bounds);
}
|
@@ -23,6 +23,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xfixesint.h"
XserverRegion
@@ -333,9 +334,17 @@ XFixesFetchRegionAndBounds (Display *dpy,
bounds->y = rep.y;
bounds->width = rep.width;
bounds->height = rep.height;
- nbytes = (long) rep.length << 2;
- nrects = rep.length >> 1;
- rects = Xmalloc (nrects * sizeof (XRectangle));
+
+ if (rep.length < (INT_MAX >> 2)) {
+ nbytes = (long) rep.length << 2;
+ nrects = rep.length >> 1;
+ rects = Xmalloc (nrects * sizeof (XRectangle));
+ } else {
+ nbytes = 0;
+ nrects = 0;
+ rects = NULL;
+ }
+
if (!rects)
{
_XEatDataWords(dpy, rep.length);
|
CWE-190
| null | null |
6,624
|
XFixesIntersectRegion (Display *dpy, XserverRegion dst,
XserverRegion src1, XserverRegion src2)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesIntersectRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesIntersectRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesIntersectRegion;
req->source1 = src1;
req->source2 = src2;
req->destination = dst;
UnlockDisplay (dpy);
SyncHandle();
}
|
Overflow +Priv
| 0
|
XFixesIntersectRegion (Display *dpy, XserverRegion dst,
XserverRegion src1, XserverRegion src2)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesIntersectRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesIntersectRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesIntersectRegion;
req->source1 = src1;
req->source2 = src2;
req->destination = dst;
UnlockDisplay (dpy);
SyncHandle();
}
|
@@ -23,6 +23,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xfixesint.h"
XserverRegion
@@ -333,9 +334,17 @@ XFixesFetchRegionAndBounds (Display *dpy,
bounds->y = rep.y;
bounds->width = rep.width;
bounds->height = rep.height;
- nbytes = (long) rep.length << 2;
- nrects = rep.length >> 1;
- rects = Xmalloc (nrects * sizeof (XRectangle));
+
+ if (rep.length < (INT_MAX >> 2)) {
+ nbytes = (long) rep.length << 2;
+ nrects = rep.length >> 1;
+ rects = Xmalloc (nrects * sizeof (XRectangle));
+ } else {
+ nbytes = 0;
+ nrects = 0;
+ rects = NULL;
+ }
+
if (!rects)
{
_XEatDataWords(dpy, rep.length);
|
CWE-190
| null | null |
6,625
|
XFixesInvertRegion (Display *dpy, XserverRegion dst,
XRectangle *rect, XserverRegion src)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesInvertRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesInvertRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesInvertRegion;
req->x = rect->x;
req->y = rect->y;
req->width = rect->width;
req->height = rect->height;
req->source = src;
req->destination = dst;
UnlockDisplay (dpy);
SyncHandle();
}
|
Overflow +Priv
| 0
|
XFixesInvertRegion (Display *dpy, XserverRegion dst,
XRectangle *rect, XserverRegion src)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesInvertRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesInvertRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesInvertRegion;
req->x = rect->x;
req->y = rect->y;
req->width = rect->width;
req->height = rect->height;
req->source = src;
req->destination = dst;
UnlockDisplay (dpy);
SyncHandle();
}
|
@@ -23,6 +23,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xfixesint.h"
XserverRegion
@@ -333,9 +334,17 @@ XFixesFetchRegionAndBounds (Display *dpy,
bounds->y = rep.y;
bounds->width = rep.width;
bounds->height = rep.height;
- nbytes = (long) rep.length << 2;
- nrects = rep.length >> 1;
- rects = Xmalloc (nrects * sizeof (XRectangle));
+
+ if (rep.length < (INT_MAX >> 2)) {
+ nbytes = (long) rep.length << 2;
+ nrects = rep.length >> 1;
+ rects = Xmalloc (nrects * sizeof (XRectangle));
+ } else {
+ nbytes = 0;
+ nrects = 0;
+ rects = NULL;
+ }
+
if (!rects)
{
_XEatDataWords(dpy, rep.length);
|
CWE-190
| null | null |
6,626
|
XFixesRegionExtents (Display *dpy, XserverRegion dst, XserverRegion src)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesRegionExtentsReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesRegionExtents, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesRegionExtents;
req->source = src;
req->destination = dst;
UnlockDisplay (dpy);
SyncHandle();
}
|
Overflow +Priv
| 0
|
XFixesRegionExtents (Display *dpy, XserverRegion dst, XserverRegion src)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesRegionExtentsReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesRegionExtents, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesRegionExtents;
req->source = src;
req->destination = dst;
UnlockDisplay (dpy);
SyncHandle();
}
|
@@ -23,6 +23,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xfixesint.h"
XserverRegion
@@ -333,9 +334,17 @@ XFixesFetchRegionAndBounds (Display *dpy,
bounds->y = rep.y;
bounds->width = rep.width;
bounds->height = rep.height;
- nbytes = (long) rep.length << 2;
- nrects = rep.length >> 1;
- rects = Xmalloc (nrects * sizeof (XRectangle));
+
+ if (rep.length < (INT_MAX >> 2)) {
+ nbytes = (long) rep.length << 2;
+ nrects = rep.length >> 1;
+ rects = Xmalloc (nrects * sizeof (XRectangle));
+ } else {
+ nbytes = 0;
+ nrects = 0;
+ rects = NULL;
+ }
+
if (!rects)
{
_XEatDataWords(dpy, rep.length);
|
CWE-190
| null | null |
6,627
|
XFixesSetGCClipRegion (Display *dpy, GC gc,
int clip_x_origin, int clip_y_origin,
XserverRegion region)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesSetGCClipRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesSetGCClipRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesSetGCClipRegion;
req->gc = gc->gid;
req->region = region;
req->xOrigin = clip_x_origin;
req->yOrigin = clip_y_origin;
UnlockDisplay (dpy);
SyncHandle();
}
|
Overflow +Priv
| 0
|
XFixesSetGCClipRegion (Display *dpy, GC gc,
int clip_x_origin, int clip_y_origin,
XserverRegion region)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesSetGCClipRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesSetGCClipRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesSetGCClipRegion;
req->gc = gc->gid;
req->region = region;
req->xOrigin = clip_x_origin;
req->yOrigin = clip_y_origin;
UnlockDisplay (dpy);
SyncHandle();
}
|
@@ -23,6 +23,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xfixesint.h"
XserverRegion
@@ -333,9 +334,17 @@ XFixesFetchRegionAndBounds (Display *dpy,
bounds->y = rep.y;
bounds->width = rep.width;
bounds->height = rep.height;
- nbytes = (long) rep.length << 2;
- nrects = rep.length >> 1;
- rects = Xmalloc (nrects * sizeof (XRectangle));
+
+ if (rep.length < (INT_MAX >> 2)) {
+ nbytes = (long) rep.length << 2;
+ nrects = rep.length >> 1;
+ rects = Xmalloc (nrects * sizeof (XRectangle));
+ } else {
+ nbytes = 0;
+ nrects = 0;
+ rects = NULL;
+ }
+
if (!rects)
{
_XEatDataWords(dpy, rep.length);
|
CWE-190
| null | null |
6,628
|
XFixesSetRegion (Display *dpy, XserverRegion region,
XRectangle *rectangles, int nrectangles)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesSetRegionReq *req;
long len;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesSetRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesSetRegion;
req->region = region;
len = ((long) nrectangles) << 1;
SetReqLen (req, len, len);
len <<= 2;
Data16 (dpy, (short *) rectangles, len);
UnlockDisplay (dpy);
SyncHandle();
}
|
Overflow +Priv
| 0
|
XFixesSetRegion (Display *dpy, XserverRegion region,
XRectangle *rectangles, int nrectangles)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesSetRegionReq *req;
long len;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesSetRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesSetRegion;
req->region = region;
len = ((long) nrectangles) << 1;
SetReqLen (req, len, len);
len <<= 2;
Data16 (dpy, (short *) rectangles, len);
UnlockDisplay (dpy);
SyncHandle();
}
|
@@ -23,6 +23,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xfixesint.h"
XserverRegion
@@ -333,9 +334,17 @@ XFixesFetchRegionAndBounds (Display *dpy,
bounds->y = rep.y;
bounds->width = rep.width;
bounds->height = rep.height;
- nbytes = (long) rep.length << 2;
- nrects = rep.length >> 1;
- rects = Xmalloc (nrects * sizeof (XRectangle));
+
+ if (rep.length < (INT_MAX >> 2)) {
+ nbytes = (long) rep.length << 2;
+ nrects = rep.length >> 1;
+ rects = Xmalloc (nrects * sizeof (XRectangle));
+ } else {
+ nbytes = 0;
+ nrects = 0;
+ rects = NULL;
+ }
+
if (!rects)
{
_XEatDataWords(dpy, rep.length);
|
CWE-190
| null | null |
6,629
|
XFixesSetWindowShapeRegion (Display *dpy, Window win, int shape_kind,
int x_off, int y_off, XserverRegion region)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesSetWindowShapeRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesSetWindowShapeRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesSetWindowShapeRegion;
req->dest = win;
req->destKind = shape_kind;
req->xOff = x_off;
req->yOff = y_off;
req->region = region;
UnlockDisplay (dpy);
SyncHandle();
}
|
Overflow +Priv
| 0
|
XFixesSetWindowShapeRegion (Display *dpy, Window win, int shape_kind,
int x_off, int y_off, XserverRegion region)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesSetWindowShapeRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesSetWindowShapeRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesSetWindowShapeRegion;
req->dest = win;
req->destKind = shape_kind;
req->xOff = x_off;
req->yOff = y_off;
req->region = region;
UnlockDisplay (dpy);
SyncHandle();
}
|
@@ -23,6 +23,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xfixesint.h"
XserverRegion
@@ -333,9 +334,17 @@ XFixesFetchRegionAndBounds (Display *dpy,
bounds->y = rep.y;
bounds->width = rep.width;
bounds->height = rep.height;
- nbytes = (long) rep.length << 2;
- nrects = rep.length >> 1;
- rects = Xmalloc (nrects * sizeof (XRectangle));
+
+ if (rep.length < (INT_MAX >> 2)) {
+ nbytes = (long) rep.length << 2;
+ nrects = rep.length >> 1;
+ rects = Xmalloc (nrects * sizeof (XRectangle));
+ } else {
+ nbytes = 0;
+ nrects = 0;
+ rects = NULL;
+ }
+
if (!rects)
{
_XEatDataWords(dpy, rep.length);
|
CWE-190
| null | null |
6,630
|
XFixesSubtractRegion (Display *dpy, XserverRegion dst,
XserverRegion src1, XserverRegion src2)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesSubtractRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesSubtractRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesSubtractRegion;
req->source1 = src1;
req->source2 = src2;
req->destination = dst;
UnlockDisplay (dpy);
SyncHandle();
}
|
Overflow +Priv
| 0
|
XFixesSubtractRegion (Display *dpy, XserverRegion dst,
XserverRegion src1, XserverRegion src2)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesSubtractRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesSubtractRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesSubtractRegion;
req->source1 = src1;
req->source2 = src2;
req->destination = dst;
UnlockDisplay (dpy);
SyncHandle();
}
|
@@ -23,6 +23,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xfixesint.h"
XserverRegion
@@ -333,9 +334,17 @@ XFixesFetchRegionAndBounds (Display *dpy,
bounds->y = rep.y;
bounds->width = rep.width;
bounds->height = rep.height;
- nbytes = (long) rep.length << 2;
- nrects = rep.length >> 1;
- rects = Xmalloc (nrects * sizeof (XRectangle));
+
+ if (rep.length < (INT_MAX >> 2)) {
+ nbytes = (long) rep.length << 2;
+ nrects = rep.length >> 1;
+ rects = Xmalloc (nrects * sizeof (XRectangle));
+ } else {
+ nbytes = 0;
+ nrects = 0;
+ rects = NULL;
+ }
+
if (!rects)
{
_XEatDataWords(dpy, rep.length);
|
CWE-190
| null | null |
6,631
|
XFixesTranslateRegion (Display *dpy, XserverRegion region, int dx, int dy)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesTranslateRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesTranslateRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesTranslateRegion;
req->region = region;
req->dx = dx;
req->dy = dy;
UnlockDisplay (dpy);
SyncHandle();
}
|
Overflow +Priv
| 0
|
XFixesTranslateRegion (Display *dpy, XserverRegion region, int dx, int dy)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesTranslateRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesTranslateRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesTranslateRegion;
req->region = region;
req->dx = dx;
req->dy = dy;
UnlockDisplay (dpy);
SyncHandle();
}
|
@@ -23,6 +23,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xfixesint.h"
XserverRegion
@@ -333,9 +334,17 @@ XFixesFetchRegionAndBounds (Display *dpy,
bounds->y = rep.y;
bounds->width = rep.width;
bounds->height = rep.height;
- nbytes = (long) rep.length << 2;
- nrects = rep.length >> 1;
- rects = Xmalloc (nrects * sizeof (XRectangle));
+
+ if (rep.length < (INT_MAX >> 2)) {
+ nbytes = (long) rep.length << 2;
+ nrects = rep.length >> 1;
+ rects = Xmalloc (nrects * sizeof (XRectangle));
+ } else {
+ nbytes = 0;
+ nrects = 0;
+ rects = NULL;
+ }
+
if (!rects)
{
_XEatDataWords(dpy, rep.length);
|
CWE-190
| null | null |
6,632
|
XFixesUnionRegion (Display *dpy, XserverRegion dst,
XserverRegion src1, XserverRegion src2)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesUnionRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesUnionRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesUnionRegion;
req->source1 = src1;
req->source2 = src2;
req->destination = dst;
UnlockDisplay (dpy);
SyncHandle();
}
|
Overflow +Priv
| 0
|
XFixesUnionRegion (Display *dpy, XserverRegion dst,
XserverRegion src1, XserverRegion src2)
{
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy);
xXFixesUnionRegionReq *req;
XFixesSimpleCheckExtension (dpy, info);
LockDisplay (dpy);
GetReq (XFixesUnionRegion, req);
req->reqType = info->codes->major_opcode;
req->xfixesReqType = X_XFixesUnionRegion;
req->source1 = src1;
req->source2 = src2;
req->destination = dst;
UnlockDisplay (dpy);
SyncHandle();
}
|
@@ -23,6 +23,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <limits.h>
#include "Xfixesint.h"
XserverRegion
@@ -333,9 +334,17 @@ XFixesFetchRegionAndBounds (Display *dpy,
bounds->y = rep.y;
bounds->width = rep.width;
bounds->height = rep.height;
- nbytes = (long) rep.length << 2;
- nrects = rep.length >> 1;
- rects = Xmalloc (nrects * sizeof (XRectangle));
+
+ if (rep.length < (INT_MAX >> 2)) {
+ nbytes = (long) rep.length << 2;
+ nrects = rep.length >> 1;
+ rects = Xmalloc (nrects * sizeof (XRectangle));
+ } else {
+ nbytes = 0;
+ nrects = 0;
+ rects = NULL;
+ }
+
if (!rects)
{
_XEatDataWords(dpy, rep.length);
|
CWE-190
| null | null |
6,633
|
XDeleteModifiermapEntry(XModifierKeymap *map,
#if NeedWidePrototypes
unsigned int keycode,
#else
KeyCode keycode,
#endif
int modifier)
{
int i,
row = modifier * map->max_keypermod;
for (i=0; i<map->max_keypermod; i++) {
if (map->modifiermap[ row+i ] == keycode)
map->modifiermap[ row+i ] = 0;
}
/* should we shrink the map?? */
return (map);
}
|
+Priv
| 0
|
XDeleteModifiermapEntry(XModifierKeymap *map,
#if NeedWidePrototypes
unsigned int keycode,
#else
KeyCode keycode,
#endif
int modifier)
{
int i,
row = modifier * map->max_keypermod;
for (i=0; i<map->max_keypermod; i++) {
if (map->modifiermap[ row+i ] == keycode)
map->modifiermap[ row+i ] = 0;
}
/* should we shrink the map?? */
return (map);
}
|
@@ -42,7 +42,8 @@ XGetModifierMapping(register Display *dpy)
GetEmptyReq(GetModifierMapping, req);
(void) _XReply (dpy, (xReply *)&rep, 0, xFalse);
- if (rep.length < (INT_MAX >> 2)) {
+ if (rep.length < (INT_MAX >> 2) &&
+ (rep.length >> 1) == rep.numKeyPerModifier) {
nbytes = (unsigned long)rep.length << 2;
res = Xmalloc(sizeof (XModifierKeymap));
if (res)
|
CWE-787
| null | null |
6,634
|
XFreeModifiermap(XModifierKeymap *map)
{
if (map) {
Xfree(map->modifiermap);
Xfree(map);
}
return 1;
}
|
+Priv
| 0
|
XFreeModifiermap(XModifierKeymap *map)
{
if (map) {
Xfree(map->modifiermap);
Xfree(map);
}
return 1;
}
|
@@ -42,7 +42,8 @@ XGetModifierMapping(register Display *dpy)
GetEmptyReq(GetModifierMapping, req);
(void) _XReply (dpy, (xReply *)&rep, 0, xFalse);
- if (rep.length < (INT_MAX >> 2)) {
+ if (rep.length < (INT_MAX >> 2) &&
+ (rep.length >> 1) == rep.numKeyPerModifier) {
nbytes = (unsigned long)rep.length << 2;
res = Xmalloc(sizeof (XModifierKeymap));
if (res)
|
CWE-787
| null | null |
6,635
|
XInsertModifiermapEntry(XModifierKeymap *map,
#if NeedWidePrototypes
unsigned int keycode,
#else
KeyCode keycode,
#endif
int modifier)
{
XModifierKeymap *newmap;
int i,
row = modifier * map->max_keypermod,
newrow,
lastrow;
for (i=0; i<map->max_keypermod; i++) {
if (map->modifiermap[ row+i ] == keycode)
return(map); /* already in the map */
if (map->modifiermap[ row+i ] == 0) {
map->modifiermap[ row+i ] = keycode;
return(map); /* we added it without stretching the map */
}
}
/* stretch the map */
if ((newmap = XNewModifiermap(map->max_keypermod+1)) == NULL)
return (XModifierKeymap *) NULL;
newrow = row = 0;
lastrow = newmap->max_keypermod * 8;
while (newrow < lastrow) {
for (i=0; i<map->max_keypermod; i++)
newmap->modifiermap[ newrow+i ] = map->modifiermap[ row+i ];
newmap->modifiermap[ newrow+i ] = 0;
row += map->max_keypermod;
newrow += newmap->max_keypermod;
}
(void) XFreeModifiermap(map);
newrow = newmap->max_keypermod * modifier + newmap->max_keypermod - 1;
newmap->modifiermap[ newrow ] = keycode;
return(newmap);
}
|
+Priv
| 0
|
XInsertModifiermapEntry(XModifierKeymap *map,
#if NeedWidePrototypes
unsigned int keycode,
#else
KeyCode keycode,
#endif
int modifier)
{
XModifierKeymap *newmap;
int i,
row = modifier * map->max_keypermod,
newrow,
lastrow;
for (i=0; i<map->max_keypermod; i++) {
if (map->modifiermap[ row+i ] == keycode)
return(map); /* already in the map */
if (map->modifiermap[ row+i ] == 0) {
map->modifiermap[ row+i ] = keycode;
return(map); /* we added it without stretching the map */
}
}
/* stretch the map */
if ((newmap = XNewModifiermap(map->max_keypermod+1)) == NULL)
return (XModifierKeymap *) NULL;
newrow = row = 0;
lastrow = newmap->max_keypermod * 8;
while (newrow < lastrow) {
for (i=0; i<map->max_keypermod; i++)
newmap->modifiermap[ newrow+i ] = map->modifiermap[ row+i ];
newmap->modifiermap[ newrow+i ] = 0;
row += map->max_keypermod;
newrow += newmap->max_keypermod;
}
(void) XFreeModifiermap(map);
newrow = newmap->max_keypermod * modifier + newmap->max_keypermod - 1;
newmap->modifiermap[ newrow ] = keycode;
return(newmap);
}
|
@@ -42,7 +42,8 @@ XGetModifierMapping(register Display *dpy)
GetEmptyReq(GetModifierMapping, req);
(void) _XReply (dpy, (xReply *)&rep, 0, xFalse);
- if (rep.length < (INT_MAX >> 2)) {
+ if (rep.length < (INT_MAX >> 2) &&
+ (rep.length >> 1) == rep.numKeyPerModifier) {
nbytes = (unsigned long)rep.length << 2;
res = Xmalloc(sizeof (XModifierKeymap));
if (res)
|
CWE-787
| null | null |
6,636
|
XSetModifierMapping(
register Display *dpy,
register XModifierKeymap *modifier_map)
{
register xSetModifierMappingReq *req;
xSetModifierMappingReply rep;
int mapSize = modifier_map->max_keypermod << 3; /* 8 modifiers */
LockDisplay(dpy);
GetReq(SetModifierMapping, req);
req->length += mapSize >> 2;
req->numKeyPerModifier = modifier_map->max_keypermod;
Data(dpy, modifier_map->modifiermap, mapSize);
(void) _XReply(dpy, (xReply *) & rep,
(SIZEOF(xSetModifierMappingReply) - SIZEOF(xReply)) >> 2, xTrue);
UnlockDisplay(dpy);
SyncHandle();
return (rep.success);
}
|
+Priv
| 0
|
XSetModifierMapping(
register Display *dpy,
register XModifierKeymap *modifier_map)
{
register xSetModifierMappingReq *req;
xSetModifierMappingReply rep;
int mapSize = modifier_map->max_keypermod << 3; /* 8 modifiers */
LockDisplay(dpy);
GetReq(SetModifierMapping, req);
req->length += mapSize >> 2;
req->numKeyPerModifier = modifier_map->max_keypermod;
Data(dpy, modifier_map->modifiermap, mapSize);
(void) _XReply(dpy, (xReply *) & rep,
(SIZEOF(xSetModifierMappingReply) - SIZEOF(xReply)) >> 2, xTrue);
UnlockDisplay(dpy);
SyncHandle();
return (rep.success);
}
|
@@ -42,7 +42,8 @@ XGetModifierMapping(register Display *dpy)
GetEmptyReq(GetModifierMapping, req);
(void) _XReply (dpy, (xReply *)&rep, 0, xFalse);
- if (rep.length < (INT_MAX >> 2)) {
+ if (rep.length < (INT_MAX >> 2) &&
+ (rep.length >> 1) == rep.numKeyPerModifier) {
nbytes = (unsigned long)rep.length << 2;
res = Xmalloc(sizeof (XModifierKeymap));
if (res)
|
CWE-787
| null | null |
6,637
|
static unsigned int Ones( /* HACKMEM 169 */
unsigned long mask)
{
register unsigned long y;
y = (mask >> 1) &033333333333;
y = mask - y - ((y >>1) & 033333333333);
return ((unsigned int) (((y + (y >> 3)) & 030707070707) % 077));
}
|
+Priv
| 0
|
static unsigned int Ones( /* HACKMEM 169 */
unsigned long mask)
{
register unsigned long y;
y = (mask >> 1) &033333333333;
y = mask - y - ((y >>1) & 033333333333);
return ((unsigned int) (((y + (y >> 3)) & 030707070707) % 077));
}
|
@@ -59,6 +59,7 @@ XImage *XGetImage (
char *data;
unsigned long nbytes;
XImage *image;
+ int planes;
LockDisplay(dpy);
GetReq (GetImage, req);
/*
@@ -91,18 +92,28 @@ XImage *XGetImage (
return (XImage *) NULL;
}
_XReadPad (dpy, data, nbytes);
- if (format == XYPixmap)
- image = XCreateImage(dpy, _XVIDtoVisual(dpy, rep.visual),
- Ones (plane_mask &
- (((unsigned long)0xFFFFFFFF) >> (32 - rep.depth))),
- format, 0, data, width, height, dpy->bitmap_pad, 0);
- else /* format == ZPixmap */
- image = XCreateImage (dpy, _XVIDtoVisual(dpy, rep.visual),
- rep.depth, ZPixmap, 0, data, width, height,
- _XGetScanlinePad(dpy, (int) rep.depth), 0);
+ if (format == XYPixmap) {
+ image = XCreateImage(dpy, _XVIDtoVisual(dpy, rep.visual),
+ Ones (plane_mask &
+ (((unsigned long)0xFFFFFFFF) >> (32 - rep.depth))),
+ format, 0, data, width, height, dpy->bitmap_pad, 0);
+ planes = image->depth;
+ } else { /* format == ZPixmap */
+ image = XCreateImage (dpy, _XVIDtoVisual(dpy, rep.visual),
+ rep.depth, ZPixmap, 0, data, width, height,
+ _XGetScanlinePad(dpy, (int) rep.depth), 0);
+ planes = 1;
+ }
if (!image)
Xfree(data);
+ if (planes < 1 || image->height < 1 || image->bytes_per_line < 1 ||
+ INT_MAX / image->height <= image->bytes_per_line ||
+ INT_MAX / planes <= image->height * image->bytes_per_line ||
+ nbytes < planes * image->height * image->bytes_per_line) {
+ XDestroyImage(image);
+ image = NULL;
+ }
UnlockDisplay(dpy);
SyncHandle();
return (image);
|
CWE-787
| null | null |
6,638
|
static void mcf_fec_read_bd(mcf_fec_bd *bd, uint32_t addr)
{
cpu_physical_memory_read(addr, bd, sizeof(*bd));
be16_to_cpus(&bd->flags);
be16_to_cpus(&bd->length);
be32_to_cpus(&bd->data);
}
|
DoS
| 0
|
static void mcf_fec_read_bd(mcf_fec_bd *bd, uint32_t addr)
{
cpu_physical_memory_read(addr, bd, sizeof(*bd));
be16_to_cpus(&bd->flags);
be16_to_cpus(&bd->length);
be32_to_cpus(&bd->data);
}
|
@@ -23,6 +23,7 @@ do { printf("mcf_fec: " fmt , ## __VA_ARGS__); } while (0)
#define DPRINTF(fmt, ...) do {} while(0)
#endif
+#define FEC_MAX_DESC 1024
#define FEC_MAX_FRAME_SIZE 2032
typedef struct {
@@ -149,7 +150,7 @@ static void mcf_fec_do_tx(mcf_fec_state *s)
uint32_t addr;
mcf_fec_bd bd;
int frame_size;
- int len;
+ int len, descnt = 0;
uint8_t frame[FEC_MAX_FRAME_SIZE];
uint8_t *ptr;
@@ -157,7 +158,7 @@ static void mcf_fec_do_tx(mcf_fec_state *s)
ptr = frame;
frame_size = 0;
addr = s->tx_descriptor;
- while (1) {
+ while (descnt++ < FEC_MAX_DESC) {
mcf_fec_read_bd(&bd, addr);
DPRINTF("tx_bd %x flags %04x len %d data %08x\n",
addr, bd.flags, bd.length, bd.data);
|
CWE-399
| null | null |
6,639
|
static void mcf_fec_update(mcf_fec_state *s)
{
uint32_t active;
uint32_t changed;
uint32_t mask;
int i;
active = s->eir & s->eimr;
changed = active ^s->irq_state;
for (i = 0; i < FEC_NUM_IRQ; i++) {
mask = mcf_fec_irq_map[i];
if (changed & mask) {
DPRINTF("IRQ %d = %d\n", i, (active & mask) != 0);
qemu_set_irq(s->irq[i], (active & mask) != 0);
}
}
s->irq_state = active;
}
|
DoS
| 0
|
static void mcf_fec_update(mcf_fec_state *s)
{
uint32_t active;
uint32_t changed;
uint32_t mask;
int i;
active = s->eir & s->eimr;
changed = active ^s->irq_state;
for (i = 0; i < FEC_NUM_IRQ; i++) {
mask = mcf_fec_irq_map[i];
if (changed & mask) {
DPRINTF("IRQ %d = %d\n", i, (active & mask) != 0);
qemu_set_irq(s->irq[i], (active & mask) != 0);
}
}
s->irq_state = active;
}
|
@@ -23,6 +23,7 @@ do { printf("mcf_fec: " fmt , ## __VA_ARGS__); } while (0)
#define DPRINTF(fmt, ...) do {} while(0)
#endif
+#define FEC_MAX_DESC 1024
#define FEC_MAX_FRAME_SIZE 2032
typedef struct {
@@ -149,7 +150,7 @@ static void mcf_fec_do_tx(mcf_fec_state *s)
uint32_t addr;
mcf_fec_bd bd;
int frame_size;
- int len;
+ int len, descnt = 0;
uint8_t frame[FEC_MAX_FRAME_SIZE];
uint8_t *ptr;
@@ -157,7 +158,7 @@ static void mcf_fec_do_tx(mcf_fec_state *s)
ptr = frame;
frame_size = 0;
addr = s->tx_descriptor;
- while (1) {
+ while (descnt++ < FEC_MAX_DESC) {
mcf_fec_read_bd(&bd, addr);
DPRINTF("tx_bd %x flags %04x len %d data %08x\n",
addr, bd.flags, bd.length, bd.data);
|
CWE-399
| null | null |
6,640
|
static void usb_xhci_realize(struct PCIDevice *dev, Error **errp)
{
int i, ret;
Error *err = NULL;
XHCIState *xhci = XHCI(dev);
dev->config[PCI_CLASS_PROG] = 0x30; /* xHCI */
dev->config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin 1 */
dev->config[PCI_CACHE_LINE_SIZE] = 0x10;
dev->config[0x60] = 0x30; /* release number */
usb_xhci_init(xhci);
if (xhci->msi != ON_OFF_AUTO_OFF) {
ret = msi_init(dev, 0x70, xhci->numintrs, true, false, &err);
/* Any error other than -ENOTSUP(board's MSI support is broken)
* is a programming error */
assert(!ret || ret == -ENOTSUP);
if (ret && xhci->msi == ON_OFF_AUTO_ON) {
/* Can't satisfy user's explicit msi=on request, fail */
error_append_hint(&err, "You have to use msi=auto (default) or "
"msi=off with this machine type.\n");
error_propagate(errp, err);
return;
}
assert(!err || xhci->msi == ON_OFF_AUTO_AUTO);
/* With msi=auto, we fall back to MSI off silently */
error_free(err);
}
if (xhci->numintrs > MAXINTRS) {
xhci->numintrs = MAXINTRS;
}
while (xhci->numintrs & (xhci->numintrs - 1)) { /* ! power of 2 */
xhci->numintrs++;
}
if (xhci->numintrs < 1) {
xhci->numintrs = 1;
}
if (xhci->numslots > MAXSLOTS) {
xhci->numslots = MAXSLOTS;
}
if (xhci->numslots < 1) {
xhci->numslots = 1;
}
if (xhci_get_flag(xhci, XHCI_FLAG_ENABLE_STREAMS)) {
xhci->max_pstreams_mask = 7; /* == 256 primary streams */
} else {
xhci->max_pstreams_mask = 0;
}
xhci->mfwrap_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, xhci_mfwrap_timer, xhci);
memory_region_init(&xhci->mem, OBJECT(xhci), "xhci", LEN_REGS);
memory_region_init_io(&xhci->mem_cap, OBJECT(xhci), &xhci_cap_ops, xhci,
"capabilities", LEN_CAP);
memory_region_init_io(&xhci->mem_oper, OBJECT(xhci), &xhci_oper_ops, xhci,
"operational", 0x400);
memory_region_init_io(&xhci->mem_runtime, OBJECT(xhci), &xhci_runtime_ops, xhci,
"runtime", LEN_RUNTIME);
memory_region_init_io(&xhci->mem_doorbell, OBJECT(xhci), &xhci_doorbell_ops, xhci,
"doorbell", LEN_DOORBELL);
memory_region_add_subregion(&xhci->mem, 0, &xhci->mem_cap);
memory_region_add_subregion(&xhci->mem, OFF_OPER, &xhci->mem_oper);
memory_region_add_subregion(&xhci->mem, OFF_RUNTIME, &xhci->mem_runtime);
memory_region_add_subregion(&xhci->mem, OFF_DOORBELL, &xhci->mem_doorbell);
for (i = 0; i < xhci->numports; i++) {
XHCIPort *port = &xhci->ports[i];
uint32_t offset = OFF_OPER + 0x400 + 0x10 * i;
port->xhci = xhci;
memory_region_init_io(&port->mem, OBJECT(xhci), &xhci_port_ops, port,
port->name, 0x10);
memory_region_add_subregion(&xhci->mem, offset, &port->mem);
}
pci_register_bar(dev, 0,
PCI_BASE_ADDRESS_SPACE_MEMORY|PCI_BASE_ADDRESS_MEM_TYPE_64,
&xhci->mem);
if (pci_bus_is_express(dev->bus) ||
xhci_get_flag(xhci, XHCI_FLAG_FORCE_PCIE_ENDCAP)) {
ret = pcie_endpoint_cap_init(dev, 0xa0);
assert(ret >= 0);
}
if (xhci->msix != ON_OFF_AUTO_OFF) {
/* TODO check for errors */
msix_init(dev, xhci->numintrs,
&xhci->mem, 0, OFF_MSIX_TABLE,
&xhci->mem, 0, OFF_MSIX_PBA,
0x90);
}
}
|
DoS
| 0
|
static void usb_xhci_realize(struct PCIDevice *dev, Error **errp)
{
int i, ret;
Error *err = NULL;
XHCIState *xhci = XHCI(dev);
dev->config[PCI_CLASS_PROG] = 0x30; /* xHCI */
dev->config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin 1 */
dev->config[PCI_CACHE_LINE_SIZE] = 0x10;
dev->config[0x60] = 0x30; /* release number */
usb_xhci_init(xhci);
if (xhci->msi != ON_OFF_AUTO_OFF) {
ret = msi_init(dev, 0x70, xhci->numintrs, true, false, &err);
/* Any error other than -ENOTSUP(board's MSI support is broken)
* is a programming error */
assert(!ret || ret == -ENOTSUP);
if (ret && xhci->msi == ON_OFF_AUTO_ON) {
/* Can't satisfy user's explicit msi=on request, fail */
error_append_hint(&err, "You have to use msi=auto (default) or "
"msi=off with this machine type.\n");
error_propagate(errp, err);
return;
}
assert(!err || xhci->msi == ON_OFF_AUTO_AUTO);
/* With msi=auto, we fall back to MSI off silently */
error_free(err);
}
if (xhci->numintrs > MAXINTRS) {
xhci->numintrs = MAXINTRS;
}
while (xhci->numintrs & (xhci->numintrs - 1)) { /* ! power of 2 */
xhci->numintrs++;
}
if (xhci->numintrs < 1) {
xhci->numintrs = 1;
}
if (xhci->numslots > MAXSLOTS) {
xhci->numslots = MAXSLOTS;
}
if (xhci->numslots < 1) {
xhci->numslots = 1;
}
if (xhci_get_flag(xhci, XHCI_FLAG_ENABLE_STREAMS)) {
xhci->max_pstreams_mask = 7; /* == 256 primary streams */
} else {
xhci->max_pstreams_mask = 0;
}
xhci->mfwrap_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, xhci_mfwrap_timer, xhci);
memory_region_init(&xhci->mem, OBJECT(xhci), "xhci", LEN_REGS);
memory_region_init_io(&xhci->mem_cap, OBJECT(xhci), &xhci_cap_ops, xhci,
"capabilities", LEN_CAP);
memory_region_init_io(&xhci->mem_oper, OBJECT(xhci), &xhci_oper_ops, xhci,
"operational", 0x400);
memory_region_init_io(&xhci->mem_runtime, OBJECT(xhci), &xhci_runtime_ops, xhci,
"runtime", LEN_RUNTIME);
memory_region_init_io(&xhci->mem_doorbell, OBJECT(xhci), &xhci_doorbell_ops, xhci,
"doorbell", LEN_DOORBELL);
memory_region_add_subregion(&xhci->mem, 0, &xhci->mem_cap);
memory_region_add_subregion(&xhci->mem, OFF_OPER, &xhci->mem_oper);
memory_region_add_subregion(&xhci->mem, OFF_RUNTIME, &xhci->mem_runtime);
memory_region_add_subregion(&xhci->mem, OFF_DOORBELL, &xhci->mem_doorbell);
for (i = 0; i < xhci->numports; i++) {
XHCIPort *port = &xhci->ports[i];
uint32_t offset = OFF_OPER + 0x400 + 0x10 * i;
port->xhci = xhci;
memory_region_init_io(&port->mem, OBJECT(xhci), &xhci_port_ops, port,
port->name, 0x10);
memory_region_add_subregion(&xhci->mem, offset, &port->mem);
}
pci_register_bar(dev, 0,
PCI_BASE_ADDRESS_SPACE_MEMORY|PCI_BASE_ADDRESS_MEM_TYPE_64,
&xhci->mem);
if (pci_bus_is_express(dev->bus) ||
xhci_get_flag(xhci, XHCI_FLAG_FORCE_PCIE_ENDCAP)) {
ret = pcie_endpoint_cap_init(dev, 0xa0);
assert(ret >= 0);
}
if (xhci->msix != ON_OFF_AUTO_OFF) {
/* TODO check for errors */
msix_init(dev, xhci->numintrs,
&xhci->mem, 0, OFF_MSIX_TABLE,
&xhci->mem, 0, OFF_MSIX_PBA,
0x90);
}
}
|
@@ -3715,8 +3715,7 @@ static void usb_xhci_exit(PCIDevice *dev)
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
- memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio);
- memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio);
+ msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
|
CWE-399
| null | null |
6,641
|
static XHCIEPContext *xhci_alloc_epctx(XHCIState *xhci,
unsigned int slotid,
unsigned int epid)
{
XHCIEPContext *epctx;
int i;
epctx = g_new0(XHCIEPContext, 1);
epctx->xhci = xhci;
epctx->slotid = slotid;
epctx->epid = epid;
for (i = 0; i < ARRAY_SIZE(epctx->transfers); i++) {
epctx->transfers[i].xhci = xhci;
epctx->transfers[i].slotid = slotid;
epctx->transfers[i].epid = epid;
usb_packet_init(&epctx->transfers[i].packet);
}
epctx->kick_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, xhci_ep_kick_timer, epctx);
return epctx;
}
|
DoS
| 0
|
static XHCIEPContext *xhci_alloc_epctx(XHCIState *xhci,
unsigned int slotid,
unsigned int epid)
{
XHCIEPContext *epctx;
int i;
epctx = g_new0(XHCIEPContext, 1);
epctx->xhci = xhci;
epctx->slotid = slotid;
epctx->epid = epid;
for (i = 0; i < ARRAY_SIZE(epctx->transfers); i++) {
epctx->transfers[i].xhci = xhci;
epctx->transfers[i].slotid = slotid;
epctx->transfers[i].epid = epid;
usb_packet_init(&epctx->transfers[i].packet);
}
epctx->kick_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, xhci_ep_kick_timer, epctx);
return epctx;
}
|
@@ -3715,8 +3715,7 @@ static void usb_xhci_exit(PCIDevice *dev)
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
- memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio);
- memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio);
+ msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
|
CWE-399
| null | null |
6,642
|
static void xhci_complete(USBPort *port, USBPacket *packet)
{
XHCITransfer *xfer = container_of(packet, XHCITransfer, packet);
if (packet->status == USB_RET_REMOVE_FROM_QUEUE) {
xhci_ep_nuke_one_xfer(xfer, 0);
return;
}
xhci_complete_packet(xfer);
xhci_kick_ep(xfer->xhci, xfer->slotid, xfer->epid, xfer->streamid);
}
|
DoS
| 0
|
static void xhci_complete(USBPort *port, USBPacket *packet)
{
XHCITransfer *xfer = container_of(packet, XHCITransfer, packet);
if (packet->status == USB_RET_REMOVE_FROM_QUEUE) {
xhci_ep_nuke_one_xfer(xfer, 0);
return;
}
xhci_complete_packet(xfer);
xhci_kick_ep(xfer->xhci, xfer->slotid, xfer->epid, xfer->streamid);
}
|
@@ -3715,8 +3715,7 @@ static void usb_xhci_exit(PCIDevice *dev)
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
- memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio);
- memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio);
+ msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
|
CWE-399
| null | null |
6,643
|
static int xhci_complete_packet(XHCITransfer *xfer)
{
if (xfer->packet.status == USB_RET_ASYNC) {
trace_usb_xhci_xfer_async(xfer);
xfer->running_async = 1;
xfer->running_retry = 0;
xfer->complete = 0;
return 0;
} else if (xfer->packet.status == USB_RET_NAK) {
trace_usb_xhci_xfer_nak(xfer);
xfer->running_async = 0;
xfer->running_retry = 1;
xfer->complete = 0;
return 0;
} else {
xfer->running_async = 0;
xfer->running_retry = 0;
xfer->complete = 1;
xhci_xfer_unmap(xfer);
}
if (xfer->packet.status == USB_RET_SUCCESS) {
trace_usb_xhci_xfer_success(xfer, xfer->packet.actual_length);
xfer->status = CC_SUCCESS;
xhci_xfer_report(xfer);
return 0;
}
/* error */
trace_usb_xhci_xfer_error(xfer, xfer->packet.status);
switch (xfer->packet.status) {
case USB_RET_NODEV:
case USB_RET_IOERROR:
xfer->status = CC_USB_TRANSACTION_ERROR;
xhci_xfer_report(xfer);
xhci_stall_ep(xfer);
break;
case USB_RET_STALL:
xfer->status = CC_STALL_ERROR;
xhci_xfer_report(xfer);
xhci_stall_ep(xfer);
break;
case USB_RET_BABBLE:
xfer->status = CC_BABBLE_DETECTED;
xhci_xfer_report(xfer);
xhci_stall_ep(xfer);
break;
default:
DPRINTF("%s: FIXME: status = %d\n", __func__,
xfer->packet.status);
FIXME("unhandled USB_RET_*");
}
return 0;
}
|
DoS
| 0
|
static int xhci_complete_packet(XHCITransfer *xfer)
{
if (xfer->packet.status == USB_RET_ASYNC) {
trace_usb_xhci_xfer_async(xfer);
xfer->running_async = 1;
xfer->running_retry = 0;
xfer->complete = 0;
return 0;
} else if (xfer->packet.status == USB_RET_NAK) {
trace_usb_xhci_xfer_nak(xfer);
xfer->running_async = 0;
xfer->running_retry = 1;
xfer->complete = 0;
return 0;
} else {
xfer->running_async = 0;
xfer->running_retry = 0;
xfer->complete = 1;
xhci_xfer_unmap(xfer);
}
if (xfer->packet.status == USB_RET_SUCCESS) {
trace_usb_xhci_xfer_success(xfer, xfer->packet.actual_length);
xfer->status = CC_SUCCESS;
xhci_xfer_report(xfer);
return 0;
}
/* error */
trace_usb_xhci_xfer_error(xfer, xfer->packet.status);
switch (xfer->packet.status) {
case USB_RET_NODEV:
case USB_RET_IOERROR:
xfer->status = CC_USB_TRANSACTION_ERROR;
xhci_xfer_report(xfer);
xhci_stall_ep(xfer);
break;
case USB_RET_STALL:
xfer->status = CC_STALL_ERROR;
xhci_xfer_report(xfer);
xhci_stall_ep(xfer);
break;
case USB_RET_BABBLE:
xfer->status = CC_BABBLE_DETECTED;
xhci_xfer_report(xfer);
xhci_stall_ep(xfer);
break;
default:
DPRINTF("%s: FIXME: status = %d\n", __func__,
xfer->packet.status);
FIXME("unhandled USB_RET_*");
}
return 0;
}
|
@@ -3715,8 +3715,7 @@ static void usb_xhci_exit(PCIDevice *dev)
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
- memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio);
- memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio);
+ msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
|
CWE-399
| null | null |
6,644
|
static TRBCCode xhci_enable_slot(XHCIState *xhci, unsigned int slotid)
{
trace_usb_xhci_slot_enable(slotid);
assert(slotid >= 1 && slotid <= xhci->numslots);
xhci->slots[slotid-1].enabled = 1;
xhci->slots[slotid-1].uport = NULL;
memset(xhci->slots[slotid-1].eps, 0, sizeof(XHCIEPContext*)*31);
return CC_SUCCESS;
}
|
DoS
| 0
|
static TRBCCode xhci_enable_slot(XHCIState *xhci, unsigned int slotid)
{
trace_usb_xhci_slot_enable(slotid);
assert(slotid >= 1 && slotid <= xhci->numslots);
xhci->slots[slotid-1].enabled = 1;
xhci->slots[slotid-1].uport = NULL;
memset(xhci->slots[slotid-1].eps, 0, sizeof(XHCIEPContext*)*31);
return CC_SUCCESS;
}
|
@@ -3715,8 +3715,7 @@ static void usb_xhci_exit(PCIDevice *dev)
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
- memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio);
- memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio);
+ msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
|
CWE-399
| null | null |
6,645
|
static void xhci_ep_kick_timer(void *opaque)
{
XHCIEPContext *epctx = opaque;
xhci_kick_ep(epctx->xhci, epctx->slotid, epctx->epid, 0);
}
|
DoS
| 0
|
static void xhci_ep_kick_timer(void *opaque)
{
XHCIEPContext *epctx = opaque;
xhci_kick_ep(epctx->xhci, epctx->slotid, epctx->epid, 0);
}
|
@@ -3715,8 +3715,7 @@ static void usb_xhci_exit(PCIDevice *dev)
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
- memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio);
- memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio);
+ msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
|
CWE-399
| null | null |
6,646
|
static int xhci_ep_nuke_xfers(XHCIState *xhci, unsigned int slotid,
unsigned int epid, TRBCCode report)
{
XHCISlot *slot;
XHCIEPContext *epctx;
int i, xferi, killed = 0;
USBEndpoint *ep = NULL;
assert(slotid >= 1 && slotid <= xhci->numslots);
assert(epid >= 1 && epid <= 31);
DPRINTF("xhci_ep_nuke_xfers(%d, %d)\n", slotid, epid);
slot = &xhci->slots[slotid-1];
if (!slot->eps[epid-1]) {
return 0;
}
epctx = slot->eps[epid-1];
xferi = epctx->next_xfer;
for (i = 0; i < TD_QUEUE; i++) {
killed += xhci_ep_nuke_one_xfer(&epctx->transfers[xferi], report);
if (killed) {
report = 0; /* Only report once */
}
epctx->transfers[xferi].packet.ep = NULL;
xferi = (xferi + 1) % TD_QUEUE;
}
ep = xhci_epid_to_usbep(xhci, slotid, epid);
if (ep) {
usb_device_ep_stopped(ep->dev, ep);
}
return killed;
}
|
DoS
| 0
|
static int xhci_ep_nuke_xfers(XHCIState *xhci, unsigned int slotid,
unsigned int epid, TRBCCode report)
{
XHCISlot *slot;
XHCIEPContext *epctx;
int i, xferi, killed = 0;
USBEndpoint *ep = NULL;
assert(slotid >= 1 && slotid <= xhci->numslots);
assert(epid >= 1 && epid <= 31);
DPRINTF("xhci_ep_nuke_xfers(%d, %d)\n", slotid, epid);
slot = &xhci->slots[slotid-1];
if (!slot->eps[epid-1]) {
return 0;
}
epctx = slot->eps[epid-1];
xferi = epctx->next_xfer;
for (i = 0; i < TD_QUEUE; i++) {
killed += xhci_ep_nuke_one_xfer(&epctx->transfers[xferi], report);
if (killed) {
report = 0; /* Only report once */
}
epctx->transfers[xferi].packet.ep = NULL;
xferi = (xferi + 1) % TD_QUEUE;
}
ep = xhci_epid_to_usbep(xhci, slotid, epid);
if (ep) {
usb_device_ep_stopped(ep->dev, ep);
}
return killed;
}
|
@@ -3715,8 +3715,7 @@ static void usb_xhci_exit(PCIDevice *dev)
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
- memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio);
- memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio);
+ msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
|
CWE-399
| null | null |
6,647
|
static int xhci_epmask_to_eps_with_streams(XHCIState *xhci,
unsigned int slotid,
uint32_t epmask,
XHCIEPContext **epctxs,
USBEndpoint **eps)
{
XHCISlot *slot;
XHCIEPContext *epctx;
USBEndpoint *ep;
int i, j;
assert(slotid >= 1 && slotid <= xhci->numslots);
slot = &xhci->slots[slotid - 1];
for (i = 2, j = 0; i <= 31; i++) {
if (!(epmask & (1u << i))) {
continue;
}
epctx = slot->eps[i - 1];
ep = xhci_epid_to_usbep(xhci, slotid, i);
if (!epctx || !epctx->nr_pstreams || !ep) {
continue;
}
if (epctxs) {
epctxs[j] = epctx;
}
eps[j++] = ep;
}
return j;
}
|
DoS
| 0
|
static int xhci_epmask_to_eps_with_streams(XHCIState *xhci,
unsigned int slotid,
uint32_t epmask,
XHCIEPContext **epctxs,
USBEndpoint **eps)
{
XHCISlot *slot;
XHCIEPContext *epctx;
USBEndpoint *ep;
int i, j;
assert(slotid >= 1 && slotid <= xhci->numslots);
slot = &xhci->slots[slotid - 1];
for (i = 2, j = 0; i <= 31; i++) {
if (!(epmask & (1u << i))) {
continue;
}
epctx = slot->eps[i - 1];
ep = xhci_epid_to_usbep(xhci, slotid, i);
if (!epctx || !epctx->nr_pstreams || !ep) {
continue;
}
if (epctxs) {
epctxs[j] = epctx;
}
eps[j++] = ep;
}
return j;
}
|
@@ -3715,8 +3715,7 @@ static void usb_xhci_exit(PCIDevice *dev)
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
- memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio);
- memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio);
+ msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
|
CWE-399
| null | null |
6,648
|
static int xhci_fire_ctl_transfer(XHCIState *xhci, XHCITransfer *xfer)
{
XHCITRB *trb_setup, *trb_status;
uint8_t bmRequestType;
trb_setup = &xfer->trbs[0];
trb_status = &xfer->trbs[xfer->trb_count-1];
trace_usb_xhci_xfer_start(xfer, xfer->slotid, xfer->epid, xfer->streamid);
/* at most one Event Data TRB allowed after STATUS */
if (TRB_TYPE(*trb_status) == TR_EVDATA && xfer->trb_count > 2) {
trb_status--;
}
/* do some sanity checks */
if (TRB_TYPE(*trb_setup) != TR_SETUP) {
DPRINTF("xhci: ep0 first TD not SETUP: %d\n",
TRB_TYPE(*trb_setup));
return -1;
}
if (TRB_TYPE(*trb_status) != TR_STATUS) {
DPRINTF("xhci: ep0 last TD not STATUS: %d\n",
TRB_TYPE(*trb_status));
return -1;
}
if (!(trb_setup->control & TRB_TR_IDT)) {
DPRINTF("xhci: Setup TRB doesn't have IDT set\n");
return -1;
}
if ((trb_setup->status & 0x1ffff) != 8) {
DPRINTF("xhci: Setup TRB has bad length (%d)\n",
(trb_setup->status & 0x1ffff));
return -1;
}
bmRequestType = trb_setup->parameter;
xfer->in_xfer = bmRequestType & USB_DIR_IN;
xfer->iso_xfer = false;
xfer->timed_xfer = false;
if (xhci_setup_packet(xfer) < 0) {
return -1;
}
xfer->packet.parameter = trb_setup->parameter;
usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
xhci_complete_packet(xfer);
if (!xfer->running_async && !xfer->running_retry) {
xhci_kick_ep(xhci, xfer->slotid, xfer->epid, 0);
}
return 0;
}
|
DoS
| 0
|
static int xhci_fire_ctl_transfer(XHCIState *xhci, XHCITransfer *xfer)
{
XHCITRB *trb_setup, *trb_status;
uint8_t bmRequestType;
trb_setup = &xfer->trbs[0];
trb_status = &xfer->trbs[xfer->trb_count-1];
trace_usb_xhci_xfer_start(xfer, xfer->slotid, xfer->epid, xfer->streamid);
/* at most one Event Data TRB allowed after STATUS */
if (TRB_TYPE(*trb_status) == TR_EVDATA && xfer->trb_count > 2) {
trb_status--;
}
/* do some sanity checks */
if (TRB_TYPE(*trb_setup) != TR_SETUP) {
DPRINTF("xhci: ep0 first TD not SETUP: %d\n",
TRB_TYPE(*trb_setup));
return -1;
}
if (TRB_TYPE(*trb_status) != TR_STATUS) {
DPRINTF("xhci: ep0 last TD not STATUS: %d\n",
TRB_TYPE(*trb_status));
return -1;
}
if (!(trb_setup->control & TRB_TR_IDT)) {
DPRINTF("xhci: Setup TRB doesn't have IDT set\n");
return -1;
}
if ((trb_setup->status & 0x1ffff) != 8) {
DPRINTF("xhci: Setup TRB has bad length (%d)\n",
(trb_setup->status & 0x1ffff));
return -1;
}
bmRequestType = trb_setup->parameter;
xfer->in_xfer = bmRequestType & USB_DIR_IN;
xfer->iso_xfer = false;
xfer->timed_xfer = false;
if (xhci_setup_packet(xfer) < 0) {
return -1;
}
xfer->packet.parameter = trb_setup->parameter;
usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
xhci_complete_packet(xfer);
if (!xfer->running_async && !xfer->running_retry) {
xhci_kick_ep(xhci, xfer->slotid, xfer->epid, 0);
}
return 0;
}
|
@@ -3715,8 +3715,7 @@ static void usb_xhci_exit(PCIDevice *dev)
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
- memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio);
- memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio);
+ msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
|
CWE-399
| null | null |
6,649
|
static int xhci_fire_transfer(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext *epctx)
{
trace_usb_xhci_xfer_start(xfer, xfer->slotid, xfer->epid, xfer->streamid);
return xhci_submit(xhci, xfer, epctx);
}
|
DoS
| 0
|
static int xhci_fire_transfer(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext *epctx)
{
trace_usb_xhci_xfer_start(xfer, xfer->slotid, xfer->epid, xfer->streamid);
return xhci_submit(xhci, xfer, epctx);
}
|
@@ -3715,8 +3715,7 @@ static void usb_xhci_exit(PCIDevice *dev)
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
- memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio);
- memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio);
+ msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
|
CWE-399
| null | null |
6,650
|
static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
unsigned int epid, unsigned int streamid)
{
XHCIStreamContext *stctx;
XHCIEPContext *epctx;
XHCIRing *ring;
USBEndpoint *ep = NULL;
uint64_t mfindex;
int length;
int i;
trace_usb_xhci_ep_kick(slotid, epid, streamid);
assert(slotid >= 1 && slotid <= xhci->numslots);
assert(epid >= 1 && epid <= 31);
if (!xhci->slots[slotid-1].enabled) {
DPRINTF("xhci: xhci_kick_ep for disabled slot %d\n", slotid);
return;
}
epctx = xhci->slots[slotid-1].eps[epid-1];
if (!epctx) {
DPRINTF("xhci: xhci_kick_ep for disabled endpoint %d,%d\n",
epid, slotid);
return;
}
/* If the device has been detached, but the guest has not noticed this
yet the 2 above checks will succeed, but we must NOT continue */
if (!xhci->slots[slotid - 1].uport ||
!xhci->slots[slotid - 1].uport->dev ||
!xhci->slots[slotid - 1].uport->dev->attached) {
return;
}
if (epctx->retry) {
XHCITransfer *xfer = epctx->retry;
trace_usb_xhci_xfer_retry(xfer);
assert(xfer->running_retry);
if (xfer->timed_xfer) {
/* time to kick the transfer? */
mfindex = xhci_mfindex_get(xhci);
xhci_check_intr_iso_kick(xhci, xfer, epctx, mfindex);
if (xfer->running_retry) {
return;
}
xfer->timed_xfer = 0;
xfer->running_retry = 1;
}
if (xfer->iso_xfer) {
/* retry iso transfer */
if (xhci_setup_packet(xfer) < 0) {
return;
}
usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
assert(xfer->packet.status != USB_RET_NAK);
xhci_complete_packet(xfer);
} else {
/* retry nak'ed transfer */
if (xhci_setup_packet(xfer) < 0) {
return;
}
usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
if (xfer->packet.status == USB_RET_NAK) {
return;
}
xhci_complete_packet(xfer);
}
assert(!xfer->running_retry);
epctx->retry = NULL;
}
if (epctx->state == EP_HALTED) {
DPRINTF("xhci: ep halted, not running schedule\n");
return;
}
if (epctx->nr_pstreams) {
uint32_t err;
stctx = xhci_find_stream(epctx, streamid, &err);
if (stctx == NULL) {
return;
}
ring = &stctx->ring;
xhci_set_ep_state(xhci, epctx, stctx, EP_RUNNING);
} else {
ring = &epctx->ring;
streamid = 0;
xhci_set_ep_state(xhci, epctx, NULL, EP_RUNNING);
}
assert(ring->dequeue != 0);
while (1) {
XHCITransfer *xfer = &epctx->transfers[epctx->next_xfer];
if (xfer->running_async || xfer->running_retry) {
break;
}
length = xhci_ring_chain_length(xhci, ring);
if (length < 0) {
break;
} else if (length == 0) {
break;
}
if (xfer->trbs && xfer->trb_alloced < length) {
xfer->trb_count = 0;
xfer->trb_alloced = 0;
g_free(xfer->trbs);
xfer->trbs = NULL;
}
if (!xfer->trbs) {
xfer->trbs = g_new(XHCITRB, length);
xfer->trb_alloced = length;
}
xfer->trb_count = length;
for (i = 0; i < length; i++) {
TRBType type;
type = xhci_ring_fetch(xhci, ring, &xfer->trbs[i], NULL);
assert(type);
}
xfer->streamid = streamid;
if (epid == 1) {
if (xhci_fire_ctl_transfer(xhci, xfer) >= 0) {
epctx->next_xfer = (epctx->next_xfer + 1) % TD_QUEUE;
} else {
DPRINTF("xhci: error firing CTL transfer\n");
}
} else {
if (xhci_fire_transfer(xhci, xfer, epctx) >= 0) {
epctx->next_xfer = (epctx->next_xfer + 1) % TD_QUEUE;
} else {
if (!xfer->timed_xfer) {
DPRINTF("xhci: error firing data transfer\n");
}
}
}
if (epctx->state == EP_HALTED) {
break;
}
if (xfer->running_retry) {
DPRINTF("xhci: xfer nacked, stopping schedule\n");
epctx->retry = xfer;
break;
}
}
ep = xhci_epid_to_usbep(xhci, slotid, epid);
if (ep) {
usb_device_flush_ep_queue(ep->dev, ep);
}
}
|
DoS
| 0
|
static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
unsigned int epid, unsigned int streamid)
{
XHCIStreamContext *stctx;
XHCIEPContext *epctx;
XHCIRing *ring;
USBEndpoint *ep = NULL;
uint64_t mfindex;
int length;
int i;
trace_usb_xhci_ep_kick(slotid, epid, streamid);
assert(slotid >= 1 && slotid <= xhci->numslots);
assert(epid >= 1 && epid <= 31);
if (!xhci->slots[slotid-1].enabled) {
DPRINTF("xhci: xhci_kick_ep for disabled slot %d\n", slotid);
return;
}
epctx = xhci->slots[slotid-1].eps[epid-1];
if (!epctx) {
DPRINTF("xhci: xhci_kick_ep for disabled endpoint %d,%d\n",
epid, slotid);
return;
}
/* If the device has been detached, but the guest has not noticed this
yet the 2 above checks will succeed, but we must NOT continue */
if (!xhci->slots[slotid - 1].uport ||
!xhci->slots[slotid - 1].uport->dev ||
!xhci->slots[slotid - 1].uport->dev->attached) {
return;
}
if (epctx->retry) {
XHCITransfer *xfer = epctx->retry;
trace_usb_xhci_xfer_retry(xfer);
assert(xfer->running_retry);
if (xfer->timed_xfer) {
/* time to kick the transfer? */
mfindex = xhci_mfindex_get(xhci);
xhci_check_intr_iso_kick(xhci, xfer, epctx, mfindex);
if (xfer->running_retry) {
return;
}
xfer->timed_xfer = 0;
xfer->running_retry = 1;
}
if (xfer->iso_xfer) {
/* retry iso transfer */
if (xhci_setup_packet(xfer) < 0) {
return;
}
usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
assert(xfer->packet.status != USB_RET_NAK);
xhci_complete_packet(xfer);
} else {
/* retry nak'ed transfer */
if (xhci_setup_packet(xfer) < 0) {
return;
}
usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
if (xfer->packet.status == USB_RET_NAK) {
return;
}
xhci_complete_packet(xfer);
}
assert(!xfer->running_retry);
epctx->retry = NULL;
}
if (epctx->state == EP_HALTED) {
DPRINTF("xhci: ep halted, not running schedule\n");
return;
}
if (epctx->nr_pstreams) {
uint32_t err;
stctx = xhci_find_stream(epctx, streamid, &err);
if (stctx == NULL) {
return;
}
ring = &stctx->ring;
xhci_set_ep_state(xhci, epctx, stctx, EP_RUNNING);
} else {
ring = &epctx->ring;
streamid = 0;
xhci_set_ep_state(xhci, epctx, NULL, EP_RUNNING);
}
assert(ring->dequeue != 0);
while (1) {
XHCITransfer *xfer = &epctx->transfers[epctx->next_xfer];
if (xfer->running_async || xfer->running_retry) {
break;
}
length = xhci_ring_chain_length(xhci, ring);
if (length < 0) {
break;
} else if (length == 0) {
break;
}
if (xfer->trbs && xfer->trb_alloced < length) {
xfer->trb_count = 0;
xfer->trb_alloced = 0;
g_free(xfer->trbs);
xfer->trbs = NULL;
}
if (!xfer->trbs) {
xfer->trbs = g_new(XHCITRB, length);
xfer->trb_alloced = length;
}
xfer->trb_count = length;
for (i = 0; i < length; i++) {
TRBType type;
type = xhci_ring_fetch(xhci, ring, &xfer->trbs[i], NULL);
assert(type);
}
xfer->streamid = streamid;
if (epid == 1) {
if (xhci_fire_ctl_transfer(xhci, xfer) >= 0) {
epctx->next_xfer = (epctx->next_xfer + 1) % TD_QUEUE;
} else {
DPRINTF("xhci: error firing CTL transfer\n");
}
} else {
if (xhci_fire_transfer(xhci, xfer, epctx) >= 0) {
epctx->next_xfer = (epctx->next_xfer + 1) % TD_QUEUE;
} else {
if (!xfer->timed_xfer) {
DPRINTF("xhci: error firing data transfer\n");
}
}
}
if (epctx->state == EP_HALTED) {
break;
}
if (xfer->running_retry) {
DPRINTF("xhci: xfer nacked, stopping schedule\n");
epctx->retry = xfer;
break;
}
}
ep = xhci_epid_to_usbep(xhci, slotid, epid);
if (ep) {
usb_device_flush_ep_queue(ep->dev, ep);
}
}
|
@@ -3715,8 +3715,7 @@ static void usb_xhci_exit(PCIDevice *dev)
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
- memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio);
- memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio);
+ msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
|
CWE-399
| null | null |
6,651
|
static TRBType xhci_ring_fetch(XHCIState *xhci, XHCIRing *ring, XHCITRB *trb,
dma_addr_t *addr)
{
PCIDevice *pci_dev = PCI_DEVICE(xhci);
while (1) {
TRBType type;
pci_dma_read(pci_dev, ring->dequeue, trb, TRB_SIZE);
trb->addr = ring->dequeue;
trb->ccs = ring->ccs;
le64_to_cpus(&trb->parameter);
le32_to_cpus(&trb->status);
le32_to_cpus(&trb->control);
trace_usb_xhci_fetch_trb(ring->dequeue, trb_name(trb),
trb->parameter, trb->status, trb->control);
if ((trb->control & TRB_C) != ring->ccs) {
return 0;
}
type = TRB_TYPE(*trb);
if (type != TR_LINK) {
if (addr) {
*addr = ring->dequeue;
}
ring->dequeue += TRB_SIZE;
return type;
} else {
ring->dequeue = xhci_mask64(trb->parameter);
if (trb->control & TRB_LK_TC) {
ring->ccs = !ring->ccs;
}
}
}
}
|
DoS
| 0
|
static TRBType xhci_ring_fetch(XHCIState *xhci, XHCIRing *ring, XHCITRB *trb,
dma_addr_t *addr)
{
PCIDevice *pci_dev = PCI_DEVICE(xhci);
while (1) {
TRBType type;
pci_dma_read(pci_dev, ring->dequeue, trb, TRB_SIZE);
trb->addr = ring->dequeue;
trb->ccs = ring->ccs;
le64_to_cpus(&trb->parameter);
le32_to_cpus(&trb->status);
le32_to_cpus(&trb->control);
trace_usb_xhci_fetch_trb(ring->dequeue, trb_name(trb),
trb->parameter, trb->status, trb->control);
if ((trb->control & TRB_C) != ring->ccs) {
return 0;
}
type = TRB_TYPE(*trb);
if (type != TR_LINK) {
if (addr) {
*addr = ring->dequeue;
}
ring->dequeue += TRB_SIZE;
return type;
} else {
ring->dequeue = xhci_mask64(trb->parameter);
if (trb->control & TRB_LK_TC) {
ring->ccs = !ring->ccs;
}
}
}
}
|
@@ -3715,8 +3715,7 @@ static void usb_xhci_exit(PCIDevice *dev)
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
- memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio);
- memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio);
+ msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
|
CWE-399
| null | null |
6,652
|
static int xhci_setup_packet(XHCITransfer *xfer)
{
XHCIState *xhci = xfer->xhci;
USBEndpoint *ep;
int dir;
dir = xfer->in_xfer ? USB_TOKEN_IN : USB_TOKEN_OUT;
if (xfer->packet.ep) {
ep = xfer->packet.ep;
} else {
ep = xhci_epid_to_usbep(xhci, xfer->slotid, xfer->epid);
if (!ep) {
DPRINTF("xhci: slot %d has no device\n",
xfer->slotid);
return -1;
}
}
xhci_xfer_create_sgl(xfer, dir == USB_TOKEN_IN); /* Also sets int_req */
usb_packet_setup(&xfer->packet, dir, ep, xfer->streamid,
xfer->trbs[0].addr, false, xfer->int_req);
usb_packet_map(&xfer->packet, &xfer->sgl);
DPRINTF("xhci: setup packet pid 0x%x addr %d ep %d\n",
xfer->packet.pid, ep->dev->addr, ep->nr);
return 0;
}
|
DoS
| 0
|
static int xhci_setup_packet(XHCITransfer *xfer)
{
XHCIState *xhci = xfer->xhci;
USBEndpoint *ep;
int dir;
dir = xfer->in_xfer ? USB_TOKEN_IN : USB_TOKEN_OUT;
if (xfer->packet.ep) {
ep = xfer->packet.ep;
} else {
ep = xhci_epid_to_usbep(xhci, xfer->slotid, xfer->epid);
if (!ep) {
DPRINTF("xhci: slot %d has no device\n",
xfer->slotid);
return -1;
}
}
xhci_xfer_create_sgl(xfer, dir == USB_TOKEN_IN); /* Also sets int_req */
usb_packet_setup(&xfer->packet, dir, ep, xfer->streamid,
xfer->trbs[0].addr, false, xfer->int_req);
usb_packet_map(&xfer->packet, &xfer->sgl);
DPRINTF("xhci: setup packet pid 0x%x addr %d ep %d\n",
xfer->packet.pid, ep->dev->addr, ep->nr);
return 0;
}
|
@@ -3715,8 +3715,7 @@ static void usb_xhci_exit(PCIDevice *dev)
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
- memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio);
- memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio);
+ msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
|
CWE-399
| null | null |
6,653
|
static void xhci_stall_ep(XHCITransfer *xfer)
{
XHCIState *xhci = xfer->xhci;
XHCISlot *slot = &xhci->slots[xfer->slotid-1];
XHCIEPContext *epctx = slot->eps[xfer->epid-1];
uint32_t err;
XHCIStreamContext *sctx;
if (epctx->nr_pstreams) {
sctx = xhci_find_stream(epctx, xfer->streamid, &err);
if (sctx == NULL) {
return;
}
sctx->ring.dequeue = xfer->trbs[0].addr;
sctx->ring.ccs = xfer->trbs[0].ccs;
xhci_set_ep_state(xhci, epctx, sctx, EP_HALTED);
} else {
epctx->ring.dequeue = xfer->trbs[0].addr;
epctx->ring.ccs = xfer->trbs[0].ccs;
xhci_set_ep_state(xhci, epctx, NULL, EP_HALTED);
}
}
|
DoS
| 0
|
static void xhci_stall_ep(XHCITransfer *xfer)
{
XHCIState *xhci = xfer->xhci;
XHCISlot *slot = &xhci->slots[xfer->slotid-1];
XHCIEPContext *epctx = slot->eps[xfer->epid-1];
uint32_t err;
XHCIStreamContext *sctx;
if (epctx->nr_pstreams) {
sctx = xhci_find_stream(epctx, xfer->streamid, &err);
if (sctx == NULL) {
return;
}
sctx->ring.dequeue = xfer->trbs[0].addr;
sctx->ring.ccs = xfer->trbs[0].ccs;
xhci_set_ep_state(xhci, epctx, sctx, EP_HALTED);
} else {
epctx->ring.dequeue = xfer->trbs[0].addr;
epctx->ring.ccs = xfer->trbs[0].ccs;
xhci_set_ep_state(xhci, epctx, NULL, EP_HALTED);
}
}
|
@@ -3715,8 +3715,7 @@ static void usb_xhci_exit(PCIDevice *dev)
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
- memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio);
- memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio);
+ msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
|
CWE-399
| null | null |
6,654
|
static int xhci_xfer_create_sgl(XHCITransfer *xfer, int in_xfer)
{
XHCIState *xhci = xfer->xhci;
int i;
xfer->int_req = false;
pci_dma_sglist_init(&xfer->sgl, PCI_DEVICE(xhci), xfer->trb_count);
for (i = 0; i < xfer->trb_count; i++) {
XHCITRB *trb = &xfer->trbs[i];
dma_addr_t addr;
unsigned int chunk = 0;
if (trb->control & TRB_TR_IOC) {
xfer->int_req = true;
}
switch (TRB_TYPE(*trb)) {
case TR_DATA:
if ((!(trb->control & TRB_TR_DIR)) != (!in_xfer)) {
DPRINTF("xhci: data direction mismatch for TR_DATA\n");
goto err;
}
/* fallthrough */
case TR_NORMAL:
case TR_ISOCH:
addr = xhci_mask64(trb->parameter);
chunk = trb->status & 0x1ffff;
if (trb->control & TRB_TR_IDT) {
if (chunk > 8 || in_xfer) {
DPRINTF("xhci: invalid immediate data TRB\n");
goto err;
}
qemu_sglist_add(&xfer->sgl, trb->addr, chunk);
} else {
qemu_sglist_add(&xfer->sgl, addr, chunk);
}
break;
}
}
return 0;
err:
qemu_sglist_destroy(&xfer->sgl);
xhci_die(xhci);
return -1;
}
|
DoS
| 0
|
static int xhci_xfer_create_sgl(XHCITransfer *xfer, int in_xfer)
{
XHCIState *xhci = xfer->xhci;
int i;
xfer->int_req = false;
pci_dma_sglist_init(&xfer->sgl, PCI_DEVICE(xhci), xfer->trb_count);
for (i = 0; i < xfer->trb_count; i++) {
XHCITRB *trb = &xfer->trbs[i];
dma_addr_t addr;
unsigned int chunk = 0;
if (trb->control & TRB_TR_IOC) {
xfer->int_req = true;
}
switch (TRB_TYPE(*trb)) {
case TR_DATA:
if ((!(trb->control & TRB_TR_DIR)) != (!in_xfer)) {
DPRINTF("xhci: data direction mismatch for TR_DATA\n");
goto err;
}
/* fallthrough */
case TR_NORMAL:
case TR_ISOCH:
addr = xhci_mask64(trb->parameter);
chunk = trb->status & 0x1ffff;
if (trb->control & TRB_TR_IDT) {
if (chunk > 8 || in_xfer) {
DPRINTF("xhci: invalid immediate data TRB\n");
goto err;
}
qemu_sglist_add(&xfer->sgl, trb->addr, chunk);
} else {
qemu_sglist_add(&xfer->sgl, addr, chunk);
}
break;
}
}
return 0;
err:
qemu_sglist_destroy(&xfer->sgl);
xhci_die(xhci);
return -1;
}
|
@@ -3715,8 +3715,7 @@ static void usb_xhci_exit(PCIDevice *dev)
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
- memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio);
- memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio);
+ msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
|
CWE-399
| null | null |
6,655
|
static void xhci_xfer_report(XHCITransfer *xfer)
{
uint32_t edtla = 0;
unsigned int left;
bool reported = 0;
bool shortpkt = 0;
XHCIEvent event = {ER_TRANSFER, CC_SUCCESS};
XHCIState *xhci = xfer->xhci;
int i;
left = xfer->packet.actual_length;
for (i = 0; i < xfer->trb_count; i++) {
XHCITRB *trb = &xfer->trbs[i];
unsigned int chunk = 0;
switch (TRB_TYPE(*trb)) {
case TR_SETUP:
chunk = trb->status & 0x1ffff;
if (chunk > 8) {
chunk = 8;
}
break;
case TR_DATA:
case TR_NORMAL:
case TR_ISOCH:
chunk = trb->status & 0x1ffff;
if (chunk > left) {
chunk = left;
if (xfer->status == CC_SUCCESS) {
shortpkt = 1;
}
}
left -= chunk;
edtla += chunk;
break;
case TR_STATUS:
reported = 0;
shortpkt = 0;
break;
}
if (!reported && ((trb->control & TRB_TR_IOC) ||
(shortpkt && (trb->control & TRB_TR_ISP)) ||
(xfer->status != CC_SUCCESS && left == 0))) {
event.slotid = xfer->slotid;
event.epid = xfer->epid;
event.length = (trb->status & 0x1ffff) - chunk;
event.flags = 0;
event.ptr = trb->addr;
if (xfer->status == CC_SUCCESS) {
event.ccode = shortpkt ? CC_SHORT_PACKET : CC_SUCCESS;
} else {
event.ccode = xfer->status;
}
if (TRB_TYPE(*trb) == TR_EVDATA) {
event.ptr = trb->parameter;
event.flags |= TRB_EV_ED;
event.length = edtla & 0xffffff;
DPRINTF("xhci_xfer_data: EDTLA=%d\n", event.length);
edtla = 0;
}
xhci_event(xhci, &event, TRB_INTR(*trb));
reported = 1;
if (xfer->status != CC_SUCCESS) {
return;
}
}
switch (TRB_TYPE(*trb)) {
case TR_SETUP:
reported = 0;
shortpkt = 0;
break;
}
}
}
|
DoS
| 0
|
static void xhci_xfer_report(XHCITransfer *xfer)
{
uint32_t edtla = 0;
unsigned int left;
bool reported = 0;
bool shortpkt = 0;
XHCIEvent event = {ER_TRANSFER, CC_SUCCESS};
XHCIState *xhci = xfer->xhci;
int i;
left = xfer->packet.actual_length;
for (i = 0; i < xfer->trb_count; i++) {
XHCITRB *trb = &xfer->trbs[i];
unsigned int chunk = 0;
switch (TRB_TYPE(*trb)) {
case TR_SETUP:
chunk = trb->status & 0x1ffff;
if (chunk > 8) {
chunk = 8;
}
break;
case TR_DATA:
case TR_NORMAL:
case TR_ISOCH:
chunk = trb->status & 0x1ffff;
if (chunk > left) {
chunk = left;
if (xfer->status == CC_SUCCESS) {
shortpkt = 1;
}
}
left -= chunk;
edtla += chunk;
break;
case TR_STATUS:
reported = 0;
shortpkt = 0;
break;
}
if (!reported && ((trb->control & TRB_TR_IOC) ||
(shortpkt && (trb->control & TRB_TR_ISP)) ||
(xfer->status != CC_SUCCESS && left == 0))) {
event.slotid = xfer->slotid;
event.epid = xfer->epid;
event.length = (trb->status & 0x1ffff) - chunk;
event.flags = 0;
event.ptr = trb->addr;
if (xfer->status == CC_SUCCESS) {
event.ccode = shortpkt ? CC_SHORT_PACKET : CC_SUCCESS;
} else {
event.ccode = xfer->status;
}
if (TRB_TYPE(*trb) == TR_EVDATA) {
event.ptr = trb->parameter;
event.flags |= TRB_EV_ED;
event.length = edtla & 0xffffff;
DPRINTF("xhci_xfer_data: EDTLA=%d\n", event.length);
edtla = 0;
}
xhci_event(xhci, &event, TRB_INTR(*trb));
reported = 1;
if (xfer->status != CC_SUCCESS) {
return;
}
}
switch (TRB_TYPE(*trb)) {
case TR_SETUP:
reported = 0;
shortpkt = 0;
break;
}
}
}
|
@@ -3715,8 +3715,7 @@ static void usb_xhci_exit(PCIDevice *dev)
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
- memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio);
- memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio);
+ msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
|
CWE-399
| null | null |
6,656
|
static void gmc1_motion(MpegEncContext *s,
uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
uint8_t **ref_picture)
{
uint8_t *ptr;
int src_x, src_y, motion_x, motion_y;
ptrdiff_t offset, linesize, uvlinesize;
int emu = 0;
motion_x = s->sprite_offset[0][0];
motion_y = s->sprite_offset[0][1];
src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy + 1));
src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy + 1));
motion_x <<= (3 - s->sprite_warping_accuracy);
motion_y <<= (3 - s->sprite_warping_accuracy);
src_x = av_clip(src_x, -16, s->width);
if (src_x == s->width)
motion_x = 0;
src_y = av_clip(src_y, -16, s->height);
if (src_y == s->height)
motion_y = 0;
linesize = s->linesize;
uvlinesize = s->uvlinesize;
ptr = ref_picture[0] + src_y * linesize + src_x;
if ((unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0) ||
(unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)) {
s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
linesize, linesize,
17, 17,
src_x, src_y,
s->h_edge_pos, s->v_edge_pos);
ptr = s->sc.edge_emu_buffer;
}
if ((motion_x | motion_y) & 7) {
s->mdsp.gmc1(dest_y, ptr, linesize, 16,
motion_x & 15, motion_y & 15, 128 - s->no_rounding);
s->mdsp.gmc1(dest_y + 8, ptr + 8, linesize, 16,
motion_x & 15, motion_y & 15, 128 - s->no_rounding);
} else {
int dxy;
dxy = ((motion_x >> 3) & 1) | ((motion_y >> 2) & 2);
if (s->no_rounding) {
s->hdsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
} else {
s->hdsp.put_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
}
}
if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY)
return;
motion_x = s->sprite_offset[1][0];
motion_y = s->sprite_offset[1][1];
src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy + 1));
src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy + 1));
motion_x <<= (3 - s->sprite_warping_accuracy);
motion_y <<= (3 - s->sprite_warping_accuracy);
src_x = av_clip(src_x, -8, s->width >> 1);
if (src_x == s->width >> 1)
motion_x = 0;
src_y = av_clip(src_y, -8, s->height >> 1);
if (src_y == s->height >> 1)
motion_y = 0;
offset = (src_y * uvlinesize) + src_x;
ptr = ref_picture[1] + offset;
if ((unsigned)src_x >= FFMAX((s->h_edge_pos >> 1) - 9, 0) ||
(unsigned)src_y >= FFMAX((s->v_edge_pos >> 1) - 9, 0)) {
s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
uvlinesize, uvlinesize,
9, 9,
src_x, src_y,
s->h_edge_pos >> 1, s->v_edge_pos >> 1);
ptr = s->sc.edge_emu_buffer;
emu = 1;
}
s->mdsp.gmc1(dest_cb, ptr, uvlinesize, 8,
motion_x & 15, motion_y & 15, 128 - s->no_rounding);
ptr = ref_picture[2] + offset;
if (emu) {
s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
uvlinesize, uvlinesize,
9, 9,
src_x, src_y,
s->h_edge_pos >> 1, s->v_edge_pos >> 1);
ptr = s->sc.edge_emu_buffer;
}
s->mdsp.gmc1(dest_cr, ptr, uvlinesize, 8,
motion_x & 15, motion_y & 15, 128 - s->no_rounding);
}
|
DoS
| 0
|
static void gmc1_motion(MpegEncContext *s,
uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
uint8_t **ref_picture)
{
uint8_t *ptr;
int src_x, src_y, motion_x, motion_y;
ptrdiff_t offset, linesize, uvlinesize;
int emu = 0;
motion_x = s->sprite_offset[0][0];
motion_y = s->sprite_offset[0][1];
src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy + 1));
src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy + 1));
motion_x <<= (3 - s->sprite_warping_accuracy);
motion_y <<= (3 - s->sprite_warping_accuracy);
src_x = av_clip(src_x, -16, s->width);
if (src_x == s->width)
motion_x = 0;
src_y = av_clip(src_y, -16, s->height);
if (src_y == s->height)
motion_y = 0;
linesize = s->linesize;
uvlinesize = s->uvlinesize;
ptr = ref_picture[0] + src_y * linesize + src_x;
if ((unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0) ||
(unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)) {
s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
linesize, linesize,
17, 17,
src_x, src_y,
s->h_edge_pos, s->v_edge_pos);
ptr = s->sc.edge_emu_buffer;
}
if ((motion_x | motion_y) & 7) {
s->mdsp.gmc1(dest_y, ptr, linesize, 16,
motion_x & 15, motion_y & 15, 128 - s->no_rounding);
s->mdsp.gmc1(dest_y + 8, ptr + 8, linesize, 16,
motion_x & 15, motion_y & 15, 128 - s->no_rounding);
} else {
int dxy;
dxy = ((motion_x >> 3) & 1) | ((motion_y >> 2) & 2);
if (s->no_rounding) {
s->hdsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
} else {
s->hdsp.put_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
}
}
if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY)
return;
motion_x = s->sprite_offset[1][0];
motion_y = s->sprite_offset[1][1];
src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy + 1));
src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy + 1));
motion_x <<= (3 - s->sprite_warping_accuracy);
motion_y <<= (3 - s->sprite_warping_accuracy);
src_x = av_clip(src_x, -8, s->width >> 1);
if (src_x == s->width >> 1)
motion_x = 0;
src_y = av_clip(src_y, -8, s->height >> 1);
if (src_y == s->height >> 1)
motion_y = 0;
offset = (src_y * uvlinesize) + src_x;
ptr = ref_picture[1] + offset;
if ((unsigned)src_x >= FFMAX((s->h_edge_pos >> 1) - 9, 0) ||
(unsigned)src_y >= FFMAX((s->v_edge_pos >> 1) - 9, 0)) {
s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
uvlinesize, uvlinesize,
9, 9,
src_x, src_y,
s->h_edge_pos >> 1, s->v_edge_pos >> 1);
ptr = s->sc.edge_emu_buffer;
emu = 1;
}
s->mdsp.gmc1(dest_cb, ptr, uvlinesize, 8,
motion_x & 15, motion_y & 15, 128 - s->no_rounding);
ptr = ref_picture[2] + offset;
if (emu) {
s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
uvlinesize, uvlinesize,
9, 9,
src_x, src_y,
s->h_edge_pos >> 1, s->v_edge_pos >> 1);
ptr = s->sc.edge_emu_buffer;
}
s->mdsp.gmc1(dest_cr, ptr, uvlinesize, 8,
motion_x & 15, motion_y & 15, 128 - s->no_rounding);
}
|
@@ -210,17 +210,14 @@ static inline int hpel_motion(MpegEncContext *s,
dxy |= (motion_y & 1) << 1;
src += src_y * s->linesize + src_x;
- if (s->unrestricted_mv) {
- if ((unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x & 1) - 8, 0) ||
- (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y & 1) - 8, 0)) {
- s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, src,
- s->linesize, s->linesize,
- 9, 9,
- src_x, src_y, s->h_edge_pos,
- s->v_edge_pos);
- src = s->sc.edge_emu_buffer;
- emu = 1;
- }
+ if ((unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x & 1) - 8, 0) ||
+ (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y & 1) - 8, 0)) {
+ s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, src,
+ s->linesize, s->linesize,
+ 9, 9, src_x, src_y,
+ s->h_edge_pos, s->v_edge_pos);
+ src = s->sc.edge_emu_buffer;
+ emu = 1;
}
pix_op[dxy](dest, src, s->linesize, 8);
return emu;
|
CWE-476
| null | null |
6,657
|
static void gmc_motion(MpegEncContext *s,
uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
uint8_t **ref_picture)
{
uint8_t *ptr;
int linesize, uvlinesize;
const int a = s->sprite_warping_accuracy;
int ox, oy;
linesize = s->linesize;
uvlinesize = s->uvlinesize;
ptr = ref_picture[0];
ox = s->sprite_offset[0][0] + s->sprite_delta[0][0] * s->mb_x * 16 +
s->sprite_delta[0][1] * s->mb_y * 16;
oy = s->sprite_offset[0][1] + s->sprite_delta[1][0] * s->mb_x * 16 +
s->sprite_delta[1][1] * s->mb_y * 16;
s->mdsp.gmc(dest_y, ptr, linesize, 16,
ox, oy,
s->sprite_delta[0][0], s->sprite_delta[0][1],
s->sprite_delta[1][0], s->sprite_delta[1][1],
a + 1, (1 << (2 * a + 1)) - s->no_rounding,
s->h_edge_pos, s->v_edge_pos);
s->mdsp.gmc(dest_y + 8, ptr, linesize, 16,
ox + s->sprite_delta[0][0] * 8,
oy + s->sprite_delta[1][0] * 8,
s->sprite_delta[0][0], s->sprite_delta[0][1],
s->sprite_delta[1][0], s->sprite_delta[1][1],
a + 1, (1 << (2 * a + 1)) - s->no_rounding,
s->h_edge_pos, s->v_edge_pos);
if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY)
return;
ox = s->sprite_offset[1][0] + s->sprite_delta[0][0] * s->mb_x * 8 +
s->sprite_delta[0][1] * s->mb_y * 8;
oy = s->sprite_offset[1][1] + s->sprite_delta[1][0] * s->mb_x * 8 +
s->sprite_delta[1][1] * s->mb_y * 8;
ptr = ref_picture[1];
s->mdsp.gmc(dest_cb, ptr, uvlinesize, 8,
ox, oy,
s->sprite_delta[0][0], s->sprite_delta[0][1],
s->sprite_delta[1][0], s->sprite_delta[1][1],
a + 1, (1 << (2 * a + 1)) - s->no_rounding,
s->h_edge_pos >> 1, s->v_edge_pos >> 1);
ptr = ref_picture[2];
s->mdsp.gmc(dest_cr, ptr, uvlinesize, 8,
ox, oy,
s->sprite_delta[0][0], s->sprite_delta[0][1],
s->sprite_delta[1][0], s->sprite_delta[1][1],
a + 1, (1 << (2 * a + 1)) - s->no_rounding,
s->h_edge_pos >> 1, s->v_edge_pos >> 1);
}
|
DoS
| 0
|
static void gmc_motion(MpegEncContext *s,
uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
uint8_t **ref_picture)
{
uint8_t *ptr;
int linesize, uvlinesize;
const int a = s->sprite_warping_accuracy;
int ox, oy;
linesize = s->linesize;
uvlinesize = s->uvlinesize;
ptr = ref_picture[0];
ox = s->sprite_offset[0][0] + s->sprite_delta[0][0] * s->mb_x * 16 +
s->sprite_delta[0][1] * s->mb_y * 16;
oy = s->sprite_offset[0][1] + s->sprite_delta[1][0] * s->mb_x * 16 +
s->sprite_delta[1][1] * s->mb_y * 16;
s->mdsp.gmc(dest_y, ptr, linesize, 16,
ox, oy,
s->sprite_delta[0][0], s->sprite_delta[0][1],
s->sprite_delta[1][0], s->sprite_delta[1][1],
a + 1, (1 << (2 * a + 1)) - s->no_rounding,
s->h_edge_pos, s->v_edge_pos);
s->mdsp.gmc(dest_y + 8, ptr, linesize, 16,
ox + s->sprite_delta[0][0] * 8,
oy + s->sprite_delta[1][0] * 8,
s->sprite_delta[0][0], s->sprite_delta[0][1],
s->sprite_delta[1][0], s->sprite_delta[1][1],
a + 1, (1 << (2 * a + 1)) - s->no_rounding,
s->h_edge_pos, s->v_edge_pos);
if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY)
return;
ox = s->sprite_offset[1][0] + s->sprite_delta[0][0] * s->mb_x * 8 +
s->sprite_delta[0][1] * s->mb_y * 8;
oy = s->sprite_offset[1][1] + s->sprite_delta[1][0] * s->mb_x * 8 +
s->sprite_delta[1][1] * s->mb_y * 8;
ptr = ref_picture[1];
s->mdsp.gmc(dest_cb, ptr, uvlinesize, 8,
ox, oy,
s->sprite_delta[0][0], s->sprite_delta[0][1],
s->sprite_delta[1][0], s->sprite_delta[1][1],
a + 1, (1 << (2 * a + 1)) - s->no_rounding,
s->h_edge_pos >> 1, s->v_edge_pos >> 1);
ptr = ref_picture[2];
s->mdsp.gmc(dest_cr, ptr, uvlinesize, 8,
ox, oy,
s->sprite_delta[0][0], s->sprite_delta[0][1],
s->sprite_delta[1][0], s->sprite_delta[1][1],
a + 1, (1 << (2 * a + 1)) - s->no_rounding,
s->h_edge_pos >> 1, s->v_edge_pos >> 1);
}
|
@@ -210,17 +210,14 @@ static inline int hpel_motion(MpegEncContext *s,
dxy |= (motion_y & 1) << 1;
src += src_y * s->linesize + src_x;
- if (s->unrestricted_mv) {
- if ((unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x & 1) - 8, 0) ||
- (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y & 1) - 8, 0)) {
- s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, src,
- s->linesize, s->linesize,
- 9, 9,
- src_x, src_y, s->h_edge_pos,
- s->v_edge_pos);
- src = s->sc.edge_emu_buffer;
- emu = 1;
- }
+ if ((unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x & 1) - 8, 0) ||
+ (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y & 1) - 8, 0)) {
+ s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, src,
+ s->linesize, s->linesize,
+ 9, 9, src_x, src_y,
+ s->h_edge_pos, s->v_edge_pos);
+ src = s->sc.edge_emu_buffer;
+ emu = 1;
}
pix_op[dxy](dest, src, s->linesize, 8);
return emu;
|
CWE-476
| null | null |
6,658
|
static int mptsas_build_sgl(MPTSASState *s, MPTSASRequest *req, hwaddr addr)
{
PCIDevice *pci = (PCIDevice *) s;
hwaddr next_chain_addr;
uint32_t left;
hwaddr sgaddr;
uint32_t chain_offset;
chain_offset = req->scsi_io.ChainOffset;
next_chain_addr = addr + chain_offset * sizeof(uint32_t);
sgaddr = addr + sizeof(MPIMsgSCSIIORequest);
pci_dma_sglist_init(&req->qsg, pci, 4);
left = req->scsi_io.DataLength;
for(;;) {
dma_addr_t addr, len;
uint32_t flags_and_length;
flags_and_length = ldl_le_pci_dma(pci, sgaddr);
len = flags_and_length & MPI_SGE_LENGTH_MASK;
if ((flags_and_length & MPI_SGE_FLAGS_ELEMENT_TYPE_MASK)
!= MPI_SGE_FLAGS_SIMPLE_ELEMENT ||
(!len &&
!(flags_and_length & MPI_SGE_FLAGS_END_OF_LIST) &&
!(flags_and_length & MPI_SGE_FLAGS_END_OF_BUFFER))) {
return MPI_IOCSTATUS_INVALID_SGL;
}
len = MIN(len, left);
if (!len) {
/* We reached the desired transfer length, ignore extra
* elements of the s/g list.
*/
break;
}
addr = mptsas_ld_sg_base(s, flags_and_length, &sgaddr);
qemu_sglist_add(&req->qsg, addr, len);
left -= len;
if (flags_and_length & MPI_SGE_FLAGS_END_OF_LIST) {
break;
}
if (flags_and_length & MPI_SGE_FLAGS_LAST_ELEMENT) {
if (!chain_offset) {
break;
}
flags_and_length = ldl_le_pci_dma(pci, next_chain_addr);
if ((flags_and_length & MPI_SGE_FLAGS_ELEMENT_TYPE_MASK)
!= MPI_SGE_FLAGS_CHAIN_ELEMENT) {
return MPI_IOCSTATUS_INVALID_SGL;
}
sgaddr = mptsas_ld_sg_base(s, flags_and_length, &next_chain_addr);
chain_offset =
(flags_and_length & MPI_SGE_CHAIN_OFFSET_MASK) >> MPI_SGE_CHAIN_OFFSET_SHIFT;
next_chain_addr = sgaddr + chain_offset * sizeof(uint32_t);
}
}
return 0;
}
|
DoS
| 0
|
static int mptsas_build_sgl(MPTSASState *s, MPTSASRequest *req, hwaddr addr)
{
PCIDevice *pci = (PCIDevice *) s;
hwaddr next_chain_addr;
uint32_t left;
hwaddr sgaddr;
uint32_t chain_offset;
chain_offset = req->scsi_io.ChainOffset;
next_chain_addr = addr + chain_offset * sizeof(uint32_t);
sgaddr = addr + sizeof(MPIMsgSCSIIORequest);
pci_dma_sglist_init(&req->qsg, pci, 4);
left = req->scsi_io.DataLength;
for(;;) {
dma_addr_t addr, len;
uint32_t flags_and_length;
flags_and_length = ldl_le_pci_dma(pci, sgaddr);
len = flags_and_length & MPI_SGE_LENGTH_MASK;
if ((flags_and_length & MPI_SGE_FLAGS_ELEMENT_TYPE_MASK)
!= MPI_SGE_FLAGS_SIMPLE_ELEMENT ||
(!len &&
!(flags_and_length & MPI_SGE_FLAGS_END_OF_LIST) &&
!(flags_and_length & MPI_SGE_FLAGS_END_OF_BUFFER))) {
return MPI_IOCSTATUS_INVALID_SGL;
}
len = MIN(len, left);
if (!len) {
/* We reached the desired transfer length, ignore extra
* elements of the s/g list.
*/
break;
}
addr = mptsas_ld_sg_base(s, flags_and_length, &sgaddr);
qemu_sglist_add(&req->qsg, addr, len);
left -= len;
if (flags_and_length & MPI_SGE_FLAGS_END_OF_LIST) {
break;
}
if (flags_and_length & MPI_SGE_FLAGS_LAST_ELEMENT) {
if (!chain_offset) {
break;
}
flags_and_length = ldl_le_pci_dma(pci, next_chain_addr);
if ((flags_and_length & MPI_SGE_FLAGS_ELEMENT_TYPE_MASK)
!= MPI_SGE_FLAGS_CHAIN_ELEMENT) {
return MPI_IOCSTATUS_INVALID_SGL;
}
sgaddr = mptsas_ld_sg_base(s, flags_and_length, &next_chain_addr);
chain_offset =
(flags_and_length & MPI_SGE_CHAIN_OFFSET_MASK) >> MPI_SGE_CHAIN_OFFSET_SHIFT;
next_chain_addr = sgaddr + chain_offset * sizeof(uint32_t);
}
}
return 0;
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,659
|
static void mptsas_cancel_notify(Notifier *notifier, void *data)
{
MPTSASCancelNotifier *n = container_of(notifier,
MPTSASCancelNotifier,
notifier);
/* Abusing IOCLogInfo to store the expected number of requests... */
if (++n->reply->TerminationCount == n->reply->IOCLogInfo) {
n->reply->IOCLogInfo = 0;
mptsas_fix_scsi_task_mgmt_reply_endianness(n->reply);
mptsas_post_reply(n->s, (MPIDefaultReply *)n->reply);
g_free(n->reply);
}
g_free(n);
}
|
DoS
| 0
|
static void mptsas_cancel_notify(Notifier *notifier, void *data)
{
MPTSASCancelNotifier *n = container_of(notifier,
MPTSASCancelNotifier,
notifier);
/* Abusing IOCLogInfo to store the expected number of requests... */
if (++n->reply->TerminationCount == n->reply->IOCLogInfo) {
n->reply->IOCLogInfo = 0;
mptsas_fix_scsi_task_mgmt_reply_endianness(n->reply);
mptsas_post_reply(n->s, (MPIDefaultReply *)n->reply);
g_free(n->reply);
}
g_free(n);
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,660
|
static uint64_t mptsas_diag_read(void *opaque, hwaddr addr,
unsigned size)
{
MPTSASState *s = opaque;
trace_mptsas_diag_read(s, addr, 0);
return 0;
}
|
DoS
| 0
|
static uint64_t mptsas_diag_read(void *opaque, hwaddr addr,
unsigned size)
{
MPTSASState *s = opaque;
trace_mptsas_diag_read(s, addr, 0);
return 0;
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,661
|
static void mptsas_diag_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
MPTSASState *s = opaque;
trace_mptsas_diag_write(s, addr, val);
}
|
DoS
| 0
|
static void mptsas_diag_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
MPTSASState *s = opaque;
trace_mptsas_diag_write(s, addr, val);
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,662
|
static uint32_t mptsas_doorbell_read(MPTSASState *s)
{
uint32_t ret;
ret = (s->who_init << MPI_DOORBELL_WHO_INIT_SHIFT) & MPI_DOORBELL_WHO_INIT_MASK;
ret |= s->state;
switch (s->doorbell_state) {
case DOORBELL_NONE:
break;
case DOORBELL_WRITE:
ret |= MPI_DOORBELL_ACTIVE;
break;
case DOORBELL_READ:
/* Get rid of the IOC fault code. */
ret &= ~MPI_DOORBELL_DATA_MASK;
assert(s->intr_status & MPI_HIS_DOORBELL_INTERRUPT);
assert(s->doorbell_reply_idx <= s->doorbell_reply_size);
ret |= MPI_DOORBELL_ACTIVE;
if (s->doorbell_reply_idx < s->doorbell_reply_size) {
/* For more information about this endian switch, see the
* commit message for commit 36b62ae ("fw_cfg: fix endianness in
* fw_cfg_data_mem_read() / _write()", 2015-01-16).
*/
ret |= le16_to_cpu(s->doorbell_reply[s->doorbell_reply_idx++]);
}
break;
default:
abort();
}
return ret;
}
|
DoS
| 0
|
static uint32_t mptsas_doorbell_read(MPTSASState *s)
{
uint32_t ret;
ret = (s->who_init << MPI_DOORBELL_WHO_INIT_SHIFT) & MPI_DOORBELL_WHO_INIT_MASK;
ret |= s->state;
switch (s->doorbell_state) {
case DOORBELL_NONE:
break;
case DOORBELL_WRITE:
ret |= MPI_DOORBELL_ACTIVE;
break;
case DOORBELL_READ:
/* Get rid of the IOC fault code. */
ret &= ~MPI_DOORBELL_DATA_MASK;
assert(s->intr_status & MPI_HIS_DOORBELL_INTERRUPT);
assert(s->doorbell_reply_idx <= s->doorbell_reply_size);
ret |= MPI_DOORBELL_ACTIVE;
if (s->doorbell_reply_idx < s->doorbell_reply_size) {
/* For more information about this endian switch, see the
* commit message for commit 36b62ae ("fw_cfg: fix endianness in
* fw_cfg_data_mem_read() / _write()", 2015-01-16).
*/
ret |= le16_to_cpu(s->doorbell_reply[s->doorbell_reply_idx++]);
}
break;
default:
abort();
}
return ret;
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,663
|
static void mptsas_doorbell_write(MPTSASState *s, uint32_t val)
{
if (s->doorbell_state == DOORBELL_WRITE) {
if (s->doorbell_idx < s->doorbell_cnt) {
/* For more information about this endian switch, see the
* commit message for commit 36b62ae ("fw_cfg: fix endianness in
* fw_cfg_data_mem_read() / _write()", 2015-01-16).
*/
s->doorbell_msg[s->doorbell_idx++] = cpu_to_le32(val);
if (s->doorbell_idx == s->doorbell_cnt) {
mptsas_process_message(s, (MPIRequestHeader *)s->doorbell_msg);
}
}
return;
}
switch ((val & MPI_DOORBELL_FUNCTION_MASK) >> MPI_DOORBELL_FUNCTION_SHIFT) {
case MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET:
mptsas_soft_reset(s);
break;
case MPI_FUNCTION_IO_UNIT_RESET:
break;
case MPI_FUNCTION_HANDSHAKE:
s->doorbell_state = DOORBELL_WRITE;
s->doorbell_idx = 0;
s->doorbell_cnt = (val & MPI_DOORBELL_ADD_DWORDS_MASK)
>> MPI_DOORBELL_ADD_DWORDS_SHIFT;
s->intr_status |= MPI_HIS_DOORBELL_INTERRUPT;
mptsas_update_interrupt(s);
break;
default:
trace_mptsas_unhandled_doorbell_cmd(s, val);
break;
}
}
|
DoS
| 0
|
static void mptsas_doorbell_write(MPTSASState *s, uint32_t val)
{
if (s->doorbell_state == DOORBELL_WRITE) {
if (s->doorbell_idx < s->doorbell_cnt) {
/* For more information about this endian switch, see the
* commit message for commit 36b62ae ("fw_cfg: fix endianness in
* fw_cfg_data_mem_read() / _write()", 2015-01-16).
*/
s->doorbell_msg[s->doorbell_idx++] = cpu_to_le32(val);
if (s->doorbell_idx == s->doorbell_cnt) {
mptsas_process_message(s, (MPIRequestHeader *)s->doorbell_msg);
}
}
return;
}
switch ((val & MPI_DOORBELL_FUNCTION_MASK) >> MPI_DOORBELL_FUNCTION_SHIFT) {
case MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET:
mptsas_soft_reset(s);
break;
case MPI_FUNCTION_IO_UNIT_RESET:
break;
case MPI_FUNCTION_HANDSHAKE:
s->doorbell_state = DOORBELL_WRITE;
s->doorbell_idx = 0;
s->doorbell_cnt = (val & MPI_DOORBELL_ADD_DWORDS_MASK)
>> MPI_DOORBELL_ADD_DWORDS_SHIFT;
s->intr_status |= MPI_HIS_DOORBELL_INTERRUPT;
mptsas_update_interrupt(s);
break;
default:
trace_mptsas_unhandled_doorbell_cmd(s, val);
break;
}
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,664
|
static void mptsas_fetch_request(MPTSASState *s)
{
PCIDevice *pci = (PCIDevice *) s;
char req[MPTSAS_MAX_REQUEST_SIZE];
MPIRequestHeader *hdr = (MPIRequestHeader *)req;
hwaddr addr;
int size;
/* Read the message header from the guest first. */
addr = s->host_mfa_high_addr | MPTSAS_FIFO_GET(s, request_post);
pci_dma_read(pci, addr, req, sizeof(hdr));
if (hdr->Function < ARRAY_SIZE(mpi_request_sizes) &&
mpi_request_sizes[hdr->Function]) {
/* Read the rest of the request based on the type. Do not
* reread everything, as that could cause a TOC/TOU mismatch
* and leak data from the QEMU stack.
*/
size = mpi_request_sizes[hdr->Function];
assert(size <= MPTSAS_MAX_REQUEST_SIZE);
pci_dma_read(pci, addr + sizeof(hdr), &req[sizeof(hdr)],
size - sizeof(hdr));
}
if (hdr->Function == MPI_FUNCTION_SCSI_IO_REQUEST) {
/* SCSI I/O requests are separate from mptsas_process_message
* because they cannot be sent through the doorbell yet.
*/
mptsas_process_scsi_io_request(s, (MPIMsgSCSIIORequest *)req, addr);
} else {
mptsas_process_message(s, (MPIRequestHeader *)req);
}
}
|
DoS
| 0
|
static void mptsas_fetch_request(MPTSASState *s)
{
PCIDevice *pci = (PCIDevice *) s;
char req[MPTSAS_MAX_REQUEST_SIZE];
MPIRequestHeader *hdr = (MPIRequestHeader *)req;
hwaddr addr;
int size;
/* Read the message header from the guest first. */
addr = s->host_mfa_high_addr | MPTSAS_FIFO_GET(s, request_post);
pci_dma_read(pci, addr, req, sizeof(hdr));
if (hdr->Function < ARRAY_SIZE(mpi_request_sizes) &&
mpi_request_sizes[hdr->Function]) {
/* Read the rest of the request based on the type. Do not
* reread everything, as that could cause a TOC/TOU mismatch
* and leak data from the QEMU stack.
*/
size = mpi_request_sizes[hdr->Function];
assert(size <= MPTSAS_MAX_REQUEST_SIZE);
pci_dma_read(pci, addr + sizeof(hdr), &req[sizeof(hdr)],
size - sizeof(hdr));
}
if (hdr->Function == MPI_FUNCTION_SCSI_IO_REQUEST) {
/* SCSI I/O requests are separate from mptsas_process_message
* because they cannot be sent through the doorbell yet.
*/
mptsas_process_scsi_io_request(s, (MPIMsgSCSIIORequest *)req, addr);
} else {
mptsas_process_message(s, (MPIRequestHeader *)req);
}
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,665
|
static void mptsas_fetch_requests(void *opaque)
{
MPTSASState *s = opaque;
if (s->state != MPI_IOC_STATE_OPERATIONAL) {
mptsas_set_fault(s, MPI_IOCSTATUS_INVALID_STATE);
return;
}
while (!MPTSAS_FIFO_EMPTY(s, request_post)) {
mptsas_fetch_request(s);
}
}
|
DoS
| 0
|
static void mptsas_fetch_requests(void *opaque)
{
MPTSASState *s = opaque;
if (s->state != MPI_IOC_STATE_OPERATIONAL) {
mptsas_set_fault(s, MPI_IOCSTATUS_INVALID_STATE);
return;
}
while (!MPTSAS_FIFO_EMPTY(s, request_post)) {
mptsas_fetch_request(s);
}
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,666
|
static void mptsas_free_request(MPTSASRequest *req)
{
MPTSASState *s = req->dev;
if (req->sreq != NULL) {
req->sreq->hba_private = NULL;
scsi_req_unref(req->sreq);
req->sreq = NULL;
QTAILQ_REMOVE(&s->pending, req, next);
}
qemu_sglist_destroy(&req->qsg);
g_free(req);
}
|
DoS
| 0
|
static void mptsas_free_request(MPTSASRequest *req)
{
MPTSASState *s = req->dev;
if (req->sreq != NULL) {
req->sreq->hba_private = NULL;
scsi_req_unref(req->sreq);
req->sreq = NULL;
QTAILQ_REMOVE(&s->pending, req, next);
}
qemu_sglist_destroy(&req->qsg);
g_free(req);
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,667
|
static QEMUSGList *mptsas_get_sg_list(SCSIRequest *sreq)
{
MPTSASRequest *req = sreq->hba_private;
return &req->qsg;
}
|
DoS
| 0
|
static QEMUSGList *mptsas_get_sg_list(SCSIRequest *sreq)
{
MPTSASRequest *req = sreq->hba_private;
return &req->qsg;
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,668
|
static int mptsas_hard_reset(MPTSASState *s)
{
mptsas_soft_reset(s);
s->intr_mask = MPI_HIM_DIM | MPI_HIM_RIM;
s->host_mfa_high_addr = 0;
s->sense_buffer_high_addr = 0;
s->reply_frame_size = 0;
s->max_devices = MPTSAS_NUM_PORTS;
s->max_buses = 1;
return 0;
}
|
DoS
| 0
|
static int mptsas_hard_reset(MPTSASState *s)
{
mptsas_soft_reset(s);
s->intr_mask = MPI_HIM_DIM | MPI_HIM_RIM;
s->host_mfa_high_addr = 0;
s->sense_buffer_high_addr = 0;
s->reply_frame_size = 0;
s->max_devices = MPTSAS_NUM_PORTS;
s->max_buses = 1;
return 0;
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,669
|
static void mptsas_interrupt_status_write(MPTSASState *s)
{
switch (s->doorbell_state) {
case DOORBELL_NONE:
case DOORBELL_WRITE:
s->intr_status &= ~MPI_HIS_DOORBELL_INTERRUPT;
break;
case DOORBELL_READ:
/* The reply can be read continuously, so leave the interrupt up. */
assert(s->intr_status & MPI_HIS_DOORBELL_INTERRUPT);
if (s->doorbell_reply_idx == s->doorbell_reply_size) {
s->doorbell_state = DOORBELL_NONE;
}
break;
default:
abort();
}
mptsas_update_interrupt(s);
}
|
DoS
| 0
|
static void mptsas_interrupt_status_write(MPTSASState *s)
{
switch (s->doorbell_state) {
case DOORBELL_NONE:
case DOORBELL_WRITE:
s->intr_status &= ~MPI_HIS_DOORBELL_INTERRUPT;
break;
case DOORBELL_READ:
/* The reply can be read continuously, so leave the interrupt up. */
assert(s->intr_status & MPI_HIS_DOORBELL_INTERRUPT);
if (s->doorbell_reply_idx == s->doorbell_reply_size) {
s->doorbell_state = DOORBELL_NONE;
}
break;
default:
abort();
}
mptsas_update_interrupt(s);
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,670
|
static dma_addr_t mptsas_ld_sg_base(MPTSASState *s, uint32_t flags_and_length,
dma_addr_t *sgaddr)
{
PCIDevice *pci = (PCIDevice *) s;
dma_addr_t addr;
if (flags_and_length & MPI_SGE_FLAGS_64_BIT_ADDRESSING) {
addr = ldq_le_pci_dma(pci, *sgaddr + 4);
*sgaddr += 12;
} else {
addr = ldl_le_pci_dma(pci, *sgaddr + 4);
*sgaddr += 8;
}
return addr;
}
|
DoS
| 0
|
static dma_addr_t mptsas_ld_sg_base(MPTSASState *s, uint32_t flags_and_length,
dma_addr_t *sgaddr)
{
PCIDevice *pci = (PCIDevice *) s;
dma_addr_t addr;
if (flags_and_length & MPI_SGE_FLAGS_64_BIT_ADDRESSING) {
addr = ldq_le_pci_dma(pci, *sgaddr + 4);
*sgaddr += 12;
} else {
addr = ldl_le_pci_dma(pci, *sgaddr + 4);
*sgaddr += 8;
}
return addr;
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,671
|
static void *mptsas_load_request(QEMUFile *f, SCSIRequest *sreq)
{
SCSIBus *bus = sreq->bus;
MPTSASState *s = container_of(bus, MPTSASState, bus);
PCIDevice *pci = PCI_DEVICE(s);
MPTSASRequest *req;
int i, n;
req = g_new(MPTSASRequest, 1);
qemu_get_buffer(f, (unsigned char *)&req->scsi_io, sizeof(req->scsi_io));
n = qemu_get_be32(f);
/* TODO: add a way for SCSIBusInfo's load_request to fail,
* and fail migration instead of asserting here.
* When we do, we might be able to re-enable NDEBUG below.
*/
#ifdef NDEBUG
#error building with NDEBUG is not supported
#endif
assert(n >= 0);
pci_dma_sglist_init(&req->qsg, pci, n);
for (i = 0; i < n; i++) {
uint64_t base = qemu_get_be64(f);
uint64_t len = qemu_get_be64(f);
qemu_sglist_add(&req->qsg, base, len);
}
scsi_req_ref(sreq);
req->sreq = sreq;
req->dev = s;
return req;
}
|
DoS
| 0
|
static void *mptsas_load_request(QEMUFile *f, SCSIRequest *sreq)
{
SCSIBus *bus = sreq->bus;
MPTSASState *s = container_of(bus, MPTSASState, bus);
PCIDevice *pci = PCI_DEVICE(s);
MPTSASRequest *req;
int i, n;
req = g_new(MPTSASRequest, 1);
qemu_get_buffer(f, (unsigned char *)&req->scsi_io, sizeof(req->scsi_io));
n = qemu_get_be32(f);
/* TODO: add a way for SCSIBusInfo's load_request to fail,
* and fail migration instead of asserting here.
* When we do, we might be able to re-enable NDEBUG below.
*/
#ifdef NDEBUG
#error building with NDEBUG is not supported
#endif
assert(n >= 0);
pci_dma_sglist_init(&req->qsg, pci, n);
for (i = 0; i < n; i++) {
uint64_t base = qemu_get_be64(f);
uint64_t len = qemu_get_be64(f);
qemu_sglist_add(&req->qsg, base, len);
}
scsi_req_ref(sreq);
req->sreq = sreq;
req->dev = s;
return req;
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,672
|
static void mptsas_mmio_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
MPTSASState *s = opaque;
trace_mptsas_mmio_write(s, addr, val);
switch (addr) {
case MPI_DOORBELL_OFFSET:
mptsas_doorbell_write(s, val);
break;
case MPI_WRITE_SEQUENCE_OFFSET:
mptsas_write_sequence_write(s, val);
break;
case MPI_DIAGNOSTIC_OFFSET:
if (val & MPI_DIAG_RESET_ADAPTER) {
mptsas_hard_reset(s);
}
break;
case MPI_HOST_INTERRUPT_STATUS_OFFSET:
mptsas_interrupt_status_write(s);
break;
case MPI_HOST_INTERRUPT_MASK_OFFSET:
s->intr_mask = val & (MPI_HIM_RIM | MPI_HIM_DIM);
mptsas_update_interrupt(s);
break;
case MPI_REQUEST_POST_FIFO_OFFSET:
if (MPTSAS_FIFO_FULL(s, request_post)) {
mptsas_set_fault(s, MPI_IOCSTATUS_INSUFFICIENT_RESOURCES);
} else {
MPTSAS_FIFO_PUT(s, request_post, val & ~0x03);
qemu_bh_schedule(s->request_bh);
}
break;
case MPI_REPLY_FREE_FIFO_OFFSET:
if (MPTSAS_FIFO_FULL(s, reply_free)) {
mptsas_set_fault(s, MPI_IOCSTATUS_INSUFFICIENT_RESOURCES);
} else {
MPTSAS_FIFO_PUT(s, reply_free, val);
}
break;
default:
trace_mptsas_mmio_unhandled_write(s, addr, val);
break;
}
}
|
DoS
| 0
|
static void mptsas_mmio_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
MPTSASState *s = opaque;
trace_mptsas_mmio_write(s, addr, val);
switch (addr) {
case MPI_DOORBELL_OFFSET:
mptsas_doorbell_write(s, val);
break;
case MPI_WRITE_SEQUENCE_OFFSET:
mptsas_write_sequence_write(s, val);
break;
case MPI_DIAGNOSTIC_OFFSET:
if (val & MPI_DIAG_RESET_ADAPTER) {
mptsas_hard_reset(s);
}
break;
case MPI_HOST_INTERRUPT_STATUS_OFFSET:
mptsas_interrupt_status_write(s);
break;
case MPI_HOST_INTERRUPT_MASK_OFFSET:
s->intr_mask = val & (MPI_HIM_RIM | MPI_HIM_DIM);
mptsas_update_interrupt(s);
break;
case MPI_REQUEST_POST_FIFO_OFFSET:
if (MPTSAS_FIFO_FULL(s, request_post)) {
mptsas_set_fault(s, MPI_IOCSTATUS_INSUFFICIENT_RESOURCES);
} else {
MPTSAS_FIFO_PUT(s, request_post, val & ~0x03);
qemu_bh_schedule(s->request_bh);
}
break;
case MPI_REPLY_FREE_FIFO_OFFSET:
if (MPTSAS_FIFO_FULL(s, reply_free)) {
mptsas_set_fault(s, MPI_IOCSTATUS_INSUFFICIENT_RESOURCES);
} else {
MPTSAS_FIFO_PUT(s, reply_free, val);
}
break;
default:
trace_mptsas_mmio_unhandled_write(s, addr, val);
break;
}
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,673
|
static int mptsas_post_load(void *opaque, int version_id)
{
MPTSASState *s = opaque;
if (s->doorbell_idx > s->doorbell_cnt ||
s->doorbell_cnt > ARRAY_SIZE(s->doorbell_msg) ||
s->doorbell_reply_idx > s->doorbell_reply_size ||
s->doorbell_reply_size > ARRAY_SIZE(s->doorbell_reply) ||
MPTSAS_FIFO_INVALID(s, request_post) ||
MPTSAS_FIFO_INVALID(s, reply_post) ||
MPTSAS_FIFO_INVALID(s, reply_free) ||
s->diagnostic_idx > 4) {
return -EINVAL;
}
return 0;
}
|
DoS
| 0
|
static int mptsas_post_load(void *opaque, int version_id)
{
MPTSASState *s = opaque;
if (s->doorbell_idx > s->doorbell_cnt ||
s->doorbell_cnt > ARRAY_SIZE(s->doorbell_msg) ||
s->doorbell_reply_idx > s->doorbell_reply_size ||
s->doorbell_reply_size > ARRAY_SIZE(s->doorbell_reply) ||
MPTSAS_FIFO_INVALID(s, request_post) ||
MPTSAS_FIFO_INVALID(s, reply_post) ||
MPTSAS_FIFO_INVALID(s, reply_free) ||
s->diagnostic_idx > 4) {
return -EINVAL;
}
return 0;
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,674
|
static void mptsas_post_reply(MPTSASState *s, MPIDefaultReply *reply)
{
PCIDevice *pci = (PCIDevice *) s;
uint32_t addr_lo;
if (MPTSAS_FIFO_EMPTY(s, reply_free) || MPTSAS_FIFO_FULL(s, reply_post)) {
mptsas_set_fault(s, MPI_IOCSTATUS_INSUFFICIENT_RESOURCES);
return;
}
addr_lo = MPTSAS_FIFO_GET(s, reply_free);
pci_dma_write(pci, addr_lo | s->host_mfa_high_addr, reply,
MIN(s->reply_frame_size, 4 * reply->MsgLength));
MPTSAS_FIFO_PUT(s, reply_post, MPI_ADDRESS_REPLY_A_BIT | (addr_lo >> 1));
s->intr_status |= MPI_HIS_REPLY_MESSAGE_INTERRUPT;
if (s->doorbell_state == DOORBELL_WRITE) {
s->doorbell_state = DOORBELL_NONE;
s->intr_status |= MPI_HIS_DOORBELL_INTERRUPT;
}
mptsas_update_interrupt(s);
}
|
DoS
| 0
|
static void mptsas_post_reply(MPTSASState *s, MPIDefaultReply *reply)
{
PCIDevice *pci = (PCIDevice *) s;
uint32_t addr_lo;
if (MPTSAS_FIFO_EMPTY(s, reply_free) || MPTSAS_FIFO_FULL(s, reply_post)) {
mptsas_set_fault(s, MPI_IOCSTATUS_INSUFFICIENT_RESOURCES);
return;
}
addr_lo = MPTSAS_FIFO_GET(s, reply_free);
pci_dma_write(pci, addr_lo | s->host_mfa_high_addr, reply,
MIN(s->reply_frame_size, 4 * reply->MsgLength));
MPTSAS_FIFO_PUT(s, reply_post, MPI_ADDRESS_REPLY_A_BIT | (addr_lo >> 1));
s->intr_status |= MPI_HIS_REPLY_MESSAGE_INTERRUPT;
if (s->doorbell_state == DOORBELL_WRITE) {
s->doorbell_state = DOORBELL_NONE;
s->intr_status |= MPI_HIS_DOORBELL_INTERRUPT;
}
mptsas_update_interrupt(s);
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,675
|
static void mptsas_process_event_notification(MPTSASState *s,
MPIMsgEventNotify *req)
{
MPIMsgEventNotifyReply reply;
mptsas_fix_event_notification_endianness(req);
QEMU_BUILD_BUG_ON(MPTSAS_MAX_REQUEST_SIZE < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_msg) < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_reply) < sizeof(reply));
/* Don't even bother storing whether event notification is enabled,
* since it is not accessible.
*/
memset(&reply, 0, sizeof(reply));
reply.EventDataLength = sizeof(reply.Data) / 4;
reply.MsgLength = sizeof(reply) / 4;
reply.Function = req->Function;
/* This is set because events are sent through the reply FIFOs. */
reply.MsgFlags = MPI_MSGFLAGS_CONTINUATION_REPLY;
reply.MsgContext = req->MsgContext;
reply.Event = MPI_EVENT_EVENT_CHANGE;
reply.Data[0] = !!req->Switch;
mptsas_fix_event_notification_reply_endianness(&reply);
mptsas_reply(s, (MPIDefaultReply *)&reply);
}
|
DoS
| 0
|
static void mptsas_process_event_notification(MPTSASState *s,
MPIMsgEventNotify *req)
{
MPIMsgEventNotifyReply reply;
mptsas_fix_event_notification_endianness(req);
QEMU_BUILD_BUG_ON(MPTSAS_MAX_REQUEST_SIZE < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_msg) < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_reply) < sizeof(reply));
/* Don't even bother storing whether event notification is enabled,
* since it is not accessible.
*/
memset(&reply, 0, sizeof(reply));
reply.EventDataLength = sizeof(reply.Data) / 4;
reply.MsgLength = sizeof(reply) / 4;
reply.Function = req->Function;
/* This is set because events are sent through the reply FIFOs. */
reply.MsgFlags = MPI_MSGFLAGS_CONTINUATION_REPLY;
reply.MsgContext = req->MsgContext;
reply.Event = MPI_EVENT_EVENT_CHANGE;
reply.Data[0] = !!req->Switch;
mptsas_fix_event_notification_reply_endianness(&reply);
mptsas_reply(s, (MPIDefaultReply *)&reply);
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,676
|
static void mptsas_process_ioc_facts(MPTSASState *s,
MPIMsgIOCFacts *req)
{
MPIMsgIOCFactsReply reply;
mptsas_fix_ioc_facts_endianness(req);
QEMU_BUILD_BUG_ON(MPTSAS_MAX_REQUEST_SIZE < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_msg) < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_reply) < sizeof(reply));
memset(&reply, 0, sizeof(reply));
reply.MsgVersion = 0x0105;
reply.MsgLength = sizeof(reply) / 4;
reply.Function = req->Function;
reply.MsgContext = req->MsgContext;
reply.MaxChainDepth = MPTSAS_MAXIMUM_CHAIN_DEPTH;
reply.WhoInit = s->who_init;
reply.BlockSize = MPTSAS_MAX_REQUEST_SIZE / sizeof(uint32_t);
reply.ReplyQueueDepth = ARRAY_SIZE(s->reply_post) - 1;
QEMU_BUILD_BUG_ON(ARRAY_SIZE(s->reply_post) != ARRAY_SIZE(s->reply_free));
reply.RequestFrameSize = 128;
reply.ProductID = MPTSAS1068_PRODUCT_ID;
reply.CurrentHostMfaHighAddr = s->host_mfa_high_addr >> 32;
reply.GlobalCredits = ARRAY_SIZE(s->request_post) - 1;
reply.NumberOfPorts = MPTSAS_NUM_PORTS;
reply.CurrentSenseBufferHighAddr = s->sense_buffer_high_addr >> 32;
reply.CurReplyFrameSize = s->reply_frame_size;
reply.MaxDevices = s->max_devices;
reply.MaxBuses = s->max_buses;
reply.FWVersionDev = 0;
reply.FWVersionUnit = 0x92;
reply.FWVersionMinor = 0x32;
reply.FWVersionMajor = 0x1;
mptsas_fix_ioc_facts_reply_endianness(&reply);
mptsas_reply(s, (MPIDefaultReply *)&reply);
}
|
DoS
| 0
|
static void mptsas_process_ioc_facts(MPTSASState *s,
MPIMsgIOCFacts *req)
{
MPIMsgIOCFactsReply reply;
mptsas_fix_ioc_facts_endianness(req);
QEMU_BUILD_BUG_ON(MPTSAS_MAX_REQUEST_SIZE < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_msg) < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_reply) < sizeof(reply));
memset(&reply, 0, sizeof(reply));
reply.MsgVersion = 0x0105;
reply.MsgLength = sizeof(reply) / 4;
reply.Function = req->Function;
reply.MsgContext = req->MsgContext;
reply.MaxChainDepth = MPTSAS_MAXIMUM_CHAIN_DEPTH;
reply.WhoInit = s->who_init;
reply.BlockSize = MPTSAS_MAX_REQUEST_SIZE / sizeof(uint32_t);
reply.ReplyQueueDepth = ARRAY_SIZE(s->reply_post) - 1;
QEMU_BUILD_BUG_ON(ARRAY_SIZE(s->reply_post) != ARRAY_SIZE(s->reply_free));
reply.RequestFrameSize = 128;
reply.ProductID = MPTSAS1068_PRODUCT_ID;
reply.CurrentHostMfaHighAddr = s->host_mfa_high_addr >> 32;
reply.GlobalCredits = ARRAY_SIZE(s->request_post) - 1;
reply.NumberOfPorts = MPTSAS_NUM_PORTS;
reply.CurrentSenseBufferHighAddr = s->sense_buffer_high_addr >> 32;
reply.CurReplyFrameSize = s->reply_frame_size;
reply.MaxDevices = s->max_devices;
reply.MaxBuses = s->max_buses;
reply.FWVersionDev = 0;
reply.FWVersionUnit = 0x92;
reply.FWVersionMinor = 0x32;
reply.FWVersionMajor = 0x1;
mptsas_fix_ioc_facts_reply_endianness(&reply);
mptsas_reply(s, (MPIDefaultReply *)&reply);
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,677
|
static void mptsas_process_ioc_init(MPTSASState *s, MPIMsgIOCInit *req)
{
MPIMsgIOCInitReply reply;
mptsas_fix_ioc_init_endianness(req);
QEMU_BUILD_BUG_ON(MPTSAS_MAX_REQUEST_SIZE < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_msg) < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_reply) < sizeof(reply));
s->who_init = req->WhoInit;
s->reply_frame_size = req->ReplyFrameSize;
s->max_buses = req->MaxBuses;
s->max_devices = req->MaxDevices ? req->MaxDevices : 256;
s->host_mfa_high_addr = (hwaddr)req->HostMfaHighAddr << 32;
s->sense_buffer_high_addr = (hwaddr)req->SenseBufferHighAddr << 32;
if (s->state == MPI_IOC_STATE_READY) {
s->state = MPI_IOC_STATE_OPERATIONAL;
}
memset(&reply, 0, sizeof(reply));
reply.WhoInit = s->who_init;
reply.MsgLength = sizeof(reply) / 4;
reply.Function = req->Function;
reply.MaxDevices = s->max_devices;
reply.MaxBuses = s->max_buses;
reply.MsgContext = req->MsgContext;
mptsas_fix_ioc_init_reply_endianness(&reply);
mptsas_reply(s, (MPIDefaultReply *)&reply);
}
|
DoS
| 0
|
static void mptsas_process_ioc_init(MPTSASState *s, MPIMsgIOCInit *req)
{
MPIMsgIOCInitReply reply;
mptsas_fix_ioc_init_endianness(req);
QEMU_BUILD_BUG_ON(MPTSAS_MAX_REQUEST_SIZE < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_msg) < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_reply) < sizeof(reply));
s->who_init = req->WhoInit;
s->reply_frame_size = req->ReplyFrameSize;
s->max_buses = req->MaxBuses;
s->max_devices = req->MaxDevices ? req->MaxDevices : 256;
s->host_mfa_high_addr = (hwaddr)req->HostMfaHighAddr << 32;
s->sense_buffer_high_addr = (hwaddr)req->SenseBufferHighAddr << 32;
if (s->state == MPI_IOC_STATE_READY) {
s->state = MPI_IOC_STATE_OPERATIONAL;
}
memset(&reply, 0, sizeof(reply));
reply.WhoInit = s->who_init;
reply.MsgLength = sizeof(reply) / 4;
reply.Function = req->Function;
reply.MaxDevices = s->max_devices;
reply.MaxBuses = s->max_buses;
reply.MsgContext = req->MsgContext;
mptsas_fix_ioc_init_reply_endianness(&reply);
mptsas_reply(s, (MPIDefaultReply *)&reply);
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,678
|
static void mptsas_process_message(MPTSASState *s, MPIRequestHeader *req)
{
trace_mptsas_process_message(s, req->Function, req->MsgContext);
switch (req->Function) {
case MPI_FUNCTION_SCSI_TASK_MGMT:
mptsas_process_scsi_task_mgmt(s, (MPIMsgSCSITaskMgmt *)req);
break;
case MPI_FUNCTION_IOC_INIT:
mptsas_process_ioc_init(s, (MPIMsgIOCInit *)req);
break;
case MPI_FUNCTION_IOC_FACTS:
mptsas_process_ioc_facts(s, (MPIMsgIOCFacts *)req);
break;
case MPI_FUNCTION_PORT_FACTS:
mptsas_process_port_facts(s, (MPIMsgPortFacts *)req);
break;
case MPI_FUNCTION_PORT_ENABLE:
mptsas_process_port_enable(s, (MPIMsgPortEnable *)req);
break;
case MPI_FUNCTION_EVENT_NOTIFICATION:
mptsas_process_event_notification(s, (MPIMsgEventNotify *)req);
break;
case MPI_FUNCTION_CONFIG:
mptsas_process_config(s, (MPIMsgConfig *)req);
break;
default:
trace_mptsas_unhandled_cmd(s, req->Function, 0);
mptsas_set_fault(s, MPI_IOCSTATUS_INVALID_FUNCTION);
break;
}
}
|
DoS
| 0
|
static void mptsas_process_message(MPTSASState *s, MPIRequestHeader *req)
{
trace_mptsas_process_message(s, req->Function, req->MsgContext);
switch (req->Function) {
case MPI_FUNCTION_SCSI_TASK_MGMT:
mptsas_process_scsi_task_mgmt(s, (MPIMsgSCSITaskMgmt *)req);
break;
case MPI_FUNCTION_IOC_INIT:
mptsas_process_ioc_init(s, (MPIMsgIOCInit *)req);
break;
case MPI_FUNCTION_IOC_FACTS:
mptsas_process_ioc_facts(s, (MPIMsgIOCFacts *)req);
break;
case MPI_FUNCTION_PORT_FACTS:
mptsas_process_port_facts(s, (MPIMsgPortFacts *)req);
break;
case MPI_FUNCTION_PORT_ENABLE:
mptsas_process_port_enable(s, (MPIMsgPortEnable *)req);
break;
case MPI_FUNCTION_EVENT_NOTIFICATION:
mptsas_process_event_notification(s, (MPIMsgEventNotify *)req);
break;
case MPI_FUNCTION_CONFIG:
mptsas_process_config(s, (MPIMsgConfig *)req);
break;
default:
trace_mptsas_unhandled_cmd(s, req->Function, 0);
mptsas_set_fault(s, MPI_IOCSTATUS_INVALID_FUNCTION);
break;
}
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,679
|
static void mptsas_process_port_enable(MPTSASState *s,
MPIMsgPortEnable *req)
{
MPIMsgPortEnableReply reply;
mptsas_fix_port_enable_endianness(req);
QEMU_BUILD_BUG_ON(MPTSAS_MAX_REQUEST_SIZE < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_msg) < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_reply) < sizeof(reply));
memset(&reply, 0, sizeof(reply));
reply.MsgLength = sizeof(reply) / 4;
reply.PortNumber = req->PortNumber;
reply.Function = req->Function;
reply.MsgContext = req->MsgContext;
mptsas_fix_port_enable_reply_endianness(&reply);
mptsas_reply(s, (MPIDefaultReply *)&reply);
}
|
DoS
| 0
|
static void mptsas_process_port_enable(MPTSASState *s,
MPIMsgPortEnable *req)
{
MPIMsgPortEnableReply reply;
mptsas_fix_port_enable_endianness(req);
QEMU_BUILD_BUG_ON(MPTSAS_MAX_REQUEST_SIZE < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_msg) < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_reply) < sizeof(reply));
memset(&reply, 0, sizeof(reply));
reply.MsgLength = sizeof(reply) / 4;
reply.PortNumber = req->PortNumber;
reply.Function = req->Function;
reply.MsgContext = req->MsgContext;
mptsas_fix_port_enable_reply_endianness(&reply);
mptsas_reply(s, (MPIDefaultReply *)&reply);
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,680
|
static void mptsas_process_scsi_task_mgmt(MPTSASState *s, MPIMsgSCSITaskMgmt *req)
{
MPIMsgSCSITaskMgmtReply reply;
MPIMsgSCSITaskMgmtReply *reply_async;
int status, count;
SCSIDevice *sdev;
SCSIRequest *r, *next;
BusChild *kid;
mptsas_fix_scsi_task_mgmt_endianness(req);
QEMU_BUILD_BUG_ON(MPTSAS_MAX_REQUEST_SIZE < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_msg) < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_reply) < sizeof(reply));
memset(&reply, 0, sizeof(reply));
reply.TargetID = req->TargetID;
reply.Bus = req->Bus;
reply.MsgLength = sizeof(reply) / 4;
reply.Function = req->Function;
reply.TaskType = req->TaskType;
reply.MsgContext = req->MsgContext;
switch (req->TaskType) {
case MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
case MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
status = mptsas_scsi_device_find(s, req->Bus, req->TargetID,
req->LUN, &sdev);
if (status) {
reply.IOCStatus = status;
goto out;
}
if (sdev->lun != req->LUN[1]) {
reply.ResponseCode = MPI_SCSITASKMGMT_RSP_TM_INVALID_LUN;
goto out;
}
QTAILQ_FOREACH_SAFE(r, &sdev->requests, next, next) {
MPTSASRequest *cmd_req = r->hba_private;
if (cmd_req && cmd_req->scsi_io.MsgContext == req->TaskMsgContext) {
break;
}
}
if (r) {
/*
* Assert that the request has not been completed yet, we
* check for it in the loop above.
*/
assert(r->hba_private);
if (req->TaskType == MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK) {
/* "If the specified command is present in the task set, then
* return a service response set to FUNCTION SUCCEEDED".
*/
reply.ResponseCode = MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED;
} else {
MPTSASCancelNotifier *notifier;
reply_async = g_memdup(&reply, sizeof(MPIMsgSCSITaskMgmtReply));
reply_async->IOCLogInfo = INT_MAX;
count = 1;
notifier = g_new(MPTSASCancelNotifier, 1);
notifier->s = s;
notifier->reply = reply_async;
notifier->notifier.notify = mptsas_cancel_notify;
scsi_req_cancel_async(r, ¬ifier->notifier);
goto reply_maybe_async;
}
}
break;
case MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
case MPI_SCSITASKMGMT_TASKTYPE_CLEAR_TASK_SET:
status = mptsas_scsi_device_find(s, req->Bus, req->TargetID,
req->LUN, &sdev);
if (status) {
reply.IOCStatus = status;
goto out;
}
if (sdev->lun != req->LUN[1]) {
reply.ResponseCode = MPI_SCSITASKMGMT_RSP_TM_INVALID_LUN;
goto out;
}
reply_async = g_memdup(&reply, sizeof(MPIMsgSCSITaskMgmtReply));
reply_async->IOCLogInfo = INT_MAX;
count = 0;
QTAILQ_FOREACH_SAFE(r, &sdev->requests, next, next) {
if (r->hba_private) {
MPTSASCancelNotifier *notifier;
count++;
notifier = g_new(MPTSASCancelNotifier, 1);
notifier->s = s;
notifier->reply = reply_async;
notifier->notifier.notify = mptsas_cancel_notify;
scsi_req_cancel_async(r, ¬ifier->notifier);
}
}
reply_maybe_async:
if (reply_async->TerminationCount < count) {
reply_async->IOCLogInfo = count;
return;
}
g_free(reply_async);
reply.TerminationCount = count;
break;
case MPI_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
status = mptsas_scsi_device_find(s, req->Bus, req->TargetID,
req->LUN, &sdev);
if (status) {
reply.IOCStatus = status;
goto out;
}
if (sdev->lun != req->LUN[1]) {
reply.ResponseCode = MPI_SCSITASKMGMT_RSP_TM_INVALID_LUN;
goto out;
}
qdev_reset_all(&sdev->qdev);
break;
case MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
if (req->Bus != 0) {
reply.IOCStatus = MPI_IOCSTATUS_SCSI_INVALID_BUS;
goto out;
}
if (req->TargetID > s->max_devices) {
reply.IOCStatus = MPI_IOCSTATUS_SCSI_INVALID_TARGETID;
goto out;
}
QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) {
sdev = SCSI_DEVICE(kid->child);
if (sdev->channel == 0 && sdev->id == req->TargetID) {
qdev_reset_all(kid->child);
}
}
break;
case MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS:
qbus_reset_all(&s->bus.qbus);
break;
default:
reply.ResponseCode = MPI_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED;
break;
}
out:
mptsas_fix_scsi_task_mgmt_reply_endianness(&reply);
mptsas_post_reply(s, (MPIDefaultReply *)&reply);
}
|
DoS
| 0
|
static void mptsas_process_scsi_task_mgmt(MPTSASState *s, MPIMsgSCSITaskMgmt *req)
{
MPIMsgSCSITaskMgmtReply reply;
MPIMsgSCSITaskMgmtReply *reply_async;
int status, count;
SCSIDevice *sdev;
SCSIRequest *r, *next;
BusChild *kid;
mptsas_fix_scsi_task_mgmt_endianness(req);
QEMU_BUILD_BUG_ON(MPTSAS_MAX_REQUEST_SIZE < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_msg) < sizeof(*req));
QEMU_BUILD_BUG_ON(sizeof(s->doorbell_reply) < sizeof(reply));
memset(&reply, 0, sizeof(reply));
reply.TargetID = req->TargetID;
reply.Bus = req->Bus;
reply.MsgLength = sizeof(reply) / 4;
reply.Function = req->Function;
reply.TaskType = req->TaskType;
reply.MsgContext = req->MsgContext;
switch (req->TaskType) {
case MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
case MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
status = mptsas_scsi_device_find(s, req->Bus, req->TargetID,
req->LUN, &sdev);
if (status) {
reply.IOCStatus = status;
goto out;
}
if (sdev->lun != req->LUN[1]) {
reply.ResponseCode = MPI_SCSITASKMGMT_RSP_TM_INVALID_LUN;
goto out;
}
QTAILQ_FOREACH_SAFE(r, &sdev->requests, next, next) {
MPTSASRequest *cmd_req = r->hba_private;
if (cmd_req && cmd_req->scsi_io.MsgContext == req->TaskMsgContext) {
break;
}
}
if (r) {
/*
* Assert that the request has not been completed yet, we
* check for it in the loop above.
*/
assert(r->hba_private);
if (req->TaskType == MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK) {
/* "If the specified command is present in the task set, then
* return a service response set to FUNCTION SUCCEEDED".
*/
reply.ResponseCode = MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED;
} else {
MPTSASCancelNotifier *notifier;
reply_async = g_memdup(&reply, sizeof(MPIMsgSCSITaskMgmtReply));
reply_async->IOCLogInfo = INT_MAX;
count = 1;
notifier = g_new(MPTSASCancelNotifier, 1);
notifier->s = s;
notifier->reply = reply_async;
notifier->notifier.notify = mptsas_cancel_notify;
scsi_req_cancel_async(r, ¬ifier->notifier);
goto reply_maybe_async;
}
}
break;
case MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
case MPI_SCSITASKMGMT_TASKTYPE_CLEAR_TASK_SET:
status = mptsas_scsi_device_find(s, req->Bus, req->TargetID,
req->LUN, &sdev);
if (status) {
reply.IOCStatus = status;
goto out;
}
if (sdev->lun != req->LUN[1]) {
reply.ResponseCode = MPI_SCSITASKMGMT_RSP_TM_INVALID_LUN;
goto out;
}
reply_async = g_memdup(&reply, sizeof(MPIMsgSCSITaskMgmtReply));
reply_async->IOCLogInfo = INT_MAX;
count = 0;
QTAILQ_FOREACH_SAFE(r, &sdev->requests, next, next) {
if (r->hba_private) {
MPTSASCancelNotifier *notifier;
count++;
notifier = g_new(MPTSASCancelNotifier, 1);
notifier->s = s;
notifier->reply = reply_async;
notifier->notifier.notify = mptsas_cancel_notify;
scsi_req_cancel_async(r, ¬ifier->notifier);
}
}
reply_maybe_async:
if (reply_async->TerminationCount < count) {
reply_async->IOCLogInfo = count;
return;
}
g_free(reply_async);
reply.TerminationCount = count;
break;
case MPI_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
status = mptsas_scsi_device_find(s, req->Bus, req->TargetID,
req->LUN, &sdev);
if (status) {
reply.IOCStatus = status;
goto out;
}
if (sdev->lun != req->LUN[1]) {
reply.ResponseCode = MPI_SCSITASKMGMT_RSP_TM_INVALID_LUN;
goto out;
}
qdev_reset_all(&sdev->qdev);
break;
case MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
if (req->Bus != 0) {
reply.IOCStatus = MPI_IOCSTATUS_SCSI_INVALID_BUS;
goto out;
}
if (req->TargetID > s->max_devices) {
reply.IOCStatus = MPI_IOCSTATUS_SCSI_INVALID_TARGETID;
goto out;
}
QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) {
sdev = SCSI_DEVICE(kid->child);
if (sdev->channel == 0 && sdev->id == req->TargetID) {
qdev_reset_all(kid->child);
}
}
break;
case MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS:
qbus_reset_all(&s->bus.qbus);
break;
default:
reply.ResponseCode = MPI_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED;
break;
}
out:
mptsas_fix_scsi_task_mgmt_reply_endianness(&reply);
mptsas_post_reply(s, (MPIDefaultReply *)&reply);
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,681
|
static void mptsas_register_types(void)
{
type_register(&mptsas_info);
}
|
DoS
| 0
|
static void mptsas_register_types(void)
{
type_register(&mptsas_info);
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,682
|
void mptsas_reply(MPTSASState *s, MPIDefaultReply *reply)
{
if (s->doorbell_state == DOORBELL_WRITE) {
/* The reply is sent out in 16 bit chunks, while the size
* in the reply is in 32 bit units.
*/
s->doorbell_state = DOORBELL_READ;
s->doorbell_reply_idx = 0;
s->doorbell_reply_size = reply->MsgLength * 2;
memcpy(s->doorbell_reply, reply, s->doorbell_reply_size * 2);
s->intr_status |= MPI_HIS_DOORBELL_INTERRUPT;
mptsas_update_interrupt(s);
} else {
mptsas_post_reply(s, reply);
}
}
|
DoS
| 0
|
void mptsas_reply(MPTSASState *s, MPIDefaultReply *reply)
{
if (s->doorbell_state == DOORBELL_WRITE) {
/* The reply is sent out in 16 bit chunks, while the size
* in the reply is in 32 bit units.
*/
s->doorbell_state = DOORBELL_READ;
s->doorbell_reply_idx = 0;
s->doorbell_reply_size = reply->MsgLength * 2;
memcpy(s->doorbell_reply, reply, s->doorbell_reply_size * 2);
s->intr_status |= MPI_HIS_DOORBELL_INTERRUPT;
mptsas_update_interrupt(s);
} else {
mptsas_post_reply(s, reply);
}
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,683
|
static void mptsas_scsi_init(PCIDevice *dev, Error **errp)
{
DeviceState *d = DEVICE(dev);
MPTSASState *s = MPT_SAS(dev);
Error *err = NULL;
int ret;
dev->config[PCI_LATENCY_TIMER] = 0;
dev->config[PCI_INTERRUPT_PIN] = 0x01;
if (s->msi != ON_OFF_AUTO_OFF) {
ret = msi_init(dev, 0, 1, true, false, &err);
/* Any error other than -ENOTSUP(board's MSI support is broken)
* is a programming error */
assert(!ret || ret == -ENOTSUP);
if (ret && s->msi == ON_OFF_AUTO_ON) {
/* Can't satisfy user's explicit msi=on request, fail */
error_append_hint(&err, "You have to use msi=auto (default) or "
"msi=off with this machine type.\n");
error_propagate(errp, err);
return;
}
assert(!err || s->msi == ON_OFF_AUTO_AUTO);
/* With msi=auto, we fall back to MSI off silently */
error_free(err);
/* Only used for migration. */
s->msi_in_use = (ret == 0);
}
memory_region_init_io(&s->mmio_io, OBJECT(s), &mptsas_mmio_ops, s,
"mptsas-mmio", 0x4000);
memory_region_init_io(&s->port_io, OBJECT(s), &mptsas_port_ops, s,
"mptsas-io", 256);
memory_region_init_io(&s->diag_io, OBJECT(s), &mptsas_diag_ops, s,
"mptsas-diag", 0x10000);
pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->port_io);
pci_register_bar(dev, 1, PCI_BASE_ADDRESS_SPACE_MEMORY |
PCI_BASE_ADDRESS_MEM_TYPE_32, &s->mmio_io);
pci_register_bar(dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY |
PCI_BASE_ADDRESS_MEM_TYPE_32, &s->diag_io);
if (!s->sas_addr) {
s->sas_addr = ((NAA_LOCALLY_ASSIGNED_ID << 24) |
IEEE_COMPANY_LOCALLY_ASSIGNED) << 36;
s->sas_addr |= (pci_bus_num(dev->bus) << 16);
s->sas_addr |= (PCI_SLOT(dev->devfn) << 8);
s->sas_addr |= PCI_FUNC(dev->devfn);
}
s->max_devices = MPTSAS_NUM_PORTS;
s->request_bh = qemu_bh_new(mptsas_fetch_requests, s);
QTAILQ_INIT(&s->pending);
scsi_bus_new(&s->bus, sizeof(s->bus), &dev->qdev, &mptsas_scsi_info, NULL);
if (!d->hotplugged) {
scsi_bus_legacy_handle_cmdline(&s->bus, errp);
}
}
|
DoS
| 0
|
static void mptsas_scsi_init(PCIDevice *dev, Error **errp)
{
DeviceState *d = DEVICE(dev);
MPTSASState *s = MPT_SAS(dev);
Error *err = NULL;
int ret;
dev->config[PCI_LATENCY_TIMER] = 0;
dev->config[PCI_INTERRUPT_PIN] = 0x01;
if (s->msi != ON_OFF_AUTO_OFF) {
ret = msi_init(dev, 0, 1, true, false, &err);
/* Any error other than -ENOTSUP(board's MSI support is broken)
* is a programming error */
assert(!ret || ret == -ENOTSUP);
if (ret && s->msi == ON_OFF_AUTO_ON) {
/* Can't satisfy user's explicit msi=on request, fail */
error_append_hint(&err, "You have to use msi=auto (default) or "
"msi=off with this machine type.\n");
error_propagate(errp, err);
return;
}
assert(!err || s->msi == ON_OFF_AUTO_AUTO);
/* With msi=auto, we fall back to MSI off silently */
error_free(err);
/* Only used for migration. */
s->msi_in_use = (ret == 0);
}
memory_region_init_io(&s->mmio_io, OBJECT(s), &mptsas_mmio_ops, s,
"mptsas-mmio", 0x4000);
memory_region_init_io(&s->port_io, OBJECT(s), &mptsas_port_ops, s,
"mptsas-io", 256);
memory_region_init_io(&s->diag_io, OBJECT(s), &mptsas_diag_ops, s,
"mptsas-diag", 0x10000);
pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->port_io);
pci_register_bar(dev, 1, PCI_BASE_ADDRESS_SPACE_MEMORY |
PCI_BASE_ADDRESS_MEM_TYPE_32, &s->mmio_io);
pci_register_bar(dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY |
PCI_BASE_ADDRESS_MEM_TYPE_32, &s->diag_io);
if (!s->sas_addr) {
s->sas_addr = ((NAA_LOCALLY_ASSIGNED_ID << 24) |
IEEE_COMPANY_LOCALLY_ASSIGNED) << 36;
s->sas_addr |= (pci_bus_num(dev->bus) << 16);
s->sas_addr |= (PCI_SLOT(dev->devfn) << 8);
s->sas_addr |= PCI_FUNC(dev->devfn);
}
s->max_devices = MPTSAS_NUM_PORTS;
s->request_bh = qemu_bh_new(mptsas_fetch_requests, s);
QTAILQ_INIT(&s->pending);
scsi_bus_new(&s->bus, sizeof(s->bus), &dev->qdev, &mptsas_scsi_info, NULL);
if (!d->hotplugged) {
scsi_bus_legacy_handle_cmdline(&s->bus, errp);
}
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,684
|
static void mptsas_scsi_uninit(PCIDevice *dev)
{
MPTSASState *s = MPT_SAS(dev);
qemu_bh_delete(s->request_bh);
msi_uninit(dev);
}
|
DoS
| 0
|
static void mptsas_scsi_uninit(PCIDevice *dev)
{
MPTSASState *s = MPT_SAS(dev);
qemu_bh_delete(s->request_bh);
msi_uninit(dev);
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,685
|
static void mptsas_set_fault(MPTSASState *s, uint32_t code)
{
if ((s->state & MPI_IOC_STATE_FAULT) == 0) {
s->state = MPI_IOC_STATE_FAULT | code;
}
}
|
DoS
| 0
|
static void mptsas_set_fault(MPTSASState *s, uint32_t code)
{
if ((s->state & MPI_IOC_STATE_FAULT) == 0) {
s->state = MPI_IOC_STATE_FAULT | code;
}
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,686
|
static void mptsas_soft_reset(MPTSASState *s)
{
uint32_t save_mask;
trace_mptsas_reset(s);
/* Temporarily disable interrupts */
save_mask = s->intr_mask;
s->intr_mask = MPI_HIM_DIM | MPI_HIM_RIM;
mptsas_update_interrupt(s);
qbus_reset_all(&s->bus.qbus);
s->intr_status = 0;
s->intr_mask = save_mask;
s->reply_free_tail = 0;
s->reply_free_head = 0;
s->reply_post_tail = 0;
s->reply_post_head = 0;
s->request_post_tail = 0;
s->request_post_head = 0;
qemu_bh_cancel(s->request_bh);
s->state = MPI_IOC_STATE_READY;
}
|
DoS
| 0
|
static void mptsas_soft_reset(MPTSASState *s)
{
uint32_t save_mask;
trace_mptsas_reset(s);
/* Temporarily disable interrupts */
save_mask = s->intr_mask;
s->intr_mask = MPI_HIM_DIM | MPI_HIM_RIM;
mptsas_update_interrupt(s);
qbus_reset_all(&s->bus.qbus);
s->intr_status = 0;
s->intr_mask = save_mask;
s->reply_free_tail = 0;
s->reply_free_head = 0;
s->reply_post_tail = 0;
s->reply_post_head = 0;
s->request_post_tail = 0;
s->request_post_head = 0;
qemu_bh_cancel(s->request_bh);
s->state = MPI_IOC_STATE_READY;
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,687
|
static void mptsas_turbo_reply(MPTSASState *s, uint32_t msgctx)
{
if (MPTSAS_FIFO_FULL(s, reply_post)) {
mptsas_set_fault(s, MPI_IOCSTATUS_INSUFFICIENT_RESOURCES);
return;
}
/* The reply is just the message context ID (bit 31 = clear). */
MPTSAS_FIFO_PUT(s, reply_post, msgctx);
s->intr_status |= MPI_HIS_REPLY_MESSAGE_INTERRUPT;
mptsas_update_interrupt(s);
}
|
DoS
| 0
|
static void mptsas_turbo_reply(MPTSASState *s, uint32_t msgctx)
{
if (MPTSAS_FIFO_FULL(s, reply_post)) {
mptsas_set_fault(s, MPI_IOCSTATUS_INSUFFICIENT_RESOURCES);
return;
}
/* The reply is just the message context ID (bit 31 = clear). */
MPTSAS_FIFO_PUT(s, reply_post, msgctx);
s->intr_status |= MPI_HIS_REPLY_MESSAGE_INTERRUPT;
mptsas_update_interrupt(s);
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,688
|
static void mptsas_update_interrupt(MPTSASState *s)
{
PCIDevice *pci = (PCIDevice *) s;
uint32_t state = s->intr_status & ~(s->intr_mask | MPI_HIS_IOP_DOORBELL_STATUS);
if (msi_enabled(pci)) {
if (state) {
trace_mptsas_irq_msi(s);
msi_notify(pci, 0);
}
}
trace_mptsas_irq_intx(s, !!state);
pci_set_irq(pci, !!state);
}
|
DoS
| 0
|
static void mptsas_update_interrupt(MPTSASState *s)
{
PCIDevice *pci = (PCIDevice *) s;
uint32_t state = s->intr_status & ~(s->intr_mask | MPI_HIS_IOP_DOORBELL_STATUS);
if (msi_enabled(pci)) {
if (state) {
trace_mptsas_irq_msi(s);
msi_notify(pci, 0);
}
}
trace_mptsas_irq_intx(s, !!state);
pci_set_irq(pci, !!state);
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,689
|
static void mptsas_write_sequence_write(MPTSASState *s, uint32_t val)
{
/* If the diagnostic register is enabled, any write to this register
* will disable it. Otherwise, the guest has to do a magic five-write
* sequence.
*/
if (s->diagnostic & MPI_DIAG_DRWE) {
goto disable;
}
switch (s->diagnostic_idx) {
case 0:
if ((val & MPI_WRSEQ_KEY_VALUE_MASK) != MPI_WRSEQ_1ST_KEY_VALUE) {
goto disable;
}
break;
case 1:
if ((val & MPI_WRSEQ_KEY_VALUE_MASK) != MPI_WRSEQ_2ND_KEY_VALUE) {
goto disable;
}
break;
case 2:
if ((val & MPI_WRSEQ_KEY_VALUE_MASK) != MPI_WRSEQ_3RD_KEY_VALUE) {
goto disable;
}
break;
case 3:
if ((val & MPI_WRSEQ_KEY_VALUE_MASK) != MPI_WRSEQ_4TH_KEY_VALUE) {
goto disable;
}
break;
case 4:
if ((val & MPI_WRSEQ_KEY_VALUE_MASK) != MPI_WRSEQ_5TH_KEY_VALUE) {
goto disable;
}
/* Prepare Spaceball One for departure, and change the
* combination on my luggage!
*/
s->diagnostic |= MPI_DIAG_DRWE;
break;
}
s->diagnostic_idx++;
return;
disable:
s->diagnostic &= ~MPI_DIAG_DRWE;
s->diagnostic_idx = 0;
}
|
DoS
| 0
|
static void mptsas_write_sequence_write(MPTSASState *s, uint32_t val)
{
/* If the diagnostic register is enabled, any write to this register
* will disable it. Otherwise, the guest has to do a magic five-write
* sequence.
*/
if (s->diagnostic & MPI_DIAG_DRWE) {
goto disable;
}
switch (s->diagnostic_idx) {
case 0:
if ((val & MPI_WRSEQ_KEY_VALUE_MASK) != MPI_WRSEQ_1ST_KEY_VALUE) {
goto disable;
}
break;
case 1:
if ((val & MPI_WRSEQ_KEY_VALUE_MASK) != MPI_WRSEQ_2ND_KEY_VALUE) {
goto disable;
}
break;
case 2:
if ((val & MPI_WRSEQ_KEY_VALUE_MASK) != MPI_WRSEQ_3RD_KEY_VALUE) {
goto disable;
}
break;
case 3:
if ((val & MPI_WRSEQ_KEY_VALUE_MASK) != MPI_WRSEQ_4TH_KEY_VALUE) {
goto disable;
}
break;
case 4:
if ((val & MPI_WRSEQ_KEY_VALUE_MASK) != MPI_WRSEQ_5TH_KEY_VALUE) {
goto disable;
}
/* Prepare Spaceball One for departure, and change the
* combination on my luggage!
*/
s->diagnostic |= MPI_DIAG_DRWE;
break;
}
s->diagnostic_idx++;
return;
disable:
s->diagnostic &= ~MPI_DIAG_DRWE;
s->diagnostic_idx = 0;
}
|
@@ -304,7 +304,7 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
goto bad;
}
- req = g_new(MPTSASRequest, 1);
+ req = g_new0(MPTSASRequest, 1);
QTAILQ_INSERT_TAIL(&s->pending, req, next);
req->scsi_io = *scsi_io;
req->dev = s;
|
CWE-787
| null | null |
6,690
|
int virtio_queue_ready(VirtQueue *vq)
{
return vq->vring.avail != 0;
}
|
DoS
| 0
|
int virtio_queue_ready(VirtQueue *vq)
{
return vq->vring.avail != 0;
}
|
@@ -495,6 +495,11 @@ static void virtqueue_map_desc(unsigned int *p_num_sg, hwaddr *addr, struct iove
}
iov[num_sg].iov_base = cpu_physical_memory_map(pa, &len, is_write);
+ if (!iov[num_sg].iov_base) {
+ error_report("virtio: bogus descriptor or out of resources");
+ exit(1);
+ }
+
iov[num_sg].iov_len = len;
addr[num_sg] = pa;
|
CWE-476
| null | null |
6,691
|
int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes,
unsigned int out_bytes)
{
unsigned int in_total, out_total;
virtqueue_get_avail_bytes(vq, &in_total, &out_total, in_bytes, out_bytes);
return in_bytes <= in_total && out_bytes <= out_total;
}
|
DoS
| 0
|
int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes,
unsigned int out_bytes)
{
unsigned int in_total, out_total;
virtqueue_get_avail_bytes(vq, &in_total, &out_total, in_bytes, out_bytes);
return in_bytes <= in_total && out_bytes <= out_total;
}
|
@@ -495,6 +495,11 @@ static void virtqueue_map_desc(unsigned int *p_num_sg, hwaddr *addr, struct iove
}
iov[num_sg].iov_base = cpu_physical_memory_map(pa, &len, is_write);
+ if (!iov[num_sg].iov_base) {
+ error_report("virtio: bogus descriptor or out of resources");
+ exit(1);
+ }
+
iov[num_sg].iov_len = len;
addr[num_sg] = pa;
|
CWE-476
| null | null |
6,692
|
void virtqueue_flush(VirtQueue *vq, unsigned int count)
{
uint16_t old, new;
/* Make sure buffer is written before we update index. */
smp_wmb();
trace_virtqueue_flush(vq, count);
old = vq->used_idx;
new = old + count;
vring_used_idx_set(vq, new);
vq->inuse -= count;
if (unlikely((int16_t)(new - vq->signalled_used) < (uint16_t)(new - old)))
vq->signalled_used_valid = false;
}
|
DoS
| 0
|
void virtqueue_flush(VirtQueue *vq, unsigned int count)
{
uint16_t old, new;
/* Make sure buffer is written before we update index. */
smp_wmb();
trace_virtqueue_flush(vq, count);
old = vq->used_idx;
new = old + count;
vring_used_idx_set(vq, new);
vq->inuse -= count;
if (unlikely((int16_t)(new - vq->signalled_used) < (uint16_t)(new - old)))
vq->signalled_used_valid = false;
}
|
@@ -495,6 +495,11 @@ static void virtqueue_map_desc(unsigned int *p_num_sg, hwaddr *addr, struct iove
}
iov[num_sg].iov_base = cpu_physical_memory_map(pa, &len, is_write);
+ if (!iov[num_sg].iov_base) {
+ error_report("virtio: bogus descriptor or out of resources");
+ exit(1);
+ }
+
iov[num_sg].iov_len = len;
addr[num_sg] = pa;
|
CWE-476
| null | null |
6,693
|
void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
unsigned int *out_bytes,
unsigned max_in_bytes, unsigned max_out_bytes)
{
unsigned int idx;
unsigned int total_bufs, in_total, out_total;
idx = vq->last_avail_idx;
total_bufs = in_total = out_total = 0;
while (virtqueue_num_heads(vq, idx)) {
VirtIODevice *vdev = vq->vdev;
unsigned int max, num_bufs, indirect = 0;
VRingDesc desc;
hwaddr desc_pa;
int i;
max = vq->vring.num;
num_bufs = total_bufs;
i = virtqueue_get_head(vq, idx++);
desc_pa = vq->vring.desc;
vring_desc_read(vdev, &desc, desc_pa, i);
if (desc.flags & VRING_DESC_F_INDIRECT) {
if (desc.len % sizeof(VRingDesc)) {
error_report("Invalid size for indirect buffer table");
exit(1);
}
/* If we've got too many, that implies a descriptor loop. */
if (num_bufs >= max) {
error_report("Looped descriptor");
exit(1);
}
/* loop over the indirect descriptor table */
indirect = 1;
max = desc.len / sizeof(VRingDesc);
desc_pa = desc.addr;
num_bufs = i = 0;
vring_desc_read(vdev, &desc, desc_pa, i);
}
do {
/* If we've got too many, that implies a descriptor loop. */
if (++num_bufs > max) {
error_report("Looped descriptor");
exit(1);
}
if (desc.flags & VRING_DESC_F_WRITE) {
in_total += desc.len;
} else {
out_total += desc.len;
}
if (in_total >= max_in_bytes && out_total >= max_out_bytes) {
goto done;
}
} while ((i = virtqueue_read_next_desc(vdev, &desc, desc_pa, max)) != max);
if (!indirect)
total_bufs = num_bufs;
else
total_bufs++;
}
done:
if (in_bytes) {
*in_bytes = in_total;
}
if (out_bytes) {
*out_bytes = out_total;
}
}
|
DoS
| 0
|
void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
unsigned int *out_bytes,
unsigned max_in_bytes, unsigned max_out_bytes)
{
unsigned int idx;
unsigned int total_bufs, in_total, out_total;
idx = vq->last_avail_idx;
total_bufs = in_total = out_total = 0;
while (virtqueue_num_heads(vq, idx)) {
VirtIODevice *vdev = vq->vdev;
unsigned int max, num_bufs, indirect = 0;
VRingDesc desc;
hwaddr desc_pa;
int i;
max = vq->vring.num;
num_bufs = total_bufs;
i = virtqueue_get_head(vq, idx++);
desc_pa = vq->vring.desc;
vring_desc_read(vdev, &desc, desc_pa, i);
if (desc.flags & VRING_DESC_F_INDIRECT) {
if (desc.len % sizeof(VRingDesc)) {
error_report("Invalid size for indirect buffer table");
exit(1);
}
/* If we've got too many, that implies a descriptor loop. */
if (num_bufs >= max) {
error_report("Looped descriptor");
exit(1);
}
/* loop over the indirect descriptor table */
indirect = 1;
max = desc.len / sizeof(VRingDesc);
desc_pa = desc.addr;
num_bufs = i = 0;
vring_desc_read(vdev, &desc, desc_pa, i);
}
do {
/* If we've got too many, that implies a descriptor loop. */
if (++num_bufs > max) {
error_report("Looped descriptor");
exit(1);
}
if (desc.flags & VRING_DESC_F_WRITE) {
in_total += desc.len;
} else {
out_total += desc.len;
}
if (in_total >= max_in_bytes && out_total >= max_out_bytes) {
goto done;
}
} while ((i = virtqueue_read_next_desc(vdev, &desc, desc_pa, max)) != max);
if (!indirect)
total_bufs = num_bufs;
else
total_bufs++;
}
done:
if (in_bytes) {
*in_bytes = in_total;
}
if (out_bytes) {
*out_bytes = out_total;
}
}
|
@@ -495,6 +495,11 @@ static void virtqueue_map_desc(unsigned int *p_num_sg, hwaddr *addr, struct iove
}
iov[num_sg].iov_base = cpu_physical_memory_map(pa, &len, is_write);
+ if (!iov[num_sg].iov_base) {
+ error_report("virtio: bogus descriptor or out of resources");
+ exit(1);
+ }
+
iov[num_sg].iov_len = len;
addr[num_sg] = pa;
|
CWE-476
| null | null |
6,694
|
static unsigned int virtqueue_get_head(VirtQueue *vq, unsigned int idx)
{
unsigned int head;
/* Grab the next descriptor number they're advertising, and increment
* the index we've seen. */
head = vring_avail_ring(vq, idx % vq->vring.num);
/* If their number is silly, that's a fatal mistake. */
if (head >= vq->vring.num) {
error_report("Guest says index %u is available", head);
exit(1);
}
return head;
}
|
DoS
| 0
|
static unsigned int virtqueue_get_head(VirtQueue *vq, unsigned int idx)
{
unsigned int head;
/* Grab the next descriptor number they're advertising, and increment
* the index we've seen. */
head = vring_avail_ring(vq, idx % vq->vring.num);
/* If their number is silly, that's a fatal mistake. */
if (head >= vq->vring.num) {
error_report("Guest says index %u is available", head);
exit(1);
}
return head;
}
|
@@ -495,6 +495,11 @@ static void virtqueue_map_desc(unsigned int *p_num_sg, hwaddr *addr, struct iove
}
iov[num_sg].iov_base = cpu_physical_memory_map(pa, &len, is_write);
+ if (!iov[num_sg].iov_base) {
+ error_report("virtio: bogus descriptor or out of resources");
+ exit(1);
+ }
+
iov[num_sg].iov_len = len;
addr[num_sg] = pa;
|
CWE-476
| null | null |
6,695
|
pvscsi_build_sglist(PVSCSIState *s, PVSCSIRequest *r)
{
PCIDevice *d = PCI_DEVICE(s);
pci_dma_sglist_init(&r->sgl, d, 1);
if (r->req.flags & PVSCSI_FLAG_CMD_WITH_SG_LIST) {
pvscsi_convert_sglist(r);
} else {
qemu_sglist_add(&r->sgl, r->req.dataAddr, r->req.dataLen);
}
}
|
DoS
| 0
|
pvscsi_build_sglist(PVSCSIState *s, PVSCSIRequest *r)
{
PCIDevice *d = PCI_DEVICE(s);
pci_dma_sglist_init(&r->sgl, d, 1);
if (r->req.flags & PVSCSI_FLAG_CMD_WITH_SG_LIST) {
pvscsi_convert_sglist(r);
} else {
qemu_sglist_add(&r->sgl, r->req.dataAddr, r->req.dataLen);
}
}
|
@@ -247,8 +247,11 @@ static hwaddr
pvscsi_ring_pop_req_descr(PVSCSIRingInfo *mgr)
{
uint32_t ready_ptr = RS_GET_FIELD(mgr, reqProdIdx);
+ uint32_t ring_size = PVSCSI_MAX_NUM_PAGES_REQ_RING
+ * PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE;
- if (ready_ptr != mgr->consumed_ptr) {
+ if (ready_ptr != mgr->consumed_ptr
+ && ready_ptr - mgr->consumed_ptr < ring_size) {
uint32_t next_ready_ptr =
mgr->consumed_ptr++ & mgr->txr_len_mask;
uint32_t next_ready_page =
|
CWE-399
| null | null |
6,696
|
static void pvscsi_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
PVSCSIClass *pvs_k = PVSCSI_DEVICE_CLASS(klass);
HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
k->init = pvscsi_init;
k->exit = pvscsi_uninit;
k->vendor_id = PCI_VENDOR_ID_VMWARE;
k->device_id = PCI_DEVICE_ID_VMWARE_PVSCSI;
k->class_id = PCI_CLASS_STORAGE_SCSI;
k->subsystem_id = 0x1000;
pvs_k->parent_dc_realize = dc->realize;
dc->realize = pvscsi_realize;
dc->reset = pvscsi_reset;
dc->vmsd = &vmstate_pvscsi;
dc->props = pvscsi_properties;
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
hc->unplug = pvscsi_hot_unplug;
hc->plug = pvscsi_hotplug;
}
|
DoS
| 0
|
static void pvscsi_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
PVSCSIClass *pvs_k = PVSCSI_DEVICE_CLASS(klass);
HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
k->init = pvscsi_init;
k->exit = pvscsi_uninit;
k->vendor_id = PCI_VENDOR_ID_VMWARE;
k->device_id = PCI_DEVICE_ID_VMWARE_PVSCSI;
k->class_id = PCI_CLASS_STORAGE_SCSI;
k->subsystem_id = 0x1000;
pvs_k->parent_dc_realize = dc->realize;
dc->realize = pvscsi_realize;
dc->reset = pvscsi_reset;
dc->vmsd = &vmstate_pvscsi;
dc->props = pvscsi_properties;
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
hc->unplug = pvscsi_hot_unplug;
hc->plug = pvscsi_hotplug;
}
|
@@ -247,8 +247,11 @@ static hwaddr
pvscsi_ring_pop_req_descr(PVSCSIRingInfo *mgr)
{
uint32_t ready_ptr = RS_GET_FIELD(mgr, reqProdIdx);
+ uint32_t ring_size = PVSCSI_MAX_NUM_PAGES_REQ_RING
+ * PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE;
- if (ready_ptr != mgr->consumed_ptr) {
+ if (ready_ptr != mgr->consumed_ptr
+ && ready_ptr - mgr->consumed_ptr < ring_size) {
uint32_t next_ready_ptr =
mgr->consumed_ptr++ & mgr->txr_len_mask;
uint32_t next_ready_page =
|
CWE-399
| null | null |
6,697
|
pvscsi_cleanup_msi(PVSCSIState *s)
{
PCIDevice *d = PCI_DEVICE(s);
msi_uninit(d);
}
|
DoS
| 0
|
pvscsi_cleanup_msi(PVSCSIState *s)
{
PCIDevice *d = PCI_DEVICE(s);
msi_uninit(d);
}
|
@@ -247,8 +247,11 @@ static hwaddr
pvscsi_ring_pop_req_descr(PVSCSIRingInfo *mgr)
{
uint32_t ready_ptr = RS_GET_FIELD(mgr, reqProdIdx);
+ uint32_t ring_size = PVSCSI_MAX_NUM_PAGES_REQ_RING
+ * PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE;
- if (ready_ptr != mgr->consumed_ptr) {
+ if (ready_ptr != mgr->consumed_ptr
+ && ready_ptr - mgr->consumed_ptr < ring_size) {
uint32_t next_ready_ptr =
mgr->consumed_ptr++ & mgr->txr_len_mask;
uint32_t next_ready_page =
|
CWE-399
| null | null |
6,698
|
pvscsi_cmp_ring_put(PVSCSIState *s, struct PVSCSIRingCmpDesc *cmp_desc)
{
hwaddr cmp_descr_pa;
cmp_descr_pa = pvscsi_ring_pop_cmp_descr(&s->rings);
trace_pvscsi_cmp_ring_put(cmp_descr_pa);
cpu_physical_memory_write(cmp_descr_pa, (void *)cmp_desc,
sizeof(*cmp_desc));
}
|
DoS
| 0
|
pvscsi_cmp_ring_put(PVSCSIState *s, struct PVSCSIRingCmpDesc *cmp_desc)
{
hwaddr cmp_descr_pa;
cmp_descr_pa = pvscsi_ring_pop_cmp_descr(&s->rings);
trace_pvscsi_cmp_ring_put(cmp_descr_pa);
cpu_physical_memory_write(cmp_descr_pa, (void *)cmp_desc,
sizeof(*cmp_desc));
}
|
@@ -247,8 +247,11 @@ static hwaddr
pvscsi_ring_pop_req_descr(PVSCSIRingInfo *mgr)
{
uint32_t ready_ptr = RS_GET_FIELD(mgr, reqProdIdx);
+ uint32_t ring_size = PVSCSI_MAX_NUM_PAGES_REQ_RING
+ * PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE;
- if (ready_ptr != mgr->consumed_ptr) {
+ if (ready_ptr != mgr->consumed_ptr
+ && ready_ptr - mgr->consumed_ptr < ring_size) {
uint32_t next_ready_ptr =
mgr->consumed_ptr++ & mgr->txr_len_mask;
uint32_t next_ready_page =
|
CWE-399
| null | null |
6,699
|
pvscsi_command_complete(SCSIRequest *req, uint32_t status, size_t resid)
{
PVSCSIRequest *pvscsi_req = req->hba_private;
PVSCSIState *s;
if (!pvscsi_req) {
trace_pvscsi_command_complete_not_found(req->tag);
return;
}
s = pvscsi_req->dev;
if (resid) {
/* Short transfer. */
trace_pvscsi_command_complete_data_run();
pvscsi_req->cmp.hostStatus = BTSTAT_DATARUN;
}
pvscsi_req->cmp.scsiStatus = status;
if (pvscsi_req->cmp.scsiStatus == CHECK_CONDITION) {
uint8_t sense[SCSI_SENSE_BUF_SIZE];
int sense_len =
scsi_req_get_sense(pvscsi_req->sreq, sense, sizeof(sense));
trace_pvscsi_command_complete_sense_len(sense_len);
pvscsi_write_sense(pvscsi_req, sense, sense_len);
}
qemu_sglist_destroy(&pvscsi_req->sgl);
pvscsi_complete_request(s, pvscsi_req);
}
|
DoS
| 0
|
pvscsi_command_complete(SCSIRequest *req, uint32_t status, size_t resid)
{
PVSCSIRequest *pvscsi_req = req->hba_private;
PVSCSIState *s;
if (!pvscsi_req) {
trace_pvscsi_command_complete_not_found(req->tag);
return;
}
s = pvscsi_req->dev;
if (resid) {
/* Short transfer. */
trace_pvscsi_command_complete_data_run();
pvscsi_req->cmp.hostStatus = BTSTAT_DATARUN;
}
pvscsi_req->cmp.scsiStatus = status;
if (pvscsi_req->cmp.scsiStatus == CHECK_CONDITION) {
uint8_t sense[SCSI_SENSE_BUF_SIZE];
int sense_len =
scsi_req_get_sense(pvscsi_req->sreq, sense, sizeof(sense));
trace_pvscsi_command_complete_sense_len(sense_len);
pvscsi_write_sense(pvscsi_req, sense, sense_len);
}
qemu_sglist_destroy(&pvscsi_req->sgl);
pvscsi_complete_request(s, pvscsi_req);
}
|
@@ -247,8 +247,11 @@ static hwaddr
pvscsi_ring_pop_req_descr(PVSCSIRingInfo *mgr)
{
uint32_t ready_ptr = RS_GET_FIELD(mgr, reqProdIdx);
+ uint32_t ring_size = PVSCSI_MAX_NUM_PAGES_REQ_RING
+ * PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE;
- if (ready_ptr != mgr->consumed_ptr) {
+ if (ready_ptr != mgr->consumed_ptr
+ && ready_ptr - mgr->consumed_ptr < ring_size) {
uint32_t next_ready_ptr =
mgr->consumed_ptr++ & mgr->txr_len_mask;
uint32_t next_ready_page =
|
CWE-399
| null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.