【问题标题】:crash with SIGSEGV in __GI___strdup()在 __GI___strdup() 中使用 SIGSEGV 崩溃
【发布时间】:2013-08-23 13:58:03
【问题描述】:

我编写代码从 xml 文件读取和打开 myapp 配置。 代码尝试解析文件中的关键元素并在它们不存在时创建它们:

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;
}

我写测试用例:

#!/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

argv_2.symb 文件所在的位置:

'`

和文件__dev_stdin.symb 包含:

AAAAAAAAAAAAAAAAAAAAAAAA

崩溃输出:

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"

尝试使用 configfile args 运行 myapp 时基本崩溃:

/usr/bin/myapp --configfile '`

欢迎任何帮助解决这个问题

【问题讨论】:

    标签: c strdup


    【解决方案1】:

    我相信这里的config_filename 可能是NULL,尤其是考虑到这条消息:

    I/O warning : failed to load external entity "NULL"
    

    如果不是这样,我们可能需要更多上下文。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-28
      • 2011-06-25
      • 1970-01-01
      • 1970-01-01
      • 2012-09-16
      相关资源
      最近更新 更多