Fix a bug caused by sscanf trashing memory.
authorbbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 25 May 2006 18:18:27 +0000 (18:18 +0000)
committerbbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 25 May 2006 18:18:27 +0000 (18:18 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@280 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/TianoTools/GenDepex/GenDepex.c

index 2a65e08..608e27e 100644 (file)
@@ -690,21 +690,33 @@ Returns:
         Ptrx++;\r
       }\r
 \r
-      ArgCountParsed = sscanf (\r
-                        Ptrx,\r
-                                               "%x, %x, %x, { %x, %x, %x, %x, %x, %x, %x, %x }",\r
-                        &Guid.Data1,\r
-                        &Guid.Data2,\r
-                        &Guid.Data3,\r
-                        &Guid.Data4[0],\r
-                        &Guid.Data4[1],\r
-                        &Guid.Data4[2],\r
-                        &Guid.Data4[3],\r
-                        &Guid.Data4[4],\r
-                        &Guid.Data4[5],\r
-                        &Guid.Data4[6],\r
-                        &Guid.Data4[7]\r
-                        );\r
+      {\r
+        int byte_index;\r
+        // This is an array of UINT32s. sscanf will trash memory\r
+        // if you try to read into a UINT8 with a %x formatter.\r
+        UINT32 Guid_Data4[8];\r
+\r
+        ArgCountParsed = sscanf (\r
+                         Ptrx,\r
+            "%x, %x, %x, { %x, %x, %x, %x, %x, %x, %x, %x }",\r
+                         &Guid.Data1,\r
+                         &Guid.Data2,\r
+                         &Guid.Data3,\r
+                         &Guid_Data4[0],\r
+                         &Guid_Data4[1],\r
+                         &Guid_Data4[2],\r
+                         &Guid_Data4[3],\r
+                         &Guid_Data4[4],\r
+                         &Guid_Data4[5],\r
+                         &Guid_Data4[6],\r
+                         &Guid_Data4[7]\r
+                         );\r
+        \r
+        // Now we can copy the 32 bit ints into the GUID.\r
+        for (byte_index=0; byte_index<8; byte_index++) {\r
+          Guid.Data4[byte_index] = (UINT8) Guid_Data4[byte_index];\r
+        }\r
+      }\r
 \r
       if (ArgCountParsed != 11) {\r
         printf ("We have found an illegal GUID\n");\r