135c4bbdfSmrg/* 235c4bbdfSmrg * Copyright © 2011 Intel Corporation 335c4bbdfSmrg * 435c4bbdfSmrg * Permission is hereby granted, free of charge, to any person obtaining a 535c4bbdfSmrg * copy of this software and associated documentation files (the "Software"), 635c4bbdfSmrg * to deal in the Software without restriction, including without limitation 735c4bbdfSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 835c4bbdfSmrg * and/or sell copies of the Software, and to permit persons to whom the 935c4bbdfSmrg * Software is furnished to do so, subject to the following conditions: 1035c4bbdfSmrg * 1135c4bbdfSmrg * The above copyright notice and this permission notice (including the next 1235c4bbdfSmrg * paragraph) shall be included in all copies or substantial portions of the 1335c4bbdfSmrg * Software. 1435c4bbdfSmrg * 1535c4bbdfSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1635c4bbdfSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1735c4bbdfSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1835c4bbdfSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1935c4bbdfSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2035c4bbdfSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 2135c4bbdfSmrg * DEALINGS IN THE SOFTWARE. 2235c4bbdfSmrg */ 2335c4bbdfSmrg#ifdef HAVE_DIX_CONFIG_H 2435c4bbdfSmrg#include <dix-config.h> 2535c4bbdfSmrg#endif 2635c4bbdfSmrg 2735c4bbdfSmrg#include "glxserver.h" 2835c4bbdfSmrg#include "indirect_dispatch.h" 2935c4bbdfSmrg#include "glxbyteorder.h" 3035c4bbdfSmrg#include "unpack.h" 3135c4bbdfSmrg 3235c4bbdfSmrgstatic int 3335c4bbdfSmrgset_client_info(__GLXclientState * cl, xGLXSetClientInfoARBReq * req, 3435c4bbdfSmrg unsigned bytes_per_version) 3535c4bbdfSmrg{ 3635c4bbdfSmrg ClientPtr client = cl->client; 3735c4bbdfSmrg char *gl_extensions; 3835c4bbdfSmrg char *glx_extensions; 3935c4bbdfSmrg int size; 4035c4bbdfSmrg 4135c4bbdfSmrg REQUEST_AT_LEAST_SIZE(xGLXSetClientInfoARBReq); 4235c4bbdfSmrg 4335c4bbdfSmrg /* Verify that the size of the packet matches the size inferred from the 4435c4bbdfSmrg * sizes specified for the various fields. 4535c4bbdfSmrg */ 4635c4bbdfSmrg size = sz_xGLXSetClientInfoARBReq; 4735c4bbdfSmrg size = safe_add(size, safe_mul(req->numVersions, bytes_per_version)); 4835c4bbdfSmrg size = safe_add(size, safe_pad(req->numGLExtensionBytes)); 4935c4bbdfSmrg size = safe_add(size, safe_pad(req->numGLXExtensionBytes)); 5035c4bbdfSmrg 5135c4bbdfSmrg if (size < 0 || req->length != (size / 4)) 5235c4bbdfSmrg return BadLength; 5335c4bbdfSmrg 5435c4bbdfSmrg /* Verify that the actual length of the GL extension string matches what's 5535c4bbdfSmrg * encoded in protocol packet. 5635c4bbdfSmrg */ 5735c4bbdfSmrg gl_extensions = (char *) (req + 1) + (req->numVersions * bytes_per_version); 5835c4bbdfSmrg if (req->numGLExtensionBytes != 0 5935c4bbdfSmrg && memchr(gl_extensions, 0, 6035c4bbdfSmrg __GLX_PAD(req->numGLExtensionBytes)) == NULL) 6135c4bbdfSmrg return BadLength; 6235c4bbdfSmrg 6335c4bbdfSmrg /* Verify that the actual length of the GLX extension string matches 6435c4bbdfSmrg * what's encoded in protocol packet. 6535c4bbdfSmrg */ 6635c4bbdfSmrg glx_extensions = gl_extensions + __GLX_PAD(req->numGLExtensionBytes); 6735c4bbdfSmrg if (req->numGLXExtensionBytes != 0 6835c4bbdfSmrg && memchr(glx_extensions, 0, 6935c4bbdfSmrg __GLX_PAD(req->numGLXExtensionBytes)) == NULL) 7035c4bbdfSmrg return BadLength; 7135c4bbdfSmrg 7235c4bbdfSmrg free(cl->GLClientextensions); 7335c4bbdfSmrg cl->GLClientextensions = strdup(gl_extensions); 7435c4bbdfSmrg 7535c4bbdfSmrg return 0; 7635c4bbdfSmrg} 7735c4bbdfSmrg 7835c4bbdfSmrgint 7935c4bbdfSmrg__glXDisp_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc) 8035c4bbdfSmrg{ 8135c4bbdfSmrg return set_client_info(cl, (xGLXSetClientInfoARBReq *) pc, 8); 8235c4bbdfSmrg} 8335c4bbdfSmrg 8435c4bbdfSmrgint 8535c4bbdfSmrg__glXDispSwap_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc) 8635c4bbdfSmrg{ 8735c4bbdfSmrg ClientPtr client = cl->client; 8835c4bbdfSmrg xGLXSetClientInfoARBReq *req = (xGLXSetClientInfoARBReq *) pc; 8935c4bbdfSmrg 9035c4bbdfSmrg REQUEST_AT_LEAST_SIZE(xGLXSetClientInfoARBReq); 9135c4bbdfSmrg 9235c4bbdfSmrg req->length = bswap_16(req->length); 9335c4bbdfSmrg req->numVersions = bswap_32(req->numVersions); 9435c4bbdfSmrg req->numGLExtensionBytes = bswap_32(req->numGLExtensionBytes); 9535c4bbdfSmrg req->numGLXExtensionBytes = bswap_32(req->numGLXExtensionBytes); 9635c4bbdfSmrg 9735c4bbdfSmrg return __glXDisp_SetClientInfoARB(cl, pc); 9835c4bbdfSmrg} 9935c4bbdfSmrg 10035c4bbdfSmrgint 10135c4bbdfSmrg__glXDisp_SetClientInfo2ARB(__GLXclientState * cl, GLbyte * pc) 10235c4bbdfSmrg{ 10335c4bbdfSmrg return set_client_info(cl, (xGLXSetClientInfoARBReq *) pc, 12); 10435c4bbdfSmrg} 10535c4bbdfSmrg 10635c4bbdfSmrgint 10735c4bbdfSmrg__glXDispSwap_SetClientInfo2ARB(__GLXclientState * cl, GLbyte * pc) 10835c4bbdfSmrg{ 10935c4bbdfSmrg ClientPtr client = cl->client; 11035c4bbdfSmrg xGLXSetClientInfoARBReq *req = (xGLXSetClientInfoARBReq *) pc; 11135c4bbdfSmrg 11235c4bbdfSmrg REQUEST_AT_LEAST_SIZE(xGLXSetClientInfoARBReq); 11335c4bbdfSmrg 11435c4bbdfSmrg req->length = bswap_16(req->length); 11535c4bbdfSmrg req->numVersions = bswap_32(req->numVersions); 11635c4bbdfSmrg req->numGLExtensionBytes = bswap_32(req->numGLExtensionBytes); 11735c4bbdfSmrg req->numGLXExtensionBytes = bswap_32(req->numGLXExtensionBytes); 11835c4bbdfSmrg 11935c4bbdfSmrg return __glXDisp_SetClientInfo2ARB(cl, pc); 12035c4bbdfSmrg} 121