#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: file.c,v 1.155 2014/10/11 15:03:16 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.156 2014/11/27 15:40:36 christos Exp $")
#endif /* lint */
#include "magic.h"
#undef OPT_LONGONLY
{0, 0, NULL, 0}
};
-#define OPTSTRING "bcCde:Ef:F:hiklLm:nNprsvz0"
+#define OPTSTRING "bcCde:Ef:F:hiklLm:nNprR:svz0"
private const struct {
const char *name;
size_t i;
int action = 0, didsomefiles = 0, errflg = 0;
int flags = 0, e = 0;
+ size_t max_recursion = 0;
struct magic_set *magic = NULL;
int longindex;
const char *magicfile = NULL; /* where the magic is */
case 'r':
flags |= MAGIC_RAW;
break;
+ case 'R':
+ max_recursion = atoi(optarg);
+ break;
case 's':
flags |= MAGIC_DEVICES;
break;
strerror(errno));
return 1;
}
+
+
switch(action) {
case FILE_CHECK:
c = magic_check(magic, magicfile);
if (magic == NULL)
if ((magic = load(magicfile, flags)) == NULL)
return 1;
+ if (max_recursion) {
+ if (magic_setparam(magic, MAGIC_PARAM_MAX_RECURSION,
+ &max_recursion) == -1) {
+ (void)fprintf(stderr,
+ "%s: Can't set recurision %s\n", progname,
+ strerror(errno));
+ return 1;
+ }
+ }
break;
}
int magic_version(void);
int magic_load(magic_t, const char *);
-int magic_load_buffers(struct magic_set *, void **, size_t *, size_t);
+int magic_load_buffers(magic_t, void **, size_t *, size_t);
int magic_compile(magic_t, const char *);
int magic_check(magic_t, const char *);
int magic_list(magic_t, const char *);
int magic_errno(magic_t);
+#define MAGIC_PARAM_MAX_RECURSION 0
+int magic_setparam(magic_t, int, const void *);
+int magic_getparam(magic_t, int, void *);
+
#ifdef __cplusplus
};
#endif
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.198 2014/11/23 13:54:27 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.199 2014/11/27 15:40:36 christos Exp $")
#endif /* lint */
#include "magic.h"
#include <time.h>
private int match(struct magic_set *, struct magic *, uint32_t,
- const unsigned char *, size_t, size_t, int, int, int, int, int *, int *,
+ const unsigned char *, size_t, size_t, int, int, int, size_t, int *, int *,
int *);
private int mget(struct magic_set *, const unsigned char *,
- struct magic *, size_t, size_t, unsigned int, int, int, int, int, int *,
+ struct magic *, size_t, size_t, unsigned int, int, int, int, size_t, int *,
int *, int *);
private int magiccheck(struct magic_set *, struct magic *);
private int32_t mprint(struct magic_set *, struct magic *);
#define OFFSET_OOB(n, o, i) ((n) < (o) || (i) > ((n) - (o)))
-#define MAX_RECURSION_LEVEL 10
-
/*
* softmagic - lookup one file in parsed, in-memory copy of database
* Passed the name and FILE * of one file to be typed.
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 recursion_level, int *printed_something, int *need_separator,
- int *returnval)
+ int flip, size_t recursion_level, int *printed_something,
+ int *need_separator, int *returnval)
{
uint32_t magindex = 0;
unsigned int cont_level = 0;
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 recursion_level, int *printed_something,
+ int flip, size_t recursion_level, int *printed_something,
int *need_separator, int *returnval)
{
uint32_t offset = ms->offset;
union VALUETYPE *p = &ms->ms_value;
struct mlist ml;
- if (recursion_level >= MAX_RECURSION_LEVEL) {
- file_error(ms, 0, "recursion nesting exceeded");
+ if (recursion_level >= ms->max_recursion) {
+ file_error(ms, 0, "recursion nesting (%zu) exceeded",
+ recursion_level);
return -1;
}