当前位置: 技术问答>linux和unix
linux连接mysql出现stack smashing detected错误
来源: 互联网 发布时间:2017-01-15
本文导语: 各位大侠:小弟写了一个程序,来测试连接mysql。程序运行到最后出现stack smashing detected。我用gdb调试到最后一行return 0时还是对了,再调试下去就出现错误了。 代码: #include #include #include #include #include "mysql...
各位大侠:小弟写了一个程序,来测试连接mysql。程序运行到最后出现stack smashing detected。我用gdb调试到最后一行return 0时还是对了,再调试下去就出现错误了。
代码:
#include
#include
#include
#include
#include "mysql_h/mysql.h"
int main()
{
//export CFLAGS="-fno-stack-protector";
MYSQL* m_pConnection;
char * ch = "192.168.94.130";
char CError[50];
mysql_init(m_pConnection);
if (!m_pConnection) {
printf("connect error");
return 1;
}
if (!mysql_real_connect(m_pConnection, ch, "Ret_Ser", "androidser","Android", 3306, NULL, 0))
{
printf("connect error: ");
return 1;
}
mysql_close(m_pConnection); // release resource
return 0;
}
错误:*** stack smashing detected ***: terminated
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x48)[0xb7c4c238]
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x0)[0xb7c4c1f0]
[0x80485e8]
[0x0]
======= Memory map: ========
08048000-08049000 r-xp 00000000 08:01 4917807 /home/smrdn/C_Program/mysql/slq
08049000-0804a000 rw-p 00000000 08:01 4917807 /home/smrdn/C_Program/mysql/slq
0804a000-0806b000 rw-p 0804a000 00:00 0 [heap]
代码:
#include
#include
#include
#include
#include "mysql_h/mysql.h"
int main()
{
//export CFLAGS="-fno-stack-protector";
MYSQL* m_pConnection;
char * ch = "192.168.94.130";
char CError[50];
mysql_init(m_pConnection);
if (!m_pConnection) {
printf("connect error");
return 1;
}
if (!mysql_real_connect(m_pConnection, ch, "Ret_Ser", "androidser","Android", 3306, NULL, 0))
{
printf("connect error: ");
return 1;
}
mysql_close(m_pConnection); // release resource
return 0;
}
错误:*** stack smashing detected ***: terminated
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x48)[0xb7c4c238]
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x0)[0xb7c4c1f0]
[0x80485e8]
[0x0]
======= Memory map: ========
08048000-08049000 r-xp 00000000 08:01 4917807 /home/smrdn/C_Program/mysql/slq
08049000-0804a000 rw-p 00000000 08:01 4917807 /home/smrdn/C_Program/mysql/slq
0804a000-0806b000 rw-p 0804a000 00:00 0 [heap]
|
这样呢?
MYSQL* m_pConnection=mysql_init(NULL);
MYSQL* m_pConnection=mysql_init(NULL);
|
使用C API操作mysql数据库
http://blog.csdn.net/lyjinger/archive/2007/06/12/1648898.aspx
http://blog.csdn.net/lyjinger/archive/2007/06/12/1648898.aspx