Commit | Line | Data |
---|---|---|
a09e091a JB |
1 | /* |
2 | * Copyright © 2011 Intel Corporation | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a | |
5 | * copy of this software and associated documentation files (the "Software"), | |
6 | * to deal in the Software without restriction, including without limitation | |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
8 | * and/or sell copies of the Software, and to permit persons to whom the | |
9 | * Software is furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice (including the next | |
12 | * paragraph) shall be included in all copies or substantial portions of the | |
13 | * Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | */ | |
23 | #ifdef HAVE_DIX_CONFIG_H | |
24 | #include <dix-config.h> | |
25 | #endif | |
26 | ||
27 | #include "glxserver.h" | |
28 | #include "indirect_dispatch.h" | |
29 | #include "glxbyteorder.h" | |
30 | #include "unpack.h" | |
31 | ||
32 | static int | |
33 | set_client_info(__GLXclientState * cl, xGLXSetClientInfoARBReq * req, | |
34 | unsigned bytes_per_version) | |
35 | { | |
36 | char *gl_extensions; | |
37 | char *glx_extensions; | |
38 | ||
39 | /* Verify that the size of the packet matches the size inferred from the | |
40 | * sizes specified for the various fields. | |
41 | */ | |
42 | const unsigned expected_size = sz_xGLXSetClientInfoARBReq | |
43 | + (req->numVersions * bytes_per_version) | |
44 | + __GLX_PAD(req->numGLExtensionBytes) | |
45 | + __GLX_PAD(req->numGLXExtensionBytes); | |
46 | ||
47 | if (req->length != (expected_size / 4)) | |
48 | return BadLength; | |
49 | ||
50 | /* Verify that the actual length of the GL extension string matches what's | |
51 | * encoded in protocol packet. | |
52 | */ | |
53 | gl_extensions = (char *) (req + 1) + (req->numVersions * bytes_per_version); | |
54 | if (req->numGLExtensionBytes != 0 | |
55 | && memchr(gl_extensions, 0, | |
56 | __GLX_PAD(req->numGLExtensionBytes)) == NULL) | |
57 | return BadLength; | |
58 | ||
59 | /* Verify that the actual length of the GLX extension string matches | |
60 | * what's encoded in protocol packet. | |
61 | */ | |
62 | glx_extensions = gl_extensions + __GLX_PAD(req->numGLExtensionBytes); | |
63 | if (req->numGLXExtensionBytes != 0 | |
64 | && memchr(glx_extensions, 0, | |
65 | __GLX_PAD(req->numGLXExtensionBytes)) == NULL) | |
66 | return BadLength; | |
67 | ||
68 | free(cl->GLClientextensions); | |
69 | cl->GLClientextensions = strdup(gl_extensions); | |
70 | ||
71 | return 0; | |
72 | } | |
73 | ||
74 | int | |
75 | __glXDisp_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc) | |
76 | { | |
77 | return set_client_info(cl, (xGLXSetClientInfoARBReq *) pc, 8); | |
78 | } | |
79 | ||
80 | int | |
81 | __glXDispSwap_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc) | |
82 | { | |
83 | xGLXSetClientInfoARBReq *req = (xGLXSetClientInfoARBReq *) pc; | |
84 | ||
85 | req->length = bswap_16(req->length); | |
86 | req->numVersions = bswap_32(req->numVersions); | |
87 | req->numGLExtensionBytes = bswap_32(req->numGLExtensionBytes); | |
88 | req->numGLXExtensionBytes = bswap_32(req->numGLXExtensionBytes); | |
89 | ||
90 | return __glXDisp_SetClientInfoARB(cl, pc); | |
91 | } | |
92 | ||
93 | int | |
94 | __glXDisp_SetClientInfo2ARB(__GLXclientState * cl, GLbyte * pc) | |
95 | { | |
96 | return set_client_info(cl, (xGLXSetClientInfoARBReq *) pc, 12); | |
97 | } | |
98 | ||
99 | int | |
100 | __glXDispSwap_SetClientInfo2ARB(__GLXclientState * cl, GLbyte * pc) | |
101 | { | |
102 | xGLXSetClientInfoARBReq *req = (xGLXSetClientInfoARBReq *) pc; | |
103 | ||
104 | req->length = bswap_16(req->length); | |
105 | req->numVersions = bswap_32(req->numVersions); | |
106 | req->numGLExtensionBytes = bswap_32(req->numGLExtensionBytes); | |
107 | req->numGLXExtensionBytes = bswap_32(req->numGLXExtensionBytes); | |
108 | ||
109 | return __glXDisp_SetClientInfo2ARB(cl, pc); | |
110 | } |