这是我的bat文件
gcc -c ./shared/108/io.c -o io-1.o 2>>error-1.txt
gcc -I ./shared/108 -c ./000/082/975/CWE190_Integer_Overflow__int_connect_socket_add_02.c -o io-2.o 2>>error-2.txt
gcc -I ./shared/108 -g io-2.o io-1.o 2>>error-3.txt
第一步和第二步都没有出错,第三步就报错:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
也求教了很多人,有人问我是不是根本就没有写main()函数,这也就尴尬了,我真的写了,怎么就找不到。
c源文件,部分代码如下:
/* Below is the main(). It is only used when building this testcase on
its own for testing or for building a binary to use in testing binary
analysis tools. It is not used when compiling all the testcases as one
application, which is how source code analysis tools are tested. */
#ifdef INCLUDEMAIN
main(int argc, char * argv[])
{
/* seed randomness */
srand( (unsigned)time(NULL) );
#ifndef OMITGOOD
printLine("Calling good()...");
CWE190_Integer_Overflow__int_connect_socket_add_02_good();
printLine("Finished good()");
#endif /* OMITGOOD */
#ifndef OMITBAD
printLine("Calling bad()...");
CWE190_Integer_Overflow__int_connect_socket_add_02_bad();
printLine("Finished bad()");
#endif /* OMITBAD */
}
#endif
接下来怀疑是返回值的问题,又添加了返回类型,有查过引用的标准库,最后运用的控制变量法,发现了问题
是宏定义出了错误
#ifdef INCLUDEMAIN
......
#endif
#ifdef 语句1
语句2
#endif
这种语句的意思是如果存在宏定义了语句1则执行语句2,它的作用是可以用它区隔一些与特定头文件、程序库和其他文件版本有关的代码。
这代码是用于测试使用的,我看不出开发者的用意,就是验证是否存在INCLUDEMAIN这个宏定义,我也查找过了,不存在这个定义,所以自然不执行语句2,也就找不到main函数入口了,删除这条语句,走起~一切ok。
main(int argc, char * argv[])
{
/* seed randomness */
srand( (unsigned)time(NULL) );
#ifndef OMITGOOD
printLine("Calling good()...");
CWE190_Integer_Overflow__int_connect_socket_add_02_good();
printLine("Finished good()");
#endif /* OMITGOOD */
#ifndef OMITBAD
printLine("Calling bad()...");
CWE190_Integer_Overflow__int_connect_socket_add_02_bad();
printLine("Finished bad()");
#endif /* OMITBAD */
}
得到正常运行结果: