I have a complex c++ code. It's a FastCGI program, using the FastCGI C++ Class library.
When I ask it for a very looooong url, I get:
*** stack smashing detected ***: ./tileserve terminated
Erreur de segmentation
For real life applications, it's not an issue since I never use so long URLs, but this means that anyone could terminate my server... I don't like that.
Is there a tool to find out where this problem appears? How do I use it?
EDIT: SOLVED
I was doing this:
int len;
char uri[200];
len = strlen(request.params[std::string("REQUEST_URI")].c_str());
printf("%d\n", len);
if (len > 200) return 1;
strcpy(uri, request.params[std::string("REQUEST_URI")].c_str());
Looks like 200
was too high for the len
test. It actually fails at 194
.
So instead I did this:
if (len > 190) return 1;
Now, it's fine.
Erreur de segmentation
– Bocciestrcpy
if writing something like a webserver. This is a potential security issue. Instead use something likestrncpy
that makes sure you don't copy too much into the buffer. – Vast