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

Factor out get_wwwroot_parent and test it. #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

emikulic
Copy link
Owner

No description provided.

@emikulic
Copy link
Owner Author

@g-rden what do you think?

Copy link
Contributor

@g-rden g-rden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know you had to "submit" reviews, sorry. Wrote these a day ago.

}

int main(void) {
test("", ".", "");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a case that can't occur in darkhttpd. wwwroot can't be NULL at this point and

path[0] = '.';
path[1] = '\0';

in get_wwwroot_parent() would write to unallocated memory. So this test is not necessary I think.

These tests would be good too I think. Just to cover all bases.

test("x", ".", "x"); // 1 char
test(".dir/file", ".dir/", "/file"); // hidden dir
test(".file", ".", ".file"); // hidden file
test("/file", "/", "/file"); // file in root

static void xchroot(const char *path) {
if (chdir(path) == -1)
err(1, "chdir(%s)", path);
if (chroot(path) == -1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be if (chroot(".") == -1)

This is my bad. I tested with absolute paths, so I didn't notice that we already are in the directory we want to chroot to. I think we can leave path in the error messages.

char* get_wwwroot_parent() {
off_t ofs;
size_t len = strlen(wwwroot) + 1;
if (len == 1) return xstrdup(".");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len can't be 1. It's the length of wwwroot including NULL terminator.
We could remove + 1, but then memmove(wwwroot, &wwwroot[ofs], len + 1 - ofs); could be a bit more confusing.
I don't mind either way.

I am dumb, just do len == 2

Comment on lines +2922 to +2924
char* get_wwwroot_parent() {
off_t ofs;
size_t len = strlen(wwwroot) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last things I would change:
static char* get_wwwroot_parent(void) {
and something I forgot again
const size_t len = strlen(wwwroot) + 1;

While being on the topic of pedantic changes, I noticed a few things in darkhttpd.c, none of them matter much, so I don't know if I want to make a PR, but if you want I can make it.

}

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
wwwroot = sdup(data, size);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It test for data = NULL. This is the same problem we have with test("", ".", "");. We can account for wwwroot being NULL in get_wwwroot_parent(), but like I said, I don't think it is worth it.

I couldn't find anything to disallow the fuzzer from testing a string or a string length. So I added if (size == 0) return 0; to run it.

return 0;
}

/* vim:set tabstop=4 shiftwidth=4 expandtab tw=78: */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it be worth setting these settings in the .editorconfig?

@emikulic
Copy link
Owner Author

emikulic commented Mar 30, 2024

I'll get back to this eventually. :) Thanks for the comments.

@hhartzer
Copy link
Contributor

Hey @emikulic! Might you have time to take a look at this again?

I might end up writing another PR, but didn't want to introduce any merge conflicts.

Thanks!

@emikulic
Copy link
Owner Author

Go ahead without me. I'll get back to this eventually. (I want to do it in a different way anyway)

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

Successfully merging this pull request may close these issues.

3 participants