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.

356 lines
11 KiB

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