Sync patch r14325 from main trunk.
1. Fix TOCTOU issue in VariableSmm, FtwSmm, FpdtSmm, SmmCorePerformance SMM handler. For VariableSmm, pre-allocate a mVariableBufferPayload buffer with mVariableBufferPayloadSize(match with mVariableBufferPayloadSize in VariableSmmRuntimeDxe) to hold communicate buffer payload to avoid TOCTOU issue.
2. Add check to ensure CommBufferPayloadSize not exceed mVariableBufferPayloadSize or is enough to hold function structure in VariableSmm and FtwSmm.
3. Align FtwGetLastWrite() in FaultTolerantWriteSmmDxe.c to FtwGetLastWrite() in FaultTolerantWrite.c.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/branches/UDK2010.SR1@14329 6f19259b-4bc3-4df7-8a09-765794883524
Sync patches r13208, r13473, r13563, r13638, r13642, r13647, r13650 and r13656 from main trunk.
1. MdeModulePkg PiSmmCore: Fix a bug in SmmLoadImage() in PiSmmCore that in-correct status codes may be returned.
2. Check whether has storage for date/time opcode, if it has storage, also generate the offset/width info for it.
3. Close the corresponding GUIDed section extraction protocol notify event in CloseSectionStream.
4. Fix incorrect sizeof () usage.
5. Add missing break and add comment to non-necessary break.
6. IntelFrameworkModulePkg/IdeBusDxe: Add error check on the return status of invoking AtaSoftReset().
7. Enhance the code to make the code logic more clear.
8. Initialize the variable before use it.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/branches/UDK2010.SR1@14330 6f19259b-4bc3-4df7-8a09-765794883524
Sync patches r13691, r13703, r13704, r13909, r13957, r14039, r14079, r14082, r14115, r14165, r14256, r14259, r14294 adn r14296 from main trunk.
1. Should pass in bytes of string buffer to UnicodeSPrint() rather than Unicode string length.
2. Check the return code from CoreLocateDevicePath() in MdeModulePkg/Core/Dxe/Image/Image.c CoreLoadImageCommon().
3. Fix the memory leak issue and enhance the check for CoreReadImageFile return.
4. MdeModulePkg: eliminate all implicit library dependencies for all modules in MdeModulePkg on PcdLib.
5. SecurityPkg update:
   a. Correct the counter-based hash algorithm according to UEFI spec.
   b. Check the reserverd bit in variable attribute.
   c. Return EFI_OUT_OF_RESOURCE instead of EFI_SECURITY_VIOLATION if there
      is not enough speace to store the public key.
   d. Fix a bug when deleting a non-existent time-based auth variable, we
      store the certificate into cert DB incorrectly.
   e. Fix a bug that time-based auth variable can't been updated again after
      append operation.
6. Fix several RFC compliance issues in DHCP6 driver as below.
   a. Client must ignore any Advertise message that includes a Status
      Code option containing the value NoAddrsAvail.
   b. The elapsed-time should start from the current DHCP transaction.
   c. Client should not change any information about addresses the client
      has recorded in the IA but not included in the IA from the server.
   d. Client need to update to handle the error status code
      UnspecFail/UseMulticast/NotOnLink/NoBinding in the Reply message
      from server.
   e. When the client receives a Reply message in response to a 
      Renew/ Rebind message, the client examines each IA independently.
      For each IA in the original Renew/ Rebind message, the client sends
      a Renew/ Rebind if the IA is not in the Reply message.
   f. Client should uses network byte order in IANA T1/T2 option 7.
      Client should discard any addresses for which the preferred lifetime
      is greater than the valid lifetime.
7. Fix infinite loop bug in secure boot UI driver.
8. Fix a bug in snp driver binding Start() that it may return incorrect status code.
9. Fix a bug that IsSignatureFoundInDatabase() incorrectly computes CertCount.
10.Fix several bugs in the implementation of converting SAS/SASEX device path node from/to text.
11.Add transit bit check for detecting partial response in iSCSI stack.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/branches/UDK2010.SR1@14331 6f19259b-4bc3-4df7-8a09-765794883524
Sync patches r13975, r14029, r14041, r14065, r14084, r14086 and r14139 from main trunk.
1. Move the declaration of gEfiCertDbGuid to the package's Include folder.
2. Don't assume that flush the HOB variable to flash must be successful.
3. When no DELETED variable found, no variable space could be reclaimed, so just give some debug info and return EFI_SUCCESS.
4. Fix a bug that the invalid public key will never be removed from public key database.
5. a. Update the logic of UpdateVariable() for updating variable from:
        set old variable to IN_DELETED_TRANSITION -> check if reclaim is needed(If yes, do reclaim) -> add new variable -> set old variable to DELETED if no reclaim happened.
      to:
        set old variable to IN_DELETED_TRANSITION -> check if reclaim is needed(If yes, do reclaim) -> add new variable -> set old variable to DELETED.
    b. Update UpdateVariable() to correctly handle the case "both ADDED and IN_DELETED_TRANSITION variable are present", and delete both old ADDED and
       IN_DELETED_TRANSITION variable when deleting or updating variable.
    c. Update VariableServiceGetNextVariableName() to return the valid IN_DELETED_TRANSITION variable if only IN_DELETED_TRANSITION variable is present.
6. Check for NULL pointer before dereference it.
7. Add error handling code to prevent variable store corruption in release build.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/branches/UDK2010.SR1@14333 6f19259b-4bc3-4df7-8a09-765794883524