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.

290 lines
7.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: validate.cpp
  7. //
  8. // Contents: validation routines
  9. //
  10. // Classes:
  11. //
  12. // Notes:
  13. //
  14. // History: 13-Aug-98 rogerg Created.
  15. //
  16. //--------------------------------------------------------------------------
  17. #include "lib.h"
  18. //+---------------------------------------------------------------------------
  19. //
  20. // function: IsValidSyncMgrItem
  21. //
  22. // Synopsis: validates SYNCMGRITEM
  23. //
  24. // Arguments:
  25. //
  26. // Returns: TRUE if valid.
  27. //
  28. // Modifies:
  29. //
  30. // History: 13-Aug-98 rogerg Created.
  31. //
  32. //+---------------------------------------------------------------------------
  33. BOOL IsValidSyncMgrItem(SYNCMGRITEM *poffItem)
  34. {
  35. BOOL fValid = TRUE;
  36. if (NULL == poffItem)
  37. {
  38. Assert(poffItem);
  39. return FALSE;
  40. }
  41. __try
  42. {
  43. if (poffItem->cbSize == sizeof(SYNCMGRITEMNT5B2))
  44. {
  45. // this is an old NT5b2 stucture. not really anything
  46. // to do other than make sure flags are valid for ths struct.
  47. Assert(0 == (poffItem->dwFlags & ~(SYNCMGRITEM_ITEMFLAGMASKNT5B2)));
  48. // for BETA2 go ahead and fall through since didn't validate
  49. // and we can remove this.
  50. }
  51. else if (poffItem->cbSize == sizeof(SYNCMGRITEM))
  52. {
  53. if ( (0 != (poffItem->dwFlags & ~(SYNCMGRITEM_ITEMFLAGMASK) ) )
  54. || (SYNCMGRITEMSTATE_CHECKED < poffItem->dwItemState) )
  55. {
  56. AssertSz(0,"Invalid SYNCMGRITEM returned from Enumerator");
  57. Assert(0 == (poffItem->dwFlags & ~(SYNCMGRITEM_ITEMFLAGMASK)));
  58. Assert(SYNCMGRITEMSTATE_CHECKED >= poffItem->dwItemState);
  59. fValid = FALSE;
  60. }
  61. else if (GUID_NULL == poffItem->ItemID)
  62. {
  63. AssertSz(0,"ItemID Cannot be GUID_NULL");
  64. fValid = FALSE;
  65. }
  66. }
  67. else
  68. {
  69. AssertSz(0,"Invalid SYNCMGRITEM returned from Enumerator");
  70. fValid = FALSE;
  71. }
  72. }
  73. __except(EXCEPTION_EXECUTE_HANDLER)
  74. {
  75. //bogus non-NULL pointer.
  76. AssertSz(0,"Bogus, non-NULL SYNCMGRITEM pointer returned from Enumerator");
  77. fValid = FALSE;
  78. }
  79. return fValid;
  80. }
  81. //+---------------------------------------------------------------------------
  82. //
  83. // function: IsValidSyncMgrHandlerInfo
  84. //
  85. // Synopsis: validates SYNCMGRITEM
  86. //
  87. // Arguments:
  88. //
  89. // Returns: TRUE if valid.
  90. //
  91. // Modifies:
  92. //
  93. // History: 13-Aug-98 rogerg Created.
  94. //
  95. //+---------------------------------------------------------------------------
  96. BOOL IsValidSyncMgrHandlerInfo(LPSYNCMGRHANDLERINFO pSyncMgrHandlerInfo)
  97. {
  98. // validate the arguments.
  99. __try
  100. {
  101. if ( (pSyncMgrHandlerInfo->cbSize != sizeof(SYNCMGRHANDLERINFO))
  102. || (0 != (pSyncMgrHandlerInfo->SyncMgrHandlerFlags & ~(SYNCMGRHANDLERFLAG_MASK))) )
  103. {
  104. AssertSz(0,"Invalid HandlerInfo Size returned from GetHandlerInfo");
  105. Assert(pSyncMgrHandlerInfo->cbSize == sizeof(SYNCMGRHANDLERINFO));
  106. Assert(0 == (pSyncMgrHandlerInfo->SyncMgrHandlerFlags & ~(SYNCMGRHANDLERFLAG_MASK)));
  107. return FALSE;
  108. }
  109. }
  110. __except(EXCEPTION_EXECUTE_HANDLER)
  111. {
  112. AssertSz(0,"Bogus, non-NULL LPSYNCMGRHANDLERINFO pointer.");
  113. return FALSE;
  114. }
  115. return TRUE;
  116. }
  117. //+---------------------------------------------------------------------------
  118. //
  119. // Function: IsValidSyncProgressItem, private
  120. //
  121. // Synopsis: Determines if the syncprogress item structure is valid
  122. //
  123. // Arguments: [lpProgItem] - Pointer to SyncProgress Item to validate.
  124. //
  125. // Returns: Returns true is the structure is valid.
  126. //
  127. // Modifies:
  128. //
  129. // History: 17-Nov-97 rogerg Created.
  130. //
  131. //----------------------------------------------------------------------------
  132. BOOL IsValidSyncProgressItem(LPSYNCMGRPROGRESSITEM lpProgItem)
  133. {
  134. if (NULL == lpProgItem)
  135. {
  136. Assert(lpProgItem);
  137. return FALSE;
  138. }
  139. __try
  140. {
  141. if (lpProgItem->cbSize != sizeof(SYNCMGRPROGRESSITEM))
  142. {
  143. AssertSz(0,"SYNCMGRPROGRESSITEM cbSize Incorrect");
  144. return FALSE;
  145. }
  146. if (IsBadReadPtr(lpProgItem,sizeof(SYNCMGRPROGRESSITEM)) )
  147. {
  148. AssertSz(0,"ProgressItem Structure Memory Invalid");
  149. return FALSE;
  150. }
  151. if (lpProgItem->mask >= (SYNCMGRPROGRESSITEM_MAXVALUE << 1))
  152. {
  153. AssertSz(0,"Invalid ProgressItem Mask");
  154. return FALSE;
  155. }
  156. if (SYNCMGRPROGRESSITEM_STATUSTYPE & lpProgItem->mask)
  157. {
  158. if (lpProgItem->dwStatusType > SYNCMGRSTATUS_RESUMING)
  159. {
  160. AssertSz(0,"Unknown StatusType passed to Progress");
  161. return FALSE;
  162. }
  163. }
  164. if (SYNCMGRPROGRESSITEM_STATUSTEXT & lpProgItem->mask)
  165. {
  166. if (IsBadStringPtr(lpProgItem->lpcStatusText,-1) )
  167. {
  168. AssertSz(0,"Invalid status text");
  169. return FALSE;
  170. }
  171. }
  172. }
  173. __except(EXCEPTION_EXECUTE_HANDLER)
  174. {
  175. AssertSz(0,"Bogus, non-NULL LPSYNCMGRPROGRESSITEM pointer.");
  176. return FALSE;
  177. }
  178. return TRUE;
  179. }
  180. //+---------------------------------------------------------------------------
  181. //
  182. // Function: IsValidSyncLogErrorInfo, private
  183. //
  184. // Synopsis: Determines if the ErrorInfomation is valid,
  185. //
  186. // Arguments: [lpLogError] - Pointer to LogError structure to validate.
  187. //
  188. // Returns: Returns true is the structure is valid.
  189. //
  190. // Modifies:
  191. //
  192. // History: 17-Nov-97 rogerg Created.
  193. //
  194. //----------------------------------------------------------------------------
  195. #define SYNCMGRLOGERROR_VALIDMASK (SYNCMGRLOGERROR_ERRORFLAGS | SYNCMGRLOGERROR_ERRORID | SYNCMGRLOGERROR_ITEMID)
  196. #define SYNCMGRERRROFLAG_MASK (SYNCMGRERRORFLAG_ENABLEJUMPTEXT)
  197. BOOL IsValidSyncLogErrorInfo(DWORD dwErrorLevel,const WCHAR *lpcErrorText,
  198. LPSYNCMGRLOGERRORINFO lpSyncLogError)
  199. {
  200. if (SYNCMGRLOGLEVEL_ERROR < dwErrorLevel)
  201. {
  202. AssertSz(0,"Invalid ErrorLevel");
  203. return FALSE;
  204. }
  205. // must provide error text
  206. if ( (NULL == lpcErrorText) ||
  207. IsBadStringPtr(lpcErrorText,-1) )
  208. {
  209. AssertSz(0,"Invalid ErrorText");
  210. return FALSE;
  211. }
  212. // Optional to have the LogError information.
  213. __try
  214. {
  215. if (lpSyncLogError)
  216. {
  217. if (lpSyncLogError->cbSize != sizeof(SYNCMGRLOGERRORINFO))
  218. {
  219. AssertSz(0,"Unknown LogError cbSize");
  220. return FALSE;
  221. }
  222. if (IsBadReadPtr(lpSyncLogError,sizeof(SYNCMGRLOGERRORINFO)) )
  223. {
  224. AssertSz(0,"Log Structure Memory Invalid");
  225. return FALSE;
  226. }
  227. if (0 != (lpSyncLogError->mask & ~(SYNCMGRLOGERROR_VALIDMASK)) )
  228. {
  229. AssertSz(0,"Invalid LogError Mask");
  230. return FALSE;
  231. }
  232. if (lpSyncLogError->mask & SYNCMGRLOGERROR_ERRORFLAGS)
  233. {
  234. if (0 != (~(SYNCMGRERRROFLAG_MASK) & lpSyncLogError->dwSyncMgrErrorFlags))
  235. {
  236. AssertSz(0,"Invalid LogError ErrorFlags");
  237. return FALSE;
  238. }
  239. }
  240. }
  241. }
  242. __except(EXCEPTION_EXECUTE_HANDLER)
  243. {
  244. AssertSz(0,"Bogus, non-NULL LPSYNCMGRLOGERRORINFO pointer.");
  245. return FALSE;
  246. }
  247. return TRUE;
  248. }