On 04/15/2015 06:52 PM, Pino Toscano wrote:
On Wednesday 15 April 2015 18:35:29 Maros Zatko wrote:
---
  src/filearch.c | 16 ++++++++++++----
  1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/filearch.c b/src/filearch.c
index df65c98..2016115 100644
--- a/src/filearch.c
+++ b/src/filearch.c
@@ -59,8 +59,9 @@ cleanup_magic_t_free (void *ptr)
  # endif
COMPILE_REGEXP (re_file_elf,
-                "ELF.*(?:executable|shared object|relocatable), (.+?),", 0)
-COMPILE_REGEXP (re_elf_ppc64, "64.*PowerPC", 0)
+                "ELF.*(MSB|LSB).*(?:executable|shared object|relocatable), 
(.+?),", 0)
Note that re_file_elf is used in magic_for_file too, which will break
with this change (as it has not been adapted).
What about just adapting magic_for_file?

+COMPILE_REGEXP (re_elf_ppc64, "MSB.*64.*PowerPC", 0)
+COMPILE_REGEXP (re_elf_ppc64le, "LSB.*64.*PowerPC", 0)
Maybe they still can be one regex, like "(LSB|MSB).*64.*PowerPC",
checking either LSB or MSB as first capture.
Normally they cant, LSB|MSB info is stripped by re_file_elf.
  /* Convert output from 'file' command on ELF files to the canonical
   * architecture string.  Caller must free the result.
@@ -87,6 +88,8 @@ canonical_elf_arch (guestfs_h *g, const char *elf_arch)
      r = "ia64";
    else if (match (g, elf_arch, re_elf_ppc64))
      r = "ppc64";
+  else if (match (g, elf_arch, re_elf_ppc64le))
+    r = "ppc64le";
    else if (strstr (elf_arch, "PowerPC"))
      r = "ppc";
    else if (strstr (elf_arch, "ARM aarch64"))
@@ -315,6 +318,7 @@ guestfs_impl_file_architecture (guestfs_h *g, const char 
*path)
  {
    CLEANUP_FREE char *file = NULL;
    CLEANUP_FREE char *elf_arch = NULL;
+  CLEANUP_FREE char *endianness = NULL;
    char *ret = NULL;
/* Get the output of the "file" command. Note that because this
@@ -324,8 +328,12 @@ guestfs_impl_file_architecture (guestfs_h *g, const char 
*path)
    if (file == NULL)
      return NULL;
- if ((elf_arch = match1 (g, file, re_file_elf)) != NULL)
-    ret = canonical_elf_arch (g, elf_arch);
+  if ((match2 (g, file, re_file_elf, &endianness, &elf_arch)) != 0) {
+    size_t sz = strlen(elf_arch) + strlen(endianness) + 2;
+    CLEANUP_FREE char *end_elf_arch = safe_malloc(g, sz);
+    snprintf(end_elf_arch, sz, "%s %s", endianness, elf_arch);
+    ret = canonical_elf_arch (g, end_elf_arch);
Please use guestfs_int_safe_asprintf instead of malloc + snprintf.

If the idea is to pass "MSB" or "LSB" to canonical_elf_arch, then I'd
say to pass the result of (MSB|LSB) capture to that function (also from
magic_for_file) as separate parameter, checking it only when needed.
This should also require no change to re_elf_ppc64.
Thanks, I thought of this variant too.

Thanks,

_______________________________________________
Libguestfs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libguestfs

Reply via email to