Add pointer check for NULL before dereference it.
[mirror_edk2.git] / SecurityPkg / VariableAuthenticated / RuntimeDxe / Variable.c
index df8b30a63e5f004c56de81495773bd1f3b2d0acf..0846b2a21b83778d2499354a5c826ef9947ffaeb 100644 (file)
@@ -1591,12 +1591,11 @@ UpdateVariable (
   NextVariable->MonotonicCount  = MonotonicCount;\r
   SetMem (&NextVariable->TimeStamp, sizeof (EFI_TIME), 0);\r
 \r
-  if (((Attributes & EFI_VARIABLE_APPEND_WRITE) == 0) && \r
-      ((Attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) != 0)) {\r
-    CopyMem (&NextVariable->TimeStamp, TimeStamp, sizeof (EFI_TIME));\r
-  } else if (\r
-      ((Attributes & EFI_VARIABLE_APPEND_WRITE) != 0) && \r
-      ((Attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) != 0)) {\r
+  if (((Attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) != 0) &&\r
+        TimeStamp != NULL) {\r
+    if ((Attributes & EFI_VARIABLE_APPEND_WRITE) == 0) {\r
+      CopyMem (&NextVariable->TimeStamp, TimeStamp, sizeof (EFI_TIME));\r
+    } else {\r
       //\r
       // In the case when the EFI_VARIABLE_APPEND_WRITE attribute is set, only\r
       // when the new TimeStamp value is later than the current timestamp associated\r
@@ -1605,6 +1604,7 @@ UpdateVariable (
       if (CompareTimeStamp (&Variable->CurrPtr->TimeStamp, TimeStamp)) {\r
         CopyMem (&NextVariable->TimeStamp, TimeStamp, sizeof (EFI_TIME));\r
       }\r
+    }\r
   }\r
 \r
   //\r