clientinfo.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #include "glxserver.h"
  27. #include "indirect_dispatch.h"
  28. #include "glxbyteorder.h"
  29. #include "unpack.h"
  30. static int
  31. set_client_info(__GLXclientState * cl, xGLXSetClientInfoARBReq * req,
  32. unsigned bytes_per_version)
  33. {
  34. ClientPtr client = cl->client;
  35. char *gl_extensions;
  36. char *glx_extensions;
  37. int size;
  38. REQUEST_AT_LEAST_SIZE(xGLXSetClientInfoARBReq);
  39. /* Verify that the size of the packet matches the size inferred from the
  40. * sizes specified for the various fields.
  41. */
  42. size = sz_xGLXSetClientInfoARBReq;
  43. size = safe_add(size, safe_mul(req->numVersions, bytes_per_version));
  44. size = safe_add(size, safe_pad(req->numGLExtensionBytes));
  45. size = safe_add(size, safe_pad(req->numGLXExtensionBytes));
  46. if (size < 0 || req->length != (size / 4))
  47. return BadLength;
  48. /* Verify that the actual length of the GL extension string matches what's
  49. * encoded in protocol packet.
  50. */
  51. gl_extensions = (char *) (req + 1) + (req->numVersions * bytes_per_version);
  52. if (req->numGLExtensionBytes != 0
  53. && memchr(gl_extensions, 0,
  54. __GLX_PAD(req->numGLExtensionBytes)) == NULL)
  55. return BadLength;
  56. /* Verify that the actual length of the GLX extension string matches
  57. * what's encoded in protocol packet.
  58. */
  59. glx_extensions = gl_extensions + __GLX_PAD(req->numGLExtensionBytes);
  60. if (req->numGLXExtensionBytes != 0
  61. && memchr(glx_extensions, 0,
  62. __GLX_PAD(req->numGLXExtensionBytes)) == NULL)
  63. return BadLength;
  64. free(cl->GLClientextensions);
  65. cl->GLClientextensions = strdup(gl_extensions);
  66. return 0;
  67. }
  68. int
  69. __glXDisp_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
  70. {
  71. return set_client_info(cl, (xGLXSetClientInfoARBReq *) pc, 8);
  72. }
  73. int
  74. __glXDispSwap_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
  75. {
  76. ClientPtr client = cl->client;
  77. xGLXSetClientInfoARBReq *req = (xGLXSetClientInfoARBReq *) pc;
  78. REQUEST_AT_LEAST_SIZE(xGLXSetClientInfoARBReq);
  79. req->length = bswap_16(req->length);
  80. req->numVersions = bswap_32(req->numVersions);
  81. req->numGLExtensionBytes = bswap_32(req->numGLExtensionBytes);
  82. req->numGLXExtensionBytes = bswap_32(req->numGLXExtensionBytes);
  83. return __glXDisp_SetClientInfoARB(cl, pc);
  84. }
  85. int
  86. __glXDisp_SetClientInfo2ARB(__GLXclientState * cl, GLbyte * pc)
  87. {
  88. return set_client_info(cl, (xGLXSetClientInfoARBReq *) pc, 12);
  89. }
  90. int
  91. __glXDispSwap_SetClientInfo2ARB(__GLXclientState * cl, GLbyte * pc)
  92. {
  93. ClientPtr client = cl->client;
  94. xGLXSetClientInfoARBReq *req = (xGLXSetClientInfoARBReq *) pc;
  95. REQUEST_AT_LEAST_SIZE(xGLXSetClientInfoARBReq);
  96. req->length = bswap_16(req->length);
  97. req->numVersions = bswap_32(req->numVersions);
  98. req->numGLExtensionBytes = bswap_32(req->numGLExtensionBytes);
  99. req->numGLXExtensionBytes = bswap_32(req->numGLXExtensionBytes);
  100. return __glXDisp_SetClientInfo2ARB(cl, pc);
  101. }