Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check size of returned str #4

Open
paulpach opened this issue Jun 15, 2017 · 0 comments
Open

check size of returned str #4

paulpach opened this issue Jun 15, 2017 · 0 comments

Comments

@paulpach
Copy link

paulpach commented Jun 15, 2017

This kind of code could lead to buffer overflow:

    recv(_clt_sock_fd, buf, 1024, 0);
    
    std::cout << buf << std::endl;
    
    if (strcmp(buf, "Hello from svr!") == 0) {

there is no guarantee that recv will null terminate buf, so strcmp could read past the end of the array.

recv returns how many bytes it returns, use that value for strncmp. the cout << buf is also problematic. You need to check the result of recv before doing either operation.

I don't know if you are avoiding using libraries, but boost has a nice c++ abstraction for sockets, which would be much more readable and help you avoid these type of things.

Since you are writing a server, this kind of bugs in the server could easily turn into a security vulnerability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant