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.

61 lines
1.5 KiB

  1. #include <stdlib.h>
  2. #include <spbase.h>
  3. #include <wincrypt.h>
  4. SP_STATUS SPAllocOutMem(DWORD cbMessage, PSPBuffer pCommOutput)
  5. {
  6. SP_BEGIN("SPAllocOutMem");
  7. pCommOutput->cbData = cbMessage;
  8. DebugLog((DEB_TRACE, "Output buffer size %x\n", cbMessage));
  9. /* are we allocating our own memory? */
  10. if(pCommOutput->pvBuffer == NULL)
  11. {
  12. pCommOutput->pvBuffer = SPExternalAlloc(pCommOutput->cbData);
  13. if (NULL == pCommOutput->pvBuffer)
  14. {
  15. SP_RETURN(SP_LOG_RESULT(SEC_E_INSUFFICIENT_MEMORY));
  16. }
  17. pCommOutput->cbBuffer = pCommOutput->cbData;
  18. }
  19. if(pCommOutput->cbData > pCommOutput->cbBuffer)
  20. {
  21. // Required buffer size returned in pCommOutput->cbData.
  22. SP_RETURN(PCT_INT_BUFF_TOO_SMALL);
  23. }
  24. SP_RETURN(PCT_ERR_OK);
  25. }
  26. //Make sure that we have cbMessage in the buffer, if not allocate,
  27. //if more leave it alone
  28. SP_STATUS SPAllocOutMemChk(DWORD cbMessage, PSPBuffer pOut)
  29. {
  30. SP_STATUS pctRet = PCT_ERR_OK;
  31. if(pOut->cbBuffer < cbMessage)
  32. {
  33. SPBuffer spbufT;
  34. spbufT.cbData = spbufT.cbBuffer = 0;
  35. spbufT.pvBuffer = NULL;
  36. pctRet = SPAllocOutMem(cbMessage, &spbufT);
  37. if(PCT_ERR_OK == pctRet)
  38. {
  39. CopyMemory((PBYTE)spbufT.pvBuffer, (PBYTE)pOut->pvBuffer, pOut->cbData);
  40. SPExternalFree(pOut->pvBuffer);
  41. pOut->pvBuffer = spbufT.pvBuffer;
  42. pOut->cbBuffer = cbMessage;
  43. }
  44. }
  45. return(pctRet);
  46. }