Skip to content

examples/http2-upload: fix a crash - #5463

Closed
rgeorgiev583 wants to merge 3 commits into
curl:masterfrom
rgeorgiev583:fix-crash-in-example
Closed

examples/http2-upload: fix a crash#5463
rgeorgiev583 wants to merge 3 commits into
curl:masterfrom
rgeorgiev583:fix-crash-in-example

Conversation

@rgeorgiev583

Copy link
Copy Markdown
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

bagder commented May 26, 2020

Copy link
Copy Markdown
Member

'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

bagder commented Jun 1, 2020

Copy link
Copy Markdown
Member

ping @rgeorgiev583 ?

@rgeorgiev583

rgeorgiev583 commented Jun 1, 2020

Copy link
Copy Markdown
Contributor Author

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

bagder commented Jun 1, 2020

Copy link
Copy Markdown
Member

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.

2 participants