duangang4001 2019-07-31 01:40
浏览 107

如何修复PHP扩展中的“分段错误”错误

I configure php-7.1.0 with --enable-debug. But my extension can't get string param.Now it's "Segmentation fault",and it didn't occur without --enable-debug.

Is this a php problem or a problem with my code?

I've tried to use gdb to debug. It occurred in function “zend_parse_parameters”. And it's normal before running to the end of the function “zend_parse_arg_string”. The pointer of string was redirect to .

PHP_FUNCTION(sigTKeyEncrypt)
{
    array_init(return_value);
    const unsigned char *pInBuf = NULL;
    int nInBufLen, pOutBufLen;
    char pOutBuf[BUF_LEN] = { 0 };
    pOutBufLen = sizeof(pOutBuf);
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &pInBuf, &nInBufLen) == FAILURE) {
        php_printf("zend_parse_parameters failed!
");
        add_assoc_long(return_value, "r", 99);
        return;
    }
    php_printf("buf:%s, bufLen:%d
", pInBuf, nInBufLen);

    OicqEncrypt(300, pInBuf, nInBufLen, (const BYTE*)SIG_TENCENT_KEY, (unsigned char*)pOutBuf, &pOutBufLen);

    add_assoc_long(return_value, "r", 0);
    add_assoc_stringl(return_value, "data", pOutBuf, pOutBufLen);
}

I expect the function “zend_parse_parameters” can read the string correctly with configure --enable-debug.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大