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.

105 lines
2.9 KiB

  1. #include <ole2.h>
  2. #include "valid.h"
  3. #include "debug.h"
  4. #if 1
  5. // we cannot turn this off until we remove from the export list!
  6. #undef IsValidPtrIn
  7. #undef IsValidPtrOut
  8. // BUGBUG: The following two functions are MACRO's in 2.01 code
  9. // but we need them for now because we only run with a storage
  10. // that uses ole232.dll. When we get rid of this these may die.
  11. STDAPI_(BOOL) IsValidPtrIn( const void FAR* pv, UINT cb )
  12. { // NULL is acceptable
  13. if (pv && IsBadReadPtr(pv,cb))
  14. {
  15. // AssertSz(FALSE, "Invalid in pointer");
  16. return FALSE;
  17. }
  18. return TRUE;
  19. }
  20. STDAPI_(BOOL) IsValidPtrOut( void FAR* pv, UINT cb )
  21. // NULL is not acceptable
  22. {
  23. if (IsBadWritePtr(pv,cb))
  24. {
  25. // AssertSz(FALSE, "Invalid out pointer");
  26. return FALSE;
  27. }
  28. return TRUE;
  29. }
  30. #endif
  31. STDAPI_(BOOL) IsValidInterface( void FAR* pv )
  32. {
  33. //
  34. // There is nothing to do about it on UNIX.
  35. //
  36. #ifndef UNIX
  37. DWORD_PTR FAR* pVtbl;
  38. BYTE FAR* pFcn;
  39. volatile BYTE bInstr;
  40. int i;
  41. __try {
  42. pVtbl = *(DWORD_PTR FAR* FAR*)pv; // pVtbl now points to beginning of vtable
  43. #if DBG==1
  44. for (i=0;i<3;++i) // loop through qi,addref,rel
  45. #else
  46. i=1; // in retail, just do AddRef
  47. #endif
  48. {
  49. pFcn = *(BYTE FAR* FAR*) &pVtbl[i]; // pFcn now points to beginning of QI,Addref, or Release
  50. #if DBG==1
  51. if (IsBadCodePtr((FARPROC FAR)pFcn)) {
  52. return FALSE;
  53. }
  54. #endif
  55. bInstr = *(BYTE FAR*) pFcn; // get 1st byte of 1st instruction
  56. }
  57. }
  58. __except(EXCEPTION_EXECUTE_HANDLER)
  59. {
  60. return FALSE;
  61. }
  62. #endif /* !unix */
  63. return TRUE;
  64. }
  65. // #if DBG==1
  66. // we cannot remove IsValidIID fcn until we remove from export list!
  67. // This function is NOT called in retail builds.
  68. // Its former implementation always returned TRUE thus doing NO validation.
  69. // It now validates in debug build and is not called in retail build
  70. #if DBG==0
  71. #ifdef IsValidIid
  72. #undef IsValidIid
  73. STDAPI_(BOOL) IsValidIid( REFIID iid );
  74. #endif
  75. #endif
  76. STDAPI_(BOOL) IsValidIid( REFIID iid )
  77. {
  78. #if DBG==1
  79. if (IsBadReadPtr((void*) &iid, 16)) {
  80. AssertSz(FALSE, "Invalid iid");
  81. return FALSE;
  82. }
  83. #endif
  84. return TRUE;
  85. }
  86. // #endif // DBG==1