diff options
-rw-r--r-- | dix/cursor.c | 92 | ||||
-rw-r--r-- | dix/dispatch.c | 47 | ||||
-rw-r--r-- | dix/events.c | 18 | ||||
-rw-r--r-- | dix/window.c | 3 | ||||
-rw-r--r-- | include/cursor.h | 26 | ||||
-rw-r--r-- | render/render.c | 26 | ||||
-rwxr-xr-x | xfixes/cursor.c | 8 |
7 files changed, 113 insertions, 107 deletions
diff --git a/dix/cursor.c b/dix/cursor.c index d903124c4..b188e3f98 100644 --- a/dix/cursor.c +++ b/dix/cursor.c @@ -59,6 +59,7 @@ SOFTWARE. #include "cursorstr.h" #include "dixfontstr.h" #include "opaque.h" +#include "xace.h" typedef struct _GlyphShare { FontPtr font; @@ -161,23 +162,25 @@ CheckForEmptyMask(CursorBitsPtr bits) * \param pmaskbits server-defined padding * \param argb no padding */ -CursorPtr -AllocCursorARGB(unsigned char *psrcbits, unsigned char *pmaskbits, CARD32 *argb, - CursorMetricPtr cm, - unsigned foreRed, unsigned foreGreen, unsigned foreBlue, - unsigned backRed, unsigned backGreen, unsigned backBlue) +int +AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits, + CARD32 *argb, CursorMetricPtr cm, + unsigned foreRed, unsigned foreGreen, unsigned foreBlue, + unsigned backRed, unsigned backGreen, unsigned backBlue, + CursorPtr *ppCurs, ClientPtr client, XID cid) { CursorBitsPtr bits; CursorPtr pCurs; - int nscr; + int rc, nscr; ScreenPtr pscr; + *ppCurs = NULL; pCurs = (CursorPtr)xalloc(sizeof(CursorRec) + sizeof(CursorBits)); if (!pCurs) { xfree(psrcbits); xfree(pmaskbits); - return (CursorPtr)NULL; + return BadAlloc; } bits = (CursorBitsPtr)((char *)pCurs + sizeof(CursorRec)); bits->source = psrcbits; @@ -207,6 +210,15 @@ AllocCursorARGB(unsigned char *psrcbits, unsigned char *pmaskbits, CARD32 *argb, pCurs->backGreen = backGreen; pCurs->backBlue = backBlue; + /* security creation/labeling check */ + rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR, + DixCreateAccess, pCurs); + if (rc != Success) { + FreeCursorBits(bits); + xfree(pCurs); + return rc; + } + /* * realize the cursor for every screen */ @@ -222,59 +234,43 @@ AllocCursorARGB(unsigned char *psrcbits, unsigned char *pmaskbits, CARD32 *argb, } FreeCursorBits(bits); xfree(pCurs); - return (CursorPtr)NULL; + return BadAlloc; } } - return pCurs; -} - -/** - * - * \param psrcbits server-defined padding - * \param pmaskbits server-defined padding - */ -CursorPtr -AllocCursor(unsigned char *psrcbits, unsigned char *pmaskbits, - CursorMetricPtr cm, - unsigned foreRed, unsigned foreGreen, unsigned foreBlue, - unsigned backRed, unsigned backGreen, unsigned backBlue) -{ - return AllocCursorARGB (psrcbits, pmaskbits, (CARD32 *) 0, cm, - foreRed, foreGreen, foreBlue, - backRed, backGreen, backBlue); + *ppCurs = pCurs; + return rc; } int AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar, unsigned foreRed, unsigned foreGreen, unsigned foreBlue, unsigned backRed, unsigned backGreen, unsigned backBlue, - CursorPtr *ppCurs, ClientPtr client) + CursorPtr *ppCurs, ClientPtr client, XID cid) { FontPtr sourcefont, maskfont; unsigned char *srcbits; unsigned char *mskbits; CursorMetricRec cm; - int res; + int rc; CursorBitsPtr bits; CursorPtr pCurs; int nscr; ScreenPtr pscr; GlyphSharePtr pShare; - sourcefont = (FontPtr) SecurityLookupIDByType(client, source, RT_FONT, - DixReadAccess); - maskfont = (FontPtr) SecurityLookupIDByType(client, mask, RT_FONT, - DixReadAccess); - - if (!sourcefont) + rc = dixLookupResource((pointer *)&sourcefont, source, RT_FONT, client, + DixUseAccess); + if (rc != Success) { client->errorValue = source; - return(BadFont); + return (rc == BadValue) ? BadFont : rc; } - if (!maskfont && (mask != None)) + rc = dixLookupResource((pointer *)&maskfont, mask, RT_FONT, client, + DixUseAccess); + if (rc != Success && mask != None) { client->errorValue = mask; - return(BadFont); + return (rc == BadValue) ? BadFont : rc; } if (sourcefont != maskfont) pShare = (GlyphSharePtr)NULL; @@ -322,13 +318,13 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar, client->errorValue = maskChar; return BadValue; } - if ((res = ServerBitsFromGlyph(maskfont, maskChar, &cm, &mskbits)) != 0) - return res; + if ((rc = ServerBitsFromGlyph(maskfont, maskChar, &cm, &mskbits))) + return rc; } - if ((res = ServerBitsFromGlyph(sourcefont, sourceChar, &cm, &srcbits)) != 0) + if ((rc = ServerBitsFromGlyph(sourcefont, sourceChar, &cm, &srcbits))) { xfree(mskbits); - return res; + return rc; } if (sourcefont != maskfont) { @@ -398,6 +394,15 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar, pCurs->backGreen = backGreen; pCurs->backBlue = backBlue; + /* security creation/labeling check */ + rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR, + DixCreateAccess, pCurs); + if (rc != Success) { + FreeCursorBits(bits); + xfree(pCurs); + return rc; + } + /* * realize the cursor for every screen */ @@ -447,7 +452,8 @@ CreateRootCursor(char *unused1, unsigned int unused2) cm.xhot = 0; cm.yhot = 0; - curs = AllocCursor(NULL, NULL, &cm, 0, 0, 0, 0, 0, 0); + AllocARGBCursor(NULL, NULL, NULL, &cm, 0, 0, 0, 0, 0, 0, + &curs, serverClient, (XID)0); if (curs == NullCursor) return NullCursor; @@ -461,8 +467,8 @@ CreateRootCursor(char *unused1, unsigned int unused2) cursorfont = (FontPtr)LookupIDByType(fontID, RT_FONT); if (!cursorfont) return NullCursor; - if (AllocGlyphCursor(fontID, 0, fontID, 1, - 0, 0, 0, ~0, ~0, ~0, &curs, serverClient) != Success) + if (AllocGlyphCursor(fontID, 0, fontID, 1, 0, 0, 0, ~0, ~0, ~0, + &curs, serverClient, (XID)0) != Success) return NullCursor; #endif diff --git a/dix/dispatch.c b/dix/dispatch.c index 4260799bd..4a9064db7 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -3070,28 +3070,28 @@ ProcCreateCursor (ClientPtr client) unsigned short width, height; long n; CursorMetricRec cm; - + int rc; REQUEST(xCreateCursorReq); REQUEST_SIZE_MATCH(xCreateCursorReq); LEGAL_NEW_RESOURCE(stuff->cid, client); - src = (PixmapPtr)SecurityLookupIDByType(client, stuff->source, - RT_PIXMAP, DixReadAccess); - msk = (PixmapPtr)SecurityLookupIDByType(client, stuff->mask, - RT_PIXMAP, DixReadAccess); - if ( src == (PixmapPtr)NULL) - { + rc = dixLookupResource((pointer *)&src, stuff->source, RT_PIXMAP, client, + DixReadAccess); + if (rc != Success) { client->errorValue = stuff->source; - return (BadPixmap); + return (rc == BadValue) ? BadPixmap : rc; } - if ( msk == (PixmapPtr)NULL) + + rc = dixLookupResource((pointer *)&msk, stuff->mask, RT_PIXMAP, client, + DixReadAccess); + if (rc != Success) { if (stuff->mask != None) { client->errorValue = stuff->mask; - return (BadPixmap); + return (rc == BadValue) ? BadPixmap : rc; } } else if ( src->drawable.width != msk->drawable.width @@ -3139,13 +3139,17 @@ ProcCreateCursor (ClientPtr client) cm.height = height; cm.xhot = stuff->x; cm.yhot = stuff->y; - pCursor = AllocCursor( srcbits, mskbits, &cm, - stuff->foreRed, stuff->foreGreen, stuff->foreBlue, - stuff->backRed, stuff->backGreen, stuff->backBlue); + rc = AllocARGBCursor(srcbits, mskbits, NULL, &cm, + stuff->foreRed, stuff->foreGreen, stuff->foreBlue, + stuff->backRed, stuff->backGreen, stuff->backBlue, + &pCursor, client, stuff->cid); - if (pCursor && AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) - return (client->noClientException); - return BadAlloc; + if (rc != Success) + return rc; + if (!AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) + return BadAlloc; + + return client->noClientException; } int @@ -3163,7 +3167,7 @@ ProcCreateGlyphCursor (ClientPtr client) stuff->mask, stuff->maskChar, stuff->foreRed, stuff->foreGreen, stuff->foreBlue, stuff->backRed, stuff->backGreen, stuff->backBlue, - &pCursor, client); + &pCursor, client, stuff->cid); if (res != Success) return res; if (AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) @@ -3176,12 +3180,13 @@ int ProcFreeCursor (ClientPtr client) { CursorPtr pCursor; + int rc; REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); - pCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->id, - RT_CURSOR, DixDestroyAccess); - if (pCursor) + rc = dixLookupResource((pointer *)&pCursor, stuff->id, RT_CURSOR, client, + DixDestroyAccess); + if (rc == Success) { FreeResource(stuff->id, RT_NONE); return (client->noClientException); @@ -3189,7 +3194,7 @@ ProcFreeCursor (ClientPtr client) else { client->errorValue = stuff->id; - return (BadCursor); + return (rc == BadValue) ? BadCursor : rc; } } diff --git a/dix/events.c b/dix/events.c index 3fbe9b829..f109dad4d 100644 --- a/dix/events.c +++ b/dix/events.c @@ -4115,12 +4115,12 @@ ProcChangeActivePointerGrab(ClientPtr client) newCursor = NullCursor; else { - newCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, DixReadAccess); - if (!newCursor) + int rc = dixLookupResource((pointer *)&newCursor, stuff->cursor, + RT_CURSOR, client, DixUseAccess); + if (rc != Success) { client->errorValue = stuff->cursor; - return BadCursor; + return (rc == BadValue) ? BadCursor : rc; } } if (!grab) @@ -4889,18 +4889,18 @@ int ProcRecolorCursor(ClientPtr client) { CursorPtr pCursor; - int nscr; + int rc, nscr; ScreenPtr pscr; Bool displayed; REQUEST(xRecolorCursorReq); REQUEST_SIZE_MATCH(xRecolorCursorReq); - pCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor, - RT_CURSOR, DixWriteAccess); - if ( !pCursor) + rc = dixLookupResource((pointer *)&pCursor, stuff->cursor, RT_CURSOR, + client, DixWriteAccess); + if (rc != Success) { client->errorValue = stuff->cursor; - return (BadCursor); + return (rc == BadValue) ? BadCursor : rc; } pCursor->foreRed = stuff->foreRed; diff --git a/dix/window.c b/dix/window.c index 3addc73cd..9d1947a53 100644 --- a/dix/window.c +++ b/dix/window.c @@ -3541,7 +3541,8 @@ TileScreenSaver(int i, int kind) { for (j=0; j<BitmapBytePad(32)*16; j++) srcbits[j] = mskbits[j] = 0x0; - cursor = AllocCursor(srcbits, mskbits, &cm, 0, 0, 0, 0, 0, 0); + result = AllocARGBCursor(srcbits, mskbits, NULL, &cm, 0, 0, 0, 0, 0, 0, + &cursor, serverClient, (XID)0); if (cursor) { cursorID = FakeClientID(0); diff --git a/include/cursor.h b/include/cursor.h index bdf4fd301..8635cf1a2 100644 --- a/include/cursor.h +++ b/include/cursor.h @@ -68,23 +68,7 @@ extern int FreeCursor( pointer /*pCurs*/, XID /*cid*/); -/* Quartz support on Mac OS X pulls in the QuickDraw - framework whose AllocCursor function conflicts here. */ -#ifdef __DARWIN__ -#define AllocCursor Darwin_X_AllocCursor -#endif -extern CursorPtr AllocCursor( - unsigned char* /*psrcbits*/, - unsigned char* /*pmaskbits*/, - CursorMetricPtr /*cm*/, - unsigned /*foreRed*/, - unsigned /*foreGreen*/, - unsigned /*foreBlue*/, - unsigned /*backRed*/, - unsigned /*backGreen*/, - unsigned /*backBlue*/); - -extern CursorPtr AllocCursorARGB( +extern int AllocARGBCursor( unsigned char* /*psrcbits*/, unsigned char* /*pmaskbits*/, CARD32* /*argb*/, @@ -94,7 +78,10 @@ extern CursorPtr AllocCursorARGB( unsigned /*foreBlue*/, unsigned /*backRed*/, unsigned /*backGreen*/, - unsigned /*backBlue*/); + unsigned /*backBlue*/, + CursorPtr* /*ppCurs*/, + ClientPtr /*client*/, + XID /*cid*/); extern int AllocGlyphCursor( Font /*source*/, @@ -108,7 +95,8 @@ extern int AllocGlyphCursor( unsigned /*backGreen*/, unsigned /*backBlue*/, CursorPtr* /*ppCurs*/, - ClientPtr /*client*/); + ClientPtr /*client*/, + XID /*cid*/); extern CursorPtr CreateRootCursor( char* /*pfilename*/, diff --git a/render/render.c b/render/render.c index caaa2781c..e57ffb126 100644 --- a/render/render.c +++ b/render/render.c @@ -1492,7 +1492,7 @@ ProcRenderCreateCursor (ClientPtr client) CursorMetricRec cm; CursorPtr pCursor; CARD32 twocolor[3]; - int ncolor; + int rc, ncolor; REQUEST_SIZE_MATCH (xRenderCreateCursorReq); LEGAL_NEW_RESOURCE(stuff->cid, client); @@ -1659,16 +1659,20 @@ ProcRenderCreateCursor (ClientPtr client) cm.height = height; cm.xhot = stuff->x; cm.yhot = stuff->y; - pCursor = AllocCursorARGB (srcbits, mskbits, argbbits, &cm, - GetColor(twocolor[0], 16), - GetColor(twocolor[0], 8), - GetColor(twocolor[0], 0), - GetColor(twocolor[1], 16), - GetColor(twocolor[1], 8), - GetColor(twocolor[1], 0)); - if (pCursor && AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) - return (client->noClientException); - return BadAlloc; + rc = AllocARGBCursor(srcbits, mskbits, argbbits, &cm, + GetColor(twocolor[0], 16), + GetColor(twocolor[0], 8), + GetColor(twocolor[0], 0), + GetColor(twocolor[1], 16), + GetColor(twocolor[1], 8), + GetColor(twocolor[1], 0), + &pCursor, client, stuff->cid); + if (rc != Success) + return rc; + if (!AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) + return BadAlloc; + + return client->noClientException; } static int diff --git a/xfixes/cursor.c b/xfixes/cursor.c index 401c403c8..450f366f2 100755 --- a/xfixes/cursor.c +++ b/xfixes/cursor.c @@ -980,6 +980,7 @@ createInvisibleCursor (void) CursorPtr pCursor; static unsigned int *psrcbits, *pmaskbits; CursorMetricRec cm; + int rc; psrcbits = (unsigned int *) xalloc(4); pmaskbits = (unsigned int *) xalloc(4); @@ -994,12 +995,13 @@ createInvisibleCursor (void) cm.xhot = 0; cm.yhot = 0; - pCursor = AllocCursor( + rc = AllocARGBCursor( (unsigned char *)psrcbits, (unsigned char *)pmaskbits, - &cm, + NULL, &cm, 0, 0, 0, - 0, 0, 0); + 0, 0, 0, + &pCursor, serverClient, (XID)0); return pCursor; } |