1
C++函数,的strtok()cplusplus.com的strtok - 缓冲区溢出
将本实施例中苦于缓冲区溢出如果STR未正确结束?
/* strtok example */
/* source - cplusplus.com (see link below) */
#include <stdio.h>
#include <string.h>
int main()
{
char str[] ="- This, a sample string.";
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str," ,.-");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ,.-"); // walk the stack?
}
return 0;
}
如果STR不以 “\ 0” 正确端接,是不是有可能
pch = strtok (NULL, " ,.-");
走栈?
谢谢!
想到这一点的简单方法是,如果'str'没有正确终止,那么*它不是C风格的字符串*。这只是一些人物。当然,将C字符串以外的任何内容传递给'strtok'都是坏消息。 – 2010-09-02 21:22:15
这是为了一些白帽子黑客? – Chubsdad 2010-09-03 04:39:27