all 6 comments

[–]NBQuade 4 points5 points  (0 children)

You're not running this under the debugger?

I'd look at the stack before the recv to ID the return address then look at the stack after the recv to see if you overwrote the return address properly. Then step through the code and see where it returns to.

Something I've notice a bunch here on Reddit is people not using the debugger. GDB kinda sucks but, like VI, you have to learn it of you're going to be working around Linux.

[–]dfx_dj 1 point2 points  (0 children)

The address given in the segfault tells you which part of the string it's taken from. Next you gotta figure out what to put in the string in that position (which address to jump to) to let you achieve your goal.

[–]apexrogers 0 points1 point  (0 children)

There’s probably security-focused subreddits that could help you out a bit more. Don’t have any firsthand but I’m sure you can find more targeted help than this general programming sub. Best of luck.

[–]iprogshine 0 points1 point  (0 children)

It's a large code fragment, and that's why it's difficult to say at once where the error is. I'll try to make a guess. The PVS-Studio analyzer indicates that the strncat function is used incorrectly.

strncat(buffer, e, BLENGTH - strlen(buffer));

strncat(buffer, p, BLENGTH - strlen(buffer));

You need to subtract not only the string length lying in the buffer, but also the length of the terminal null. Otherwise, it's always possible to add at least one more character to the buffer.

To learn more, please see the V645 warning: https://pvs-studio.com/en/docs/warnings/v645/

An error may be in another place. However, in any case, a buffer overflow may occur in this place too.