Sophie

Sophie

distrib > Mageia > 3 > i586 > by-pkgid > 13e85e8a723f0fdcda512f01195c8d5d > files > 14

file-5.12-8.8.mga3.src.rpm

Edited to remove RCSID

From b8bdbebce8a6b7b90d2c668413f21b3a1a699ad3 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Fri, 4 Jan 2013 16:37:54 +0000
Subject: [PATCH] Need to pass the returnval that the child match determined
 in the use case. This broke the elf mime printing, where
 softmagic returned a non-match although the child match()
 actually printed something.

---
 src/softmagic.c |   38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/src/softmagic.c b/src/softmagic.c
index a85333c..6dd62c4 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -43,9 +43,9 @@
 
 
 private int match(struct magic_set *, struct magic *, uint32_t,
-    const unsigned char *, size_t, size_t, int, int, int);
+    const unsigned char *, size_t, size_t, int, int, int, int *);
 private int mget(struct magic_set *, const unsigned char *,
-    struct magic *, size_t, size_t, unsigned int, int, int, int);
+    struct magic *, size_t, size_t, unsigned int, int, int, int, int *);
 private int magiccheck(struct magic_set *, struct magic *);
 private int32_t mprint(struct magic_set *, struct magic *);
 private int32_t moffset(struct magic_set *, struct magic *);
@@ -73,7 +73,7 @@ private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
 	int rv;
 	for (ml = ms->mlist[0]->next; ml != ms->mlist[0]; ml = ml->next)
 		if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, 0, mode,
-		    text, 0)) != 0)
+		    text, 0, NULL)) != 0)
 			return rv;
 
 	return 0;
@@ -109,16 +109,19 @@ private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
 private int
 match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
     const unsigned char *s, size_t nbytes, size_t offset, int mode, int text,
-    int flip)
+    int flip, int *returnval)
 {
 	uint32_t magindex = 0;
 	unsigned int cont_level = 0;
 	int need_separator = 0;
-	int returnval = 0, e; /* if a match is found it is set to 1*/
+	int returnvalv = 0, e; /* if a match is found it is set to 1*/
 	int firstline = 1; /* a flag to print X\n  X\n- X */
 	int printed_something = 0;
 	int print = (ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0;
 
+	if (returnval == NULL)
+		returnval = &returnvalv;
+
 	if (file_check_mem(ms, cont_level) == -1)
 		return -1;
 
@@ -144,7 +147,7 @@ private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
 
 		/* if main entry matches, print it... */
 		switch (mget(ms, s, m, nbytes, offset, cont_level, mode, text,
-		    flip)) {
+		    flip, returnval)) {
 		case -1:
 			return -1;
 		case 0:
@@ -152,7 +155,7 @@ private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
 			break;
 		default:
 			if (m->type == FILE_INDIRECT)
-				returnval = 1;
+				*returnval = 1;
 
 			switch (magiccheck(ms, m)) {
 			case -1:
@@ -178,6 +181,7 @@ private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
 		}
 
 		if ((e = handle_annotation(ms, m)) != 0) {
+			*returnval = 1;
 			return e;
 		}
 		/*
@@ -229,7 +233,7 @@ private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
 			}
 #endif
 			switch (mget(ms, s, m, nbytes, offset, cont_level, mode,
-			    text, flip)) {
+			    text, flip, returnval)) {
 			case -1:
 				return -1;
 			case 0:
@@ -239,7 +243,7 @@ private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
 				break;
 			default:
 				if (m->type == FILE_INDIRECT)
-					returnval = 1;
+					*returnval = 1;
 				flush = 0;
 				break;
 			}
@@ -262,8 +266,10 @@ private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
 					ms->c.li[cont_level].got_match = 0;
 					break;
 				}
-				if ((e = handle_annotation(ms, m)) != 0)
+				if ((e = handle_annotation(ms, m)) != 0) {
+					*returnval = 1;
 					return e;
+				}
 				/*
 				 * If we are going to print something,
 				 * make sure that we have a separator first.
@@ -312,13 +318,13 @@ private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
 		if (printed_something) {
 			firstline = 0;
 			if (print)
-				returnval = 1;
+				*returnval = 1;
 		}
 		if ((ms->flags & MAGIC_CONTINUE) == 0 && printed_something) {
-			return returnval; /* don't keep searching */
+			return *returnval; /* don't keep searching */
 		}
 	}
-	return returnval;  /* This is hit if -k is set or there is no match */
+	return *returnval;  /* This is hit if -k is set or there is no match */
 }
 
 private int
@@ -1110,7 +1116,7 @@ private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
 private int
 mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
     size_t nbytes, size_t o, unsigned int cont_level, int mode, int text,
-    int flip)
+    int flip, int *returnval)
 {
 	uint32_t offset = ms->offset;
 	uint32_t count = m->str_range;
@@ -1713,7 +1719,7 @@ private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
 			return -1;
 		}
 		return match(ms, ml.magic, ml.nmagic, s, nbytes, offset,
-		    mode, text, flip);
+		    mode, text, flip, returnval);
 
 	case FILE_NAME:
 		if (file_printf(ms, "%s", m->desc) == -1)
-- 
1.7.10