[115476] trunk/base/src/machista1.0/libmachista.c

jeremyhu at macports.org jeremyhu at macports.org
Thu Jan 2 16:21:35 PST 2014


Revision: 115476
          https://trac.macports.org/changeset/115476
Author:   jeremyhu at macports.org
Date:     2014-01-02 16:21:35 -0800 (Thu, 02 Jan 2014)
Log Message:
-----------
rev-upgrade: Silence invalid "Premature end of data, possibly corrupt file" warnings

It's not an error if fail to load the n+1-th load command when there were only n.

Modified Paths:
--------------
    trunk/base/src/machista1.0/libmachista.c

Modified: trunk/base/src/machista1.0/libmachista.c
===================================================================
--- trunk/base/src/machista1.0/libmachista.c	2014-01-02 23:59:27 UTC (rev 115475)
+++ trunk/base/src/machista1.0/libmachista.c	2014-01-03 00:21:35 UTC (rev 115476)
@@ -339,15 +339,21 @@
     mat->mat_arch = swap32(header->cputype);
 
     /* Parse the Mach-O load commands */
-    const struct load_command *cmd = macho_offset(input, header, header_size, sizeof(struct load_command));
-    if (cmd == NULL)
-        return MACHO_ERANGE;
     uint32_t ncmds = swap32(header->ncmds);
 
+    /* Setup to jump over the header on the first pass through instead of the previous command */
+    const struct load_command *cmd = (void *)header;
+    uint32_t cmdsize = header_size;
+
     /* Iterate over the load commands */
     for (uint32_t i = 0; i < ncmds; i++) {
+        /* Load the next command */
+        cmd = macho_offset(input, cmd, cmdsize, sizeof(struct load_command));
+        if (cmd == NULL)
+            return MACHO_ERANGE;
+
         /* Load the full command */
-        uint32_t cmdsize = swap32(cmd->cmdsize);
+        cmdsize = swap32(cmd->cmdsize);
         cmd = macho_read(input, cmd, cmdsize);
         if (cmd == NULL)
             return MACHO_ERANGE;
@@ -426,11 +432,6 @@
             default:
                 break;
         }
-
-        /* Load the next command */
-        cmd = macho_offset(input, cmd, cmdsize, sizeof(struct load_command));
-        if (cmd == NULL)
-            return MACHO_ERANGE;
     }
 
     return MACHO_SUCCESS;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20140102/cb98bc4f/attachment.html>


More information about the macports-changes mailing list