Segfault in magic_check

Brett Funderburg brettf at deepfile.com
Wed Oct 8 11:09:33 EDT 2003


Maybe some of these apis aren't quite finised yet but the following:

m = magic_open(MAGIC_NONE)
magic_load(m, NULL)
magic_check(m, NULL)

causes a segfault.

According to libmagic(3) passing NULL as the filename pointer to
magic_check should cause the default database to be checked but it doesn't
look like the code in apprentice.c/file_apprentice is set up to handle
this.

Backtrace looks like this:

#0  0x4207a703 in strlen () from /lib/tls/libc.so.6
#1  0x4207a445 in strdup () from /lib/tls/libc.so.6
#2  0x40417636 in file_apprentice (ms=0x8185218, fn=0x0, action=1)
    at apprentice.c:204
#3  0x404170be in magic_check (ms=0x0, magicfile=0x0) at magic.c:188
#4  0x4001d2b7 in py_magic_check (self=0x0, args=0x4011d02c) at
py_magic.c:172
...python call stack omitted...

As a point of reference, this works fine:

m = magic_open(MAGIC_NONE)
magic_load(m, NULL)
magic_file(m, "/path/to/some/file")

and so does this:

m = magic_open(MAGIC_NONE)
magic_load(m, NULL)
magic_buffer(m, some_data_buffer, buffer_size)

brett



More information about the File mailing list