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

examples/http2-upload: fix a crash #5463

Closed
wants to merge 3 commits into from

Conversation

rgeorgiev583
Copy link
Contributor

If index.html does not exist in the directory from which the example
is invoked, the fopen(upload, "rb") invocation in setup would fail,
returning NULL. This value is subsequently passed as the FILE* argument
of the fread invocation in the read_callback function, which is the
actual cause of the crash (apparently fread assumes that argument to
be non-null).

In addition, mitigate some possible crashes of similar origin.

If `index.html` does not exist in the directory from which the example
is invoked, the fopen(upload, "rb") invocation in `setup` would fail,
returning NULL.  This value is subsequently passed as the FILE* argument
of the `fread` invocation in the `read_callback` function, which is the
actual cause of the crash (apparently `fread` assumes that argument to
be non-null).

In addition, mitigate some possible crashes of similar origin.
@bagder
Copy link
Member

bagder commented May 26, 2020

'make checksrc' found a few code style nits:

  RUN      checksrc
./http2-download.c:153:5: warning: if with space (SPACEBEFOREPAREN)
   if (!t->out)
     ^
./http2-download.c:154:3: warning: badly placed open brace (BRACEPOS)
   {
   ^
./http2-download.c:155:99: warning: Longer than 79 columns (LONGLINE)
     fprintf(stderr, "error: could not open file %s for writing: %s\n", filename, strerror(errno));
./http2-upload.c:182:5: warning: if with space (SPACEBEFOREPAREN)
   if (!out)
     ^
./http2-upload.c:183:3: warning: badly placed open brace (BRACEPOS)
   {
   ^
./http2-upload.c:184:97: warning: Longer than 79 columns (LONGLINE)
     fprintf(stderr, "error: could not open file %s for writing: %s\n", upload, strerror(errno));
./http2-upload.c:191:5: warning: if with space (SPACEBEFOREPAREN)
   if (stat(upload, &file_info))
     ^
./http2-upload.c:192:3: warning: badly placed open brace (BRACEPOS)
   {
   ^
./http2-upload.c:193:85: warning: Longer than 79 columns (LONGLINE)
     fprintf(stderr, "error: could not stat file %s: %s\n", upload, strerror(errno));
./http2-upload.c:200:5: warning: if with space (SPACEBEFOREPAREN)
   if (!i->in)
     ^
./http2-upload.c:201:3: warning: badly placed open brace (BRACEPOS)
   {
   ^
./http2-upload.c:202:97: warning: Longer than 79 columns (LONGLINE)
     fprintf(stderr, "error: could not open file %s for reading: %s\n", upload, strerror(errno));

@bagder
Copy link
Member

bagder commented Jun 1, 2020

ping @rgeorgiev583 ?

@rgeorgiev583
Copy link
Contributor Author

rgeorgiev583 commented Jun 1, 2020

Sorry for not responding; was a bit busy recently. Am also sorry for overlooking the code style guide. I'm pushing the fixes now; hope the checks would turn out fine after that :)

@bagder bagder closed this in abfd154 Jun 1, 2020
@bagder
Copy link
Member

bagder commented Jun 1, 2020

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

2 participants