Source code of Windows XP (NT5)
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.

357 lines
11 KiB

  1. /*
  2. * olevalid.c - OLE validation functions module.
  3. */
  4. /* Headers
  5. **********/
  6. #include "project.h"
  7. #pragma hdrstop
  8. #include <intshcut.h>
  9. #include "olestock.h"
  10. #include "olevalid.h"
  11. #ifdef DEBUG
  12. /****************************** Public Functions *****************************/
  13. PUBLIC_CODE BOOL IsValidPCGUID(PCGUID pcguid)
  14. {
  15. /* All values are valid GUIDs. */
  16. return(IS_VALID_READ_PTR(pcguid, CGUID));
  17. }
  18. PUBLIC_CODE BOOL IsValidPCCLSID(PCCLSID pcclsid)
  19. {
  20. return(IS_VALID_STRUCT_PTR(pcclsid, CGUID));
  21. }
  22. PUBLIC_CODE BOOL IsValidPCIID(PCIID pciid)
  23. {
  24. return(IS_VALID_STRUCT_PTR(pciid, CGUID));
  25. }
  26. PUBLIC_CODE BOOL IsValidPCDVTARGETDEVICE(PCDVTARGETDEVICE pcdvtd)
  27. {
  28. /* FEATURE: Validate remaining fields here. */
  29. return(IS_VALID_READ_PTR(&(pcdvtd->tdSize), DWORD) &&
  30. IS_VALID_READ_BUFFER_PTR(pcdvtd, DVTARGETDEVICE, pcdvtd->tdSize));
  31. }
  32. PUBLIC_CODE BOOL IsValidPCFORMATETC(PCFORMATETC pcfe)
  33. {
  34. /* FEATURE: Validate structure fields. */
  35. return(IS_VALID_READ_PTR(pcfe, CFORMATETC));
  36. }
  37. PUBLIC_CODE BOOL IsValidStgMediumType(DWORD tymed)
  38. {
  39. BOOL bResult;
  40. switch (tymed)
  41. {
  42. case TYMED_HGLOBAL:
  43. case TYMED_FILE:
  44. case TYMED_ISTREAM:
  45. case TYMED_ISTORAGE:
  46. case TYMED_GDI:
  47. case TYMED_MFPICT:
  48. case TYMED_ENHMF:
  49. case TYMED_NULL:
  50. bResult = TRUE;
  51. break;
  52. default:
  53. bResult = FALSE;
  54. ERROR_OUT(("IsValidStgMediumType(): Invalid storage medium type %lu.",
  55. tymed));
  56. break;
  57. }
  58. return(bResult);
  59. }
  60. PUBLIC_CODE BOOL IsValidPCSTGMEDIUM(PCSTGMEDIUM pcstgmed)
  61. {
  62. /* FEATURE: Validate u union field. */
  63. return(IS_VALID_READ_PTR(pcstgmed, CSTGMEDIUM) &&
  64. IsValidStgMediumType(pcstgmed->tymed) &&
  65. (! pcstgmed->pUnkForRelease ||
  66. IS_VALID_INTERFACE_PTR(pcstgmed->pUnkForRelease, IUnknown)));
  67. }
  68. PUBLIC_CODE BOOL IsValidREFIID(REFIID riid)
  69. {
  70. return(IS_VALID_STRUCT_PTR(riid, CIID));
  71. }
  72. PUBLIC_CODE BOOL IsValidREFCLSID(REFCLSID rclsid)
  73. {
  74. return(IS_VALID_STRUCT_PTR(rclsid, CCLSID));
  75. }
  76. PUBLIC_CODE BOOL IsValidPCINTERFACE(PCVOID pcvi)
  77. {
  78. return(IS_VALID_READ_PTR((FARPROC *)pcvi, FARPROC) &&
  79. IS_VALID_CODE_PTR(*((FARPROC *)pcvi), Method));
  80. }
  81. PUBLIC_CODE BOOL IsValidPCIAdviseSink(PCIAdviseSink pcias)
  82. {
  83. return(IS_VALID_READ_PTR(pcias, CIAdviseSink) &&
  84. IS_VALID_READ_PTR(pcias->lpVtbl, sizeof(*(pcias->lpVtbl))) &&
  85. IS_VALID_INTERFACE_PTR((PCIUnknown)pcias, IUnknown) &&
  86. IS_VALID_METHOD(pcias, OnDataChange) &&
  87. IS_VALID_METHOD(pcias, OnViewChange) &&
  88. IS_VALID_METHOD(pcias, OnRename) &&
  89. IS_VALID_METHOD(pcias, OnSave) &&
  90. IS_VALID_METHOD(pcias, OnClose));
  91. }
  92. PUBLIC_CODE BOOL IsValidPCIClassFactory(PCIClassFactory pcicf)
  93. {
  94. return(IS_VALID_READ_PTR(pcicf, CIClassFactory) &&
  95. IS_VALID_READ_PTR(pcicf->lpVtbl, sizeof(*(pcicf->lpVtbl))) &&
  96. IS_VALID_INTERFACE_PTR((PCIUnknown)pcicf, IUnknown) &&
  97. IS_VALID_METHOD(pcicf, CreateInstance) &&
  98. IS_VALID_METHOD(pcicf, LockServer));
  99. }
  100. PUBLIC_CODE BOOL IsValidPCIDataObject(PCIDataObject pcido)
  101. {
  102. return(IS_VALID_READ_PTR(pcido, CIDataObject) &&
  103. IS_VALID_READ_PTR(pcido->lpVtbl, sizeof(*(pcido->lpVtbl))) &&
  104. IS_VALID_INTERFACE_PTR((PCIUnknown)pcido, IUnknown) &&
  105. IS_VALID_METHOD(pcido, GetData) &&
  106. IS_VALID_METHOD(pcido, GetDataHere) &&
  107. IS_VALID_METHOD(pcido, QueryGetData) &&
  108. IS_VALID_METHOD(pcido, GetCanonicalFormatEtc) &&
  109. IS_VALID_METHOD(pcido, SetData) &&
  110. IS_VALID_METHOD(pcido, EnumFormatEtc) &&
  111. IS_VALID_METHOD(pcido, DAdvise) &&
  112. IS_VALID_METHOD(pcido, DUnadvise) &&
  113. IS_VALID_METHOD(pcido, EnumDAdvise));
  114. }
  115. PUBLIC_CODE BOOL IsValidPCIDropSource(PCIDropSource pcids)
  116. {
  117. return(IS_VALID_READ_PTR(pcids, CIDataObject) &&
  118. IS_VALID_READ_PTR(pcids->lpVtbl, sizeof(*(pcids->lpVtbl))) &&
  119. IS_VALID_INTERFACE_PTR((PCIUnknown)pcids, IUnknown) &&
  120. IS_VALID_METHOD(pcids, QueryContinueDrag) &&
  121. IS_VALID_METHOD(pcids, GiveFeedback));
  122. }
  123. PUBLIC_CODE BOOL IsValidPCIDropTarget(PCIDropTarget pcidt)
  124. {
  125. return(IS_VALID_READ_PTR(pcidt, CIDataObject) &&
  126. IS_VALID_READ_PTR(pcidt->lpVtbl, sizeof(*(pcidt->lpVtbl))) &&
  127. IS_VALID_INTERFACE_PTR((PCIUnknown)pcidt, IUnknown) &&
  128. IS_VALID_METHOD(pcidt, DragEnter) &&
  129. IS_VALID_METHOD(pcidt, DragOver) &&
  130. IS_VALID_METHOD(pcidt, DragLeave) &&
  131. IS_VALID_METHOD(pcidt, Drop));
  132. }
  133. PUBLIC_CODE BOOL IsValidPCIEnumFORMATETC(PCIEnumFORMATETC pciefe)
  134. {
  135. return(IS_VALID_READ_PTR(pciefe, CIEnumFORMATETC) &&
  136. IS_VALID_READ_PTR(pciefe->lpVtbl, sizeof(*(pciefe->lpVtbl))) &&
  137. IS_VALID_INTERFACE_PTR((PCIUnknown)pciefe, IUnknown) &&
  138. IS_VALID_METHOD(pciefe, Next) &&
  139. IS_VALID_METHOD(pciefe, Skip) &&
  140. IS_VALID_METHOD(pciefe, Reset) &&
  141. IS_VALID_METHOD(pciefe, Clone));
  142. }
  143. PUBLIC_CODE BOOL IsValidPCIEnumSTATDATA(PCIEnumSTATDATA pciesd)
  144. {
  145. return(IS_VALID_READ_PTR(pciesd, CIDataObject) &&
  146. IS_VALID_READ_PTR(pciesd->lpVtbl, sizeof(*(pciesd->lpVtbl))) &&
  147. IS_VALID_INTERFACE_PTR((PCIUnknown)pciesd, IUnknown) &&
  148. IS_VALID_METHOD(pciesd, Next) &&
  149. IS_VALID_METHOD(pciesd, Skip) &&
  150. IS_VALID_METHOD(pciesd, Reset) &&
  151. IS_VALID_METHOD(pciesd, Clone));
  152. }
  153. PUBLIC_CODE BOOL IsValidPCIMalloc(PCIMalloc pcimalloc)
  154. {
  155. return(IS_VALID_READ_PTR(pcimalloc, CIMalloc) &&
  156. IS_VALID_READ_PTR(pcimalloc->lpVtbl, sizeof(*(pcimalloc->lpVtbl))) &&
  157. IS_VALID_INTERFACE_PTR((PCIUnknown)pcimalloc, IUnknown) &&
  158. IS_VALID_METHOD(pcimalloc, Alloc) &&
  159. IS_VALID_METHOD(pcimalloc, Realloc) &&
  160. IS_VALID_METHOD(pcimalloc, Free) &&
  161. IS_VALID_METHOD(pcimalloc, GetSize) &&
  162. IS_VALID_METHOD(pcimalloc, DidAlloc) &&
  163. IS_VALID_METHOD(pcimalloc, HeapMinimize));
  164. }
  165. PUBLIC_CODE BOOL IsValidPCIMoniker(PCIMoniker pcimk)
  166. {
  167. return(IS_VALID_READ_PTR(pcimk, CIMoniker) &&
  168. IS_VALID_READ_PTR(pcimk->lpVtbl, sizeof(*(pcimk->lpVtbl))) &&
  169. IS_VALID_INTERFACE_PTR((PCIPersistStream)pcimk, IPersistStream) &&
  170. IS_VALID_METHOD(pcimk, BindToObject) &&
  171. IS_VALID_METHOD(pcimk, BindToStorage) &&
  172. IS_VALID_METHOD(pcimk, Reduce) &&
  173. IS_VALID_METHOD(pcimk, ComposeWith) &&
  174. IS_VALID_METHOD(pcimk, Enum) &&
  175. IS_VALID_METHOD(pcimk, IsEqual) &&
  176. IS_VALID_METHOD(pcimk, Hash) &&
  177. IS_VALID_METHOD(pcimk, IsRunning) &&
  178. IS_VALID_METHOD(pcimk, GetTimeOfLastChange) &&
  179. IS_VALID_METHOD(pcimk, Inverse) &&
  180. IS_VALID_METHOD(pcimk, CommonPrefixWith) &&
  181. IS_VALID_METHOD(pcimk, RelativePathTo) &&
  182. IS_VALID_METHOD(pcimk, GetDisplayName) &&
  183. IS_VALID_METHOD(pcimk, ParseDisplayName) &&
  184. IS_VALID_METHOD(pcimk, IsSystemMoniker));
  185. }
  186. PUBLIC_CODE BOOL IsValidPCIPersist(PCIPersist pcip)
  187. {
  188. return(IS_VALID_READ_PTR(pcip, CIUnknown) &&
  189. IS_VALID_READ_PTR(pcip->lpVtbl, sizeof(*(pcip->lpVtbl))) &&
  190. IS_VALID_INTERFACE_PTR((PCIUnknown)pcip, IUnknown) &&
  191. IS_VALID_METHOD(pcip, GetClassID));
  192. }
  193. PUBLIC_CODE BOOL IsValidPCIPersistFile(PCIPersistFile pcipfile)
  194. {
  195. return(IS_VALID_READ_PTR(pcipfile, CIPersistFile) &&
  196. IS_VALID_READ_PTR(pcipfile->lpVtbl, sizeof(*(pcipfile->lpVtbl))) &&
  197. IS_VALID_INTERFACE_PTR((PCIPersist)pcipfile, IPersist) &&
  198. IS_VALID_METHOD(pcipfile, IsDirty) &&
  199. IS_VALID_METHOD(pcipfile, Load) &&
  200. IS_VALID_METHOD(pcipfile, Save) &&
  201. IS_VALID_METHOD(pcipfile, SaveCompleted) &&
  202. IS_VALID_METHOD(pcipfile, GetCurFile));
  203. }
  204. PUBLIC_CODE BOOL IsValidPCIPersistStorage(PCIPersistStorage pcipstg)
  205. {
  206. return(IS_VALID_READ_PTR(pcipstg, CIPersistStorage) &&
  207. IS_VALID_READ_PTR(pcipstg->lpVtbl, sizeof(*(pcipstg->lpVtbl))) &&
  208. IS_VALID_INTERFACE_PTR((PCIPersist)pcipstg, IPersist) &&
  209. IS_VALID_METHOD(pcipstg, IsDirty) &&
  210. IS_VALID_METHOD(pcipstg, InitNew) &&
  211. IS_VALID_METHOD(pcipstg, Load) &&
  212. IS_VALID_METHOD(pcipstg, Save) &&
  213. IS_VALID_METHOD(pcipstg, SaveCompleted) &&
  214. IS_VALID_METHOD(pcipstg, HandsOffStorage));
  215. }
  216. PUBLIC_CODE BOOL IsValidPCIPersistStream(PCIPersistStream pcipstr)
  217. {
  218. return(IS_VALID_READ_PTR(pcipstr, CIPersistStream) &&
  219. IS_VALID_READ_PTR(pcipstr->lpVtbl, sizeof(*(pcipstr->lpVtbl))) &&
  220. IS_VALID_INTERFACE_PTR((PCIPersist)pcipstr, IPersist) &&
  221. IS_VALID_METHOD(pcipstr, IsDirty) &&
  222. IS_VALID_METHOD(pcipstr, Load) &&
  223. IS_VALID_METHOD(pcipstr, Save) &&
  224. IS_VALID_METHOD(pcipstr, GetSizeMax));
  225. }
  226. PUBLIC_CODE BOOL IsValidPCIStorage(PCIStorage pcistg)
  227. {
  228. return(IS_VALID_READ_PTR(pcistg, CIStorage) &&
  229. IS_VALID_READ_PTR(pcistg->lpVtbl, sizeof(*(pcistg->lpVtbl))) &&
  230. IS_VALID_INTERFACE_PTR((PCIUnknown)pcistg, IUnknown) &&
  231. IS_VALID_METHOD(pcistg, CreateStream) &&
  232. IS_VALID_METHOD(pcistg, OpenStream) &&
  233. IS_VALID_METHOD(pcistg, CreateStorage) &&
  234. IS_VALID_METHOD(pcistg, OpenStorage) &&
  235. IS_VALID_METHOD(pcistg, CopyTo) &&
  236. IS_VALID_METHOD(pcistg, MoveElementTo) &&
  237. IS_VALID_METHOD(pcistg, Commit) &&
  238. IS_VALID_METHOD(pcistg, Revert) &&
  239. IS_VALID_METHOD(pcistg, EnumElements) &&
  240. IS_VALID_METHOD(pcistg, DestroyElement) &&
  241. IS_VALID_METHOD(pcistg, RenameElement) &&
  242. IS_VALID_METHOD(pcistg, SetElementTimes) &&
  243. IS_VALID_METHOD(pcistg, SetClass) &&
  244. IS_VALID_METHOD(pcistg, SetStateBits) &&
  245. IS_VALID_METHOD(pcistg, Stat));
  246. }
  247. PUBLIC_CODE BOOL IsValidPCIStream(PCIStream pcistr)
  248. {
  249. return(IS_VALID_READ_PTR(pcistr, CIStorage) &&
  250. IS_VALID_READ_PTR(pcistr->lpVtbl, sizeof(*(pcistr->lpVtbl))) &&
  251. IS_VALID_INTERFACE_PTR((PCIUnknown)pcistr, IUnknown) &&
  252. IS_VALID_METHOD(pcistr, Read) &&
  253. IS_VALID_METHOD(pcistr, Write) &&
  254. IS_VALID_METHOD(pcistr, Seek) &&
  255. IS_VALID_METHOD(pcistr, SetSize) &&
  256. IS_VALID_METHOD(pcistr, CopyTo) &&
  257. IS_VALID_METHOD(pcistr, Commit) &&
  258. IS_VALID_METHOD(pcistr, Revert) &&
  259. IS_VALID_METHOD(pcistr, LockRegion) &&
  260. IS_VALID_METHOD(pcistr, UnlockRegion) &&
  261. IS_VALID_METHOD(pcistr, Stat) &&
  262. IS_VALID_METHOD(pcistr, Clone));
  263. }
  264. PUBLIC_CODE BOOL IsValidPCIUnknown(PCIUnknown pciunk)
  265. {
  266. return(IS_VALID_READ_PTR(pciunk, CIUnknown) &&
  267. IS_VALID_READ_PTR(pciunk->lpVtbl, sizeof(*(pciunk->lpVtbl))) &&
  268. IS_VALID_METHOD(pciunk, QueryInterface) &&
  269. IS_VALID_METHOD(pciunk, AddRef) &&
  270. IS_VALID_METHOD(pciunk, Release));
  271. }
  272. #ifdef __INTSHCUT_H__
  273. PUBLIC_CODE BOOL IsValidPCIUniformResourceLocator(
  274. PCIUniformResourceLocator pciurl)
  275. {
  276. return(IS_VALID_READ_PTR(pciurl, CIUniformResourceLocator) &&
  277. IS_VALID_READ_PTR(pciurl->lpVtbl, sizeof(*(pciurl->lpVtbl))) &&
  278. IS_VALID_INTERFACE_PTR((PCIUnknown)pciurl, IUnknown) &&
  279. IS_VALID_METHOD(pciurl, SetURL) &&
  280. IS_VALID_METHOD(pciurl, GetURL) &&
  281. IS_VALID_METHOD(pciurl, InvokeCommand));
  282. }
  283. #endif /* __INTSHCUT_H__ */
  284. #endif /* DEBUG */