openslp-2.0.0-fdr-CVE-2019-5544.patch 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. diff -ur openslp-2.0.0.orig/common/slp_buffer.c openslp-2.0.0/common/slp_buffer.c
  2. --- openslp-2.0.0.orig/common/slp_buffer.c 2012-12-10 15:31:53.000000000 -0800
  3. +++ openslp-2.0.0/common/slp_buffer.c 2019-11-26 21:54:20.000000000 -0800
  4. @@ -30,6 +30,13 @@
  5. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6. *-------------------------------------------------------------------------*/
  7. +/* Copyright (c) 2019 VMware, Inc.
  8. + * SPDX-License-Identifier: BSD-3-Clause
  9. + * This file is provided under the BSD-3-Clause license.
  10. + * See COPYING file for more details and other copyrights
  11. + * that may apply.
  12. + */
  13. +
  14. /** Functions for managing SLP message buffers.
  15. *
  16. * This file provides a higher level abstraction over malloc and free that
  17. @@ -153,4 +160,20 @@
  18. xfree(buf);
  19. }
  20. +/** Report remaining free buffer size in bytes.
  21. + *
  22. + * Check if buffer is allocated and if so return bytes left in a
  23. + * @c SLPBuffer object.
  24. + *
  25. + * @param[in] buf The SLPBuffer to be freed.
  26. + */
  27. +size_t
  28. +RemainingBufferSpace(SLPBuffer buf)
  29. +{
  30. + if (buf->allocated == 0) {
  31. + return 0;
  32. + }
  33. + return buf->end - buf->curpos;
  34. +}
  35. +
  36. /*=========================================================================*/
  37. diff -ur openslp-2.0.0.orig/common/slp_buffer.h openslp-2.0.0/common/slp_buffer.h
  38. --- openslp-2.0.0.orig/common/slp_buffer.h 2012-11-28 09:07:04.000000000 -0800
  39. +++ openslp-2.0.0/common/slp_buffer.h 2019-11-26 21:54:32.000000000 -0800
  40. @@ -30,6 +30,13 @@
  41. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. *-------------------------------------------------------------------------*/
  43. +/* Copyright (c) 2019 VMware, Inc.
  44. + * SPDX-License-Identifier: BSD-3-Clause
  45. + * This file is provided under the BSD-3-Clause license.
  46. + * See COPYING file for more details and other copyrights
  47. + * that may apply.
  48. + */
  49. +
  50. /** Header file that defines SLP message buffer management routines.
  51. *
  52. * Includes structures, constants and functions that used to handle memory
  53. @@ -78,6 +85,8 @@
  54. SLPBuffer SLPBufferListAdd(SLPBuffer * list, SLPBuffer buf);
  55. +size_t RemainingBufferSpace(SLPBuffer buf);
  56. +
  57. /*! @} */
  58. #endif /* SLP_BUFFER_H_INCLUDED */
  59. diff -ur openslp-2.0.0.orig/slpd/slpd_process.c openslp-2.0.0/slpd/slpd_process.c
  60. --- openslp-2.0.0.orig/slpd/slpd_process.c 2012-12-12 09:38:54.000000000 -0800
  61. +++ openslp-2.0.0/slpd/slpd_process.c 2019-11-26 21:55:10.000000000 -0800
  62. @@ -30,6 +30,13 @@
  63. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  64. *-------------------------------------------------------------------------*/
  65. +/* Copyright (c) 2019 VMware, Inc.
  66. + * SPDX-License-Identifier: BSD-3-Clause
  67. + * This file is provided under the BSD-3-Clause license.
  68. + * See COPYING file for more details and other copyrights
  69. + * that may apply.
  70. + */
  71. +
  72. /** Processes incoming SLP messages.
  73. *
  74. * @file slpd_process.c
  75. @@ -514,13 +521,27 @@
  76. {
  77. for (i = 0; i < db->urlcount; i++)
  78. {
  79. - /* urlentry is the url from the db result */
  80. urlentry = db->urlarray[i];
  81. + if (urlentry->opaque != NULL) {
  82. + const int64_t newsize = size + urlentry->opaquelen;
  83. + if (urlentry->opaquelen <= 0 || newsize > INT_MAX)
  84. + {
  85. + SLPDLog("Invalid opaquelen %d or sizeo of opaque url is too big, size=%d\n",
  86. + urlentry->opaquelen, size);
  87. + errorcode = SLP_ERROR_PARSE_ERROR;
  88. + goto FINISHED;
  89. + }
  90. + size += urlentry->opaquelen;
  91. + }
  92. + else
  93. + {
  94. + /* urlentry is the url from the db result */
  95. + size += urlentry->urllen + 6; /* 1 byte for reserved */
  96. + /* 2 bytes for lifetime */
  97. + /* 2 bytes for urllen */
  98. + /* 1 byte for authcount */
  99. + }
  100. - size += urlentry->urllen + 6; /* 1 byte for reserved */
  101. - /* 2 bytes for lifetime */
  102. - /* 2 bytes for urllen */
  103. - /* 1 byte for authcount */
  104. #ifdef ENABLE_SLPv2_SECURITY
  105. /* make room to include the authblock that was asked for */
  106. if (G_SlpdProperty.securityEnabled
  107. @@ -594,7 +615,7 @@
  108. urlentry = db->urlarray[i];
  109. #ifdef ENABLE_SLPv1
  110. - if (urlentry->opaque == 0)
  111. + if (urlentry->opaque == NULL)
  112. {
  113. /* url-entry reserved */
  114. *result->curpos++ = 0;
  115. @@ -606,8 +627,18 @@
  116. PutUINT16(&result->curpos, urlentry->urllen);
  117. /* url-entry url */
  118. - memcpy(result->curpos, urlentry->url, urlentry->urllen);
  119. - result->curpos += urlentry->urllen;
  120. + if (RemainingBufferSpace(result) >= urlentry->urllen)
  121. + {
  122. + memcpy(result->curpos, urlentry->url, urlentry->urllen);
  123. + result->curpos = result->curpos + urlentry->urllen;
  124. + }
  125. + else
  126. + {
  127. + SLPDLog("Url too big (ask: %d have %" PRId64 "), failing request\n",
  128. + urlentry->opaquelen, (int64_t) RemainingBufferSpace(result));
  129. + errorcode = SLP_ERROR_PARSE_ERROR;
  130. + goto FINISHED;
  131. + }
  132. /* url-entry auths */
  133. *result->curpos++ = 0;
  134. @@ -621,8 +652,18 @@
  135. /* TRICKY: Fix up the lifetime. */
  136. TO_UINT16(urlentry->opaque + 1, urlentry->lifetime);
  137. - memcpy(result->curpos, urlentry->opaque, urlentry->opaquelen);
  138. - result->curpos += urlentry->opaquelen;
  139. + if (RemainingBufferSpace(result) >= urlentry->opaquelen)
  140. + {
  141. + memcpy(result->curpos, urlentry->opaque, urlentry->opaquelen);
  142. + result->curpos = result->curpos + urlentry->opaquelen;
  143. + }
  144. + else
  145. + {
  146. + SLPDLog("Opaque Url too big (ask: %d have %" PRId64 "), failing request\n",
  147. + urlentry->opaquelen, (int64_t) RemainingBufferSpace(result));
  148. + errorcode = SLP_ERROR_PARSE_ERROR;
  149. + goto FINISHED;
  150. + }
  151. }
  152. }
  153. }