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

Buffer overflow in client_error #9

Open
nezza opened this issue Jul 25, 2014 · 4 comments
Open

Buffer overflow in client_error #9

nezza opened this issue Jul 25, 2014 · 4 comments

Comments

@nezza
Copy link

nezza commented Jul 25, 2014

After having a quick look at the code I think you should put a big warning on the README that this code is not at all ready for anything that listens on a public port. Besides the stack overflow that was already reported by MagicalTux there's also this code which will cause a bufferoverflow if msg & longmsg are too long:

void client_error(int fd, int status, char *msg, char *longmsg){
    char buf[MAXLINE];
    sprintf(buf, "HTTP/1.1 %d %s\r\n", status, msg);
    sprintf(buf + strlen(buf),
            "Content-length: %lu\r\n\r\n", strlen(longmsg));
    sprintf(buf + strlen(buf), "%s", longmsg);
    writen(fd, buf, strlen(buf));
}

Pretty sure this is not the only problem remaining.

@nezza nezza changed the title Dangerous use of sprintf, strcpy & strncpy. Buffer overflow in client_error Jul 25, 2014
@MagicalTux
Copy link
Contributor

Should be using nprintf()

MagicalTux pushed a commit to MagicalTux/nope.c that referenced this issue Jul 25, 2014
@nezza
Copy link
Author

nezza commented Jul 25, 2014

And how is nprintf more secure?

@MagicalTux
Copy link
Contributor

nprintf() dynamically allocates buffer space to fit the whole string and will not overflow the buffer.

@nezza
Copy link
Author

nezza commented Jul 26, 2014

nprintf() NOW dynamically allocates buffer space. As you know. Because you fixed it. #14

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

2 participants