FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Coverity fixes by pks-t · Pull Request #4167 · libgit2/libgit2 · GitHub

Repository navigation

Coverity fixes - #4167

Merged
ethomson merged 6 commits into
libgit2:masterfrom
pks-t:pks/ci-fixes
Mar 22, 2017
Merged

ethomson merged 6 commits into
libgit2:masterfrom
pks-t:pks/ci-fixes

Conversation

pks-t commented Mar 20, 2017

Copy link
Copy Markdown
Member

Some Coverity fixes. The most important one is the openssl_stream commit, which fixes an actual use after free/segfault when we shut down OpenSSL's mutexes.

Comment thread src/config_file.c Outdated

git_buf_grow(&buf, alloc_len);
if (git_buf_grow(&buf, alloc_len) < 0)
return -1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It looks like we're not doing any error checking on buf in the rest of this function. We should probably check that we didn't OOM while trying to work with this buffer before return.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Agreed, thanks!

The OpenSSL library may require multiple locks to work correctly, where
it is the caller's responsibility to initialize and release the locks.
While we correctly initialized up to `n` locks, as determined by
`CRYPTO_num_locks`, we were repeatedly freeing the same mutex in our
shutdown procedure.

Fix the issue by freeing locks at the correct index.
Comment thread src/diff_parse.c
diff->base.free_fn = diff_parsed_free;

git_diff_init_options(&diff->base.opts, GIT_DIFF_OPTIONS_VERSION);
if (git_diff_init_options(&diff->base.opts, GIT_DIFF_OPTIONS_VERSION) < 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I was surprised to find that the git_*_init_options functions return an int, since none of them can fail. I guess it's nice future proofing. Anyway, if this shuts coverity up then we should take it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I was surprised by this, as well. And actually it can fail if somehow compiling against two versions of libgit2. Unlikely, but possible.

Comment thread src/config_file.c
git_buf_printf(&buf, "%s.", base_name);
if (git_buf_grow(&buf, alloc_len) < 0
|| git_buf_printf(&buf, "%s.", base_name) < 0)
goto end_parse;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I was thinking that we didn't even need to test this if we have the git_buf_oom test at the bottom. (Since the buffer will hold on to their OOM failure.) This lets us fail earlier, which could be nice. I don't have a strong preference, but I would suggest that you change the formatting so that the || is at the end of the first line, not starting the second.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm a bit torn, as well. Anyway, I think failing early here is a nice to have and it shuts up Coverity without any real detriment.

Huh. Where did I take up that "||" should start at newline... dunno. Will fix all occasions, thanks.

Comment thread src/blame_git.c Outdated
git_object_lookup((git_object**)&porigin->blob, blame->repository,
git_blob_id(origin->blob), GIT_OBJ_BLOB);
if (!porigin->blob
&& git_object_lookup((git_object**)&porigin->blob, blame->repository,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can you pull the && up so that it's at the end of the first line, not starting the second?

Comment thread src/patch_parse.c Outdated

if (ctx->line_len > 0) {
if (parse_advance_expected_str(ctx, "\n") < 0
|| ctx->line_len > 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can you pull the || up onto the line above?

pks-t added 5 commits March 21, 2017 15:48
The function `pass_whole_blame` performs an object lookup but does not
check if the lookup actually succeeds. Convert the function to return an
error code and check for it in the calling function.
While parsing section headers, we use a buffer to store the actual
section name. We do not check though if the buffer runs out of memory at
any stage. Do so.
The `pack_entry_find_prefix` function receives a `git_rawobj` structure
as argument. While the function first initializes the structure to a
sensible state, Coverity is unable to correctly detect this, resulting
in a warning.

Fix this warning by initializing the object to all-zeroes before passing
it to the function.
While parsing patch header lines, we iterate over each line and check if
the line has trailing garbage. What we do not check though is that the
line is actually a line ending with a trailing newline.

Fix this by checking the return code of `parse_advance_expected_str`.

pks-t commented Mar 21, 2017

Copy link
Copy Markdown
Member Author

Thanks for your review, fixed all!

Copy link
Copy Markdown
Member

Thanks!

ethomson merged commit 7e53e8c into libgit2:master Mar 22, 2017
pks-t deleted the pks/ci-fixes branch March 28, 2017 06:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

2 participants


Back | FazBrowse Home | New Git URL