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.

122 lines
2.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. CorrectACMArgs.cpp
  5. Abstract:
  6. This shim is to fix apps that pass incorrect cbSrcLength(too big) in the
  7. ACMSTREAMHEADER parameter to acmStreamConvert or acmStreamPrepareHeader.
  8. Notes:
  9. This is a general purpose shim.
  10. History:
  11. 10/03/2000 maonis Created
  12. --*/
  13. #include "precomp.h"
  14. #include "msacmdrv.h"
  15. typedef MMRESULT (*_pfn_acmStreamConvert)(HACMSTREAM has, LPACMSTREAMHEADER pash, DWORD fdwConvert);
  16. typedef MMRESULT (*_pfn_acmStreamPrepareHeader)(HACMSTREAM has, LPACMSTREAMHEADER pash, DWORD fdwPrepare);
  17. IMPLEMENT_SHIM_BEGIN(CorrectACMArgs)
  18. #include "ShimHookMacro.h"
  19. APIHOOK_ENUM_BEGIN
  20. APIHOOK_ENUM_ENTRY(acmStreamConvert)
  21. APIHOOK_ENUM_ENTRY(acmStreamPrepareHeader)
  22. APIHOOK_ENUM_END
  23. /*++
  24. On win9x it checks to ensure that the app doesn't pass in a too big cbSrcLength
  25. but this check is removed on NT. We fix this by mimicing what 9x is doing -
  26. calling acmStreamSize to check if the source length is too big.
  27. --*/
  28. MMRESULT
  29. APIHOOK(acmStreamConvert)(
  30. HACMSTREAM has,
  31. LPACMSTREAMHEADER pash,
  32. DWORD fdwConvert
  33. )
  34. {
  35. DWORD dwOutputBytes = 0;
  36. MMRESULT mmr = acmStreamSize(
  37. has, pash->cbDstLength, &dwOutputBytes, ACM_STREAMSIZEF_DESTINATION);
  38. if (mmr == MMSYSERR_NOERROR)
  39. {
  40. if(pash->cbSrcLength > dwOutputBytes)
  41. {
  42. DPFN( eDbgLevelWarning, "acmStreamConvert: cbSrcLength is too big (cbSrcLength=%u, cbDstLength=%u)\n",pash->cbSrcLength,pash->cbDstLength);
  43. return ACMERR_NOTPOSSIBLE;
  44. }
  45. mmr = ORIGINAL_API(acmStreamConvert)(
  46. has, pash, fdwConvert);
  47. }
  48. return mmr;
  49. }
  50. /*++
  51. Fix bad parameters.
  52. --*/
  53. MMRESULT
  54. APIHOOK(acmStreamPrepareHeader)(
  55. HACMSTREAM has,
  56. LPACMSTREAMHEADER pash,
  57. DWORD fdwPrepare
  58. )
  59. {
  60. UINT l = pash->cbSrcLength;
  61. while (IsBadReadPtr(pash->pbSrc, l))
  62. {
  63. if (l < 256)
  64. {
  65. DPFN( eDbgLevelError, "The source buffer is invalid");
  66. return MMSYSERR_INVALPARAM;
  67. }
  68. l-=256;
  69. }
  70. if (pash->cbSrcLength != l)
  71. {
  72. DPFN( eDbgLevelWarning, "Adjusted header from %d to %d\n", pash->cbSrcLength, l);
  73. }
  74. pash->cbSrcLength = l;
  75. return ORIGINAL_API(acmStreamPrepareHeader)(
  76. has, pash, fdwPrepare);
  77. }
  78. /*++
  79. Register hooked functions
  80. --*/
  81. HOOK_BEGIN
  82. APIHOOK_ENTRY(MSACM32.DLL, acmStreamConvert)
  83. APIHOOK_ENTRY(MSACM32.DLL, acmStreamPrepareHeader)
  84. HOOK_END
  85. IMPLEMENT_SHIM_END