Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
4.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: Valid.cxx (16 bit target)
  7. //
  8. // Contents: Validation APIs exported by CompObj
  9. //
  10. // Functions:
  11. //
  12. // History: 93 OLE 2.0 Dev team Cretead
  13. // 17-Dec-93 JohannP
  14. //
  15. //--------------------------------------------------------------------------
  16. #include <headers.cxx>
  17. #pragma hdrstop
  18. /*
  19. * IsValidPtrIn -- Check if the pointer points to a readable segment
  20. * and if the pointer + #of bytes stays within the segment.
  21. *
  22. * NULL will fail
  23. *
  24. * cb == 0 will FAIL
  25. *
  26. * This function exists only for compatibility with already-compiled apps.
  27. * We now use macros for IsValidPtrIn and IsValidPtrOut
  28. * Check out the comments in inc\valid.h
  29. */
  30. //+---------------------------------------------------------------------------
  31. //
  32. // Function: ISVALIDPTRIN, Local
  33. //
  34. // Synopsis:
  35. //
  36. // Effects:
  37. //
  38. // Arguments: [pv] --
  39. // [cb] --
  40. //
  41. // Requires:
  42. //
  43. // Returns:
  44. //
  45. // Signals:
  46. //
  47. // Modifies:
  48. //
  49. // Algorithm:
  50. //
  51. // History: 2-28-94 kevinro Created
  52. //
  53. // Notes:
  54. //
  55. //----------------------------------------------------------------------------
  56. STDAPI_(BOOL)
  57. ISVALIDPTRIN( const void FAR* pv, UINT cb )
  58. {
  59. return !IsBadReadPtr (pv, cb);
  60. // We cannot use inline assembly here because the VERR instruction does
  61. // not work if the segment has been discarded (but is still valid).
  62. }
  63. // This function exists only for compatibility with already-compiled apps.
  64. // We now use macros for IsValidPtrIn and IsValidPtrOut
  65. //
  66. // Check out the comments in inc\valid.h
  67. //+---------------------------------------------------------------------------
  68. //
  69. // Function: ISVALIDPTROUT, Local
  70. //
  71. // Synopsis:
  72. //
  73. // Effects:
  74. //
  75. // Arguments: [pv] --
  76. // [cb] --
  77. //
  78. // Requires:
  79. //
  80. // Returns:
  81. //
  82. // Signals:
  83. //
  84. // Modifies:
  85. //
  86. // Algorithm:
  87. //
  88. // History: 2-28-94 kevinro Created
  89. //
  90. // Notes:
  91. //
  92. //----------------------------------------------------------------------------
  93. STDAPI_(BOOL)
  94. ISVALIDPTROUT( void FAR* pv, UINT cb )
  95. // NULL is not acceptable
  96. {
  97. return !IsBadWritePtr (pv, cb);
  98. }
  99. // valid code begins 0xb8, ??, ??, followed by:
  100. // BYTE validcode[6] = { 0x55, 0x8b, 0xec, 0x1e, 0x8e, 0xd8};
  101. //+---------------------------------------------------------------------------
  102. //
  103. // Function: IsValidInterface, Local
  104. //
  105. // Synopsis:
  106. //
  107. // Effects:
  108. //
  109. // Arguments: [pv] --
  110. //
  111. // Requires:
  112. //
  113. // Returns:
  114. //
  115. // Signals:
  116. //
  117. // Modifies:
  118. //
  119. // Algorithm:
  120. //
  121. // History: 2-28-94 kevinro Created
  122. //
  123. // Notes:
  124. //
  125. //----------------------------------------------------------------------------
  126. STDAPI_(BOOL) IsValidInterface( void FAR* pv )
  127. {
  128. BYTE FAR* pb;
  129. // NULL is not acceptable as input.
  130. if (!IsValidPtrIn(pv,4)) goto false;
  131. #ifdef _STRICT_VALIDATION
  132. // if the interface was compiled with C++, the virtual function table
  133. // will be in a code segment
  134. if (IsBadCodePtr(*(FARPROC FAR*)pv)) goto false;
  135. #endif
  136. pb = *(BYTE FAR* FAR*)pv; // pb points to beginning of vftable
  137. if (!IsValidPtrIn(pb, 4)) goto false;
  138. if (IsBadCodePtr(*(FARPROC FAR*)pb)) goto false;
  139. pb = *(BYTE FAR* FAR*)pb;
  140. if (!IsValidPtrIn(pb, 9)) goto false;
  141. // if (*pb != 0xb8) goto false;
  142. // pb += 3;
  143. // if (_fmemcmp(pb, validcode, 6)) goto false;
  144. return TRUE;
  145. false:
  146. // AssertSz(FALSE, "Invalid interface pointer");
  147. return FALSE;
  148. }
  149. //+---------------------------------------------------------------------------
  150. //
  151. // Function: IsValidIid, Local
  152. //
  153. // Synopsis:
  154. //
  155. // Effects:
  156. //
  157. // Arguments: [iid] --
  158. //
  159. // Requires:
  160. //
  161. // Returns:
  162. //
  163. // Signals:
  164. //
  165. // Modifies:
  166. //
  167. // Algorithm:
  168. //
  169. // History: 2-28-94 kevinro Created
  170. //
  171. // Notes:
  172. //
  173. //----------------------------------------------------------------------------
  174. STDAPI_(BOOL)
  175. IsValidIid( REFIID iid )
  176. {
  177. IID iidTemp = iid;
  178. DWORD FAR* pdw = (DWORD FAR*)&iidTemp;
  179. *pdw = 0;
  180. if (IID_IUnknown == iidTemp) return TRUE;
  181. thkDebugOut((DEB_IERROR, "WARNING: Nonstandard IID parameter"));
  182. return TRUE;
  183. }