Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

NULL pointer passed as an argument to a nonnull parameter #465

Open
vincenttesla opened this issue Mar 28, 2019 · 2 comments
Open

NULL pointer passed as an argument to a nonnull parameter #465

vincenttesla opened this issue Mar 28, 2019 · 2 comments

Comments

@vincenttesla
Copy link

test.c line 4042 to 4044 :

char *
create_large_chunked_message (int body_size_in_kb, const char* headers)
{
int i;
size_t wrote = 0;
size_t headers_len = strlen(headers);
size_t bufsize = headers_len + (5+1024+2)*body_size_in_kb + 6;
char * buf = malloc(bufsize);

memcpy(buf, headers, headers_len);
wrote += headers_len;

for (i = 0; i < body_size_in_kb; i++) {
// write 1kb chunk into the body.
memcpy(buf + wrote, "400\r\n", 5);
wrote += 5;
memset(buf + wrote, 'C', 1024);
wrote += 1024;
strcpy(buf + wrote, "\r\n");
wrote += 2;
}

memcpy(buf + wrote, "0\r\n\r\n", 6);
wrote += 6;
assert(wrote == bufsize);

return buf;
}

if the "malloc" function return 0, the following "memcpy" function would received a NULL pointer arg. This may happen under some extreme conditions.

@indutny
Copy link
Member

indutny commented Mar 28, 2019

Good catch! I think an assert() would suffice, since this is a test file. Would you be interested in submitting a Pull Request to fix this?

Thank you!

@vincenttesla
Copy link
Author

I submitted a Pull Request, I'm glad I could help.

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

No branches or pull requests

2 participants