Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 163948 - sys-apps/file-4.18 doesn't NULLify file in struct magic_set
Summary: sys-apps/file-4.18 doesn't NULLify file in struct magic_set
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High major (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-26 18:17 UTC by Jeff Hansen
Modified: 2007-02-07 04:50 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff Hansen 2007-01-26 18:17:09 UTC
When a new struct magic_set is created as the handle to the calling application (in magic_open), the "file" char * is not NULLified.  This causes unexplained segfaults in other apps that don't properly have their magic.mgc file created, i.e. in app-arch/rpm-4.4.6-r3.  The file pointer is some random value, so when file_magwarn tries to report a missing magic.mgc file, for example, it tries to print ms->file, which is NULL, and the segfault occurs.

I have submitted a patch that fixes the problem and allows file to properly tell the user that they are missing a magic.mgc file, instead of just crashing outright.  We could also just bzero the struct magic_set after it is malloc'ed.


Reproducible: Always

Steps to Reproduce:
1. Try to build an rpm using rpmbuild with the current portage tree.  It segfaults with no explanation.
2. Or just try to use any app that uses magic_open on an unexisting magic.mgc file, it will segfault.

Hopefully you won't need to reproduce the problem, though.  It's just bad practice in file's "magic.c" source code to not initialize the pointer properly, and then expect it to be set when an error occurs.




--- src/magic.c.orig	2007-01-26 11:00:41.310878002 -0700
+++ src/magic.c	2007-01-26 10:42:51.569916935 -0700
@@ -110,6 +110,7 @@
 	ms->haderr = 0;
 	ms->error = -1;
 	ms->mlist = NULL;
+	ms->file = NULL;
 	return ms;
 free3:
 	free(ms->o.pbuf);
Comment 1 SpanKY gentoo-dev 2007-02-07 04:50:17 UTC
looks sane to me ... added to 4.19-r1 and mailed upstream, cheers