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

Various fixes based on coverity errors #405

merged 51 commits into from Oct 4, 2016


None yet
1 participant

lutter commented Sep 29, 2016

This fixes are all based on running augeas through coverity.

lutter added some commits Sep 23, 2016

* src/get.c: move saving/restoring match state into macros
The main reason to make these macros is that it makes sure we set
state->regs to NULL when we save registers so that any error path does not
inadvertently free the caller's registers.

Before we inconsistently set state->regs to NULL manually, and there were
cases where we could have freed the caller's registers when encountering
certain errors.
* src/pathx.c (clone_vlaue): remove incorrect call to free
We were calling free on a pointer into the interior of an array
* src/pathx.c (parse_relative_location_path): avoid leak on ENOMEM
When we ran out of memory, we did not properly free the previously
allocated LOCPATH.

lutter added some commits Sep 24, 2016

* src/pathx.c (ns_from_locpath): insist that arg LP is not NULL
This allows us to remove some confused checking
* src/info.c, src/lens.c: shore up some error formatting routines
These routines are now more resilient to being passed NULL arguments
* src/internal.c (path_expand): remove unnecessary NULL check
The TREE argument must not be NULL, so there's no need to check for that
later on
* src/get.c (print_frames): do not leak the result of format_lens
Fixing this to make coverity happy - it's unused code in a debugging routine
* src/fa.c (determinize): do not leak INI in an error case
If we succeed in allocating INI ourselves, but then fail to push the
initial state into it, we would leak INI. Fix that by explicitly freeing
* src/syntax.c (define_native_intl): fix memory leak on allocation error
When we tried to allocate BODY and allocation failed, we still had
allocated memory in PARAMS that was not freed in the error label. We now
free that list on error.

To make sure we do not try and free PARAMS when it has been linked into
FUNC, we set it to NULL after the call to BUILD_FUNC.

The call to BUILD_FUNC also erroneously checked the return value for NULL,
even though this function can never return NULL. This check was removed.
* src/builtin.c (make_pathx_exn): avoid unnecessary alllocation and leak
We used to call STRDUP for no good reason on the constant error message
returned by PATHX_ERROR and promptly leaked it.

@lutter lutter force-pushed the lutter:dev/cov branch from 33685db to 35a1c30 Oct 1, 2016

lutter added some commits Oct 1, 2016

* src/builtin.c (pathx_parse_glue): do not ref INFO passed to make_pa…

make_pathx_exn already increases the reference count appropriately. The
additional reference caused INFO to be leaked.
* src/put.c (lns_put): do not leak various things when parse fails
When parse failed, and we needed to skip the actual put, we used to return
straight away, even though we were holding on to a number of intermediate
data structures. Now we properly clean them up.
* src/augrun.c (aug_srun): make sure we always initialize CMD
Otherwise, we might try to free cmd.opt before it has been set to NULL.
* src/get.c (parse_combine): do not leak SKEL or DICT on error
If we encountered an (internal) error in ENSURE, it was possible that we
leaked SKEL and DICT. We now make sure they get set to NULL when we have
saved them, and free them if they are not NULL yet.
* examples/fadot.c: free the result from FA_AS_REGEXP
This avoids false positives with address sanitizer

@lutter lutter force-pushed the lutter:dev/cov branch from 35a1c30 to e38a014 Oct 2, 2016


This comment has been minimized.


lutter commented Oct 2, 2016

With the latest updates to this PR, pretty much all coverity errors have been addressed, and the build passes for me locally with ASAN turned on.

* src/augeas.c (aug_load): make detection of file metadata safer
When we went to clean up files that are not managed by a lens anymore, we
just assumed that anything with a 'path' child held metadata for a file and
removed that metadata and the actual contents.

That could lead to a situation where creating a node /augeas/files/path
would lead to a crash. We now use an explicit flag in the tree node that
holds file metadata to indicate the fact rather than just inferring it from
the presence of a 'path' child, so that we will never inadvertently free
everything under /augeas/files.

@lutter lutter force-pushed the lutter:dev/cov branch from 8440ac6 to a0e04bf Oct 2, 2016

@lutter lutter force-pushed the lutter:dev/cov branch from a0e04bf to 9404fe4 Oct 2, 2016

lutter added some commits Oct 4, 2016

* tests/cutest.c: fix indentation by removing tabs
This file used tabs for indentation which causes errors about misleading
indentation with GCC 6. Replacing tabs with spaces fixes that.

@lutter lutter merged commit 0d8c7bb into hercules-team:master Oct 4, 2016

1 check was pending

continuous-integration/travis-ci/pr The Travis CI build is in progress

@lutter lutter deleted the lutter:dev/cov branch Oct 4, 2016

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