I write code to read and open myapp configuration from xml file. Code attempt to parse the file for key elements and create them if they don't exist:
static xmlDocPtr configsave_open( const char *config_filename )
{
xmlDocPtr doc;
xmlNodePtr top;
int create_file = 0;
doc = xmlParseFile( config_filename );
......................................
xmlKeepBlanksDefault( 0 );
if( create_file ) {
char *temp = strdup( config_filename ); /* <-- crashed with SIGSEGV in __GI___strdup() */
if( ! temp ) {
fprintf( stderr, "strdup failed for config_filename %s\n", config_filename );
xmlFreeDoc( doc );
return 0;
}
mkdir_and_force_owner( dirname( temp ), getuid(), getgid() );
free( temp );
}
......................................
return doc;
}
I write testcase:
#!/bin/bash
# seed id: 16154
DIR="$( cd "$( dirname "$0" )" && pwd )"
GDB=
if [ "$1" = "-g" ]
then
GDB="gdb --args"
fi
env -i \
MALLOC_CHECK_=0 \
$GDB \
/usr/bin/myapp \
"`cat $DIR/argv_1.symb`" \
"`cat $DIR/argv_2.symb`" \
\
< "$DIR/file___dev__stdin.symb"
exit_code=$?
exit $exit_code
where argv_2.symb file containe:
'`
and file__dev_stdin.symb containe:
AAAAAAAAAAAAAAAAAAAAAAAA
crash output:
I/O warning : failed to load external entity "NULL"
./exploit.sh: line 19: 7175 Segmentation fault
(core dumped)
env -i MALLOC_CHECK_=0 $GDB /usr/bin/myapp "`cat $DIR/argv_1.symb`" "`cat $DIR/argv_2.symb`" < "$DIR/file___dev__stdin.symb"
basic crash when try to run myapp with configfile args:
/usr/bin/myapp --configfile '`
Any help to solve this are welcome
I believe that
config_filename
might beNULL
here, especially considering this message:If that is not the case, we probably need more context.