Skip to content

Fix bugs reported by Clang analyzer#3887

Merged
chemamartinez merged 13 commits into3.11from
3870-fix-defects
Sep 19, 2019
Merged

Fix bugs reported by Clang analyzer#3887
chemamartinez merged 13 commits into3.11from
3870-fix-defects

Conversation

@crolopez
Copy link
Contributor

@crolopez crolopez commented Aug 27, 2019

Related issue
#3870

This PR solves the bugs reported by Clang which can be seen in the linked issue.

The reports of dangerous castings to a struct from a non-struct type will be ignored (except for os_net.c). The reason for this is that we need to add strange and confusing code to silent these warnings, which are controlled situations (false positives). These reports cannot be omitted by just adding the #ifndef __clang_analyzer__ expression.

The undesired use of the sizeof function in syscheck_audit.c has been solved by using the size of the memory allocated in the cache variable.

The memory leak in rules.c has been solved by releasing the config_ruleinfo variable with the program flow jumps to cleanup tag in case of error. Fixing this is not dangerous since the error case of this function end in a merror_exit call (the program finishes), and for this reason, it didn't suppose a real memory leak.

The possibly memory leak reported in reports-config.c was a false positive because if os_report_configfilter function returns 0, the memory allocated in ncat is now referenced by another variable. For some reason, Clang analyzer does not verify the function flow. To solve it, the memory allocated for the filter_value parameter is not allocated in the function when arg_type is REPORT_FILTER.

Tests

  • Compilation without warnings in every supported platform

    • Linux
    • Windows
    • MAC OS X
  • Source installation

  • Package installation

  • Source upgrade

  • Package upgrade

  • Memory tests for Linux

    • Scan-build report
    • Coverity
    • Valgrind (memcheck and descriptor leaks check)
    • AddressSanitizer

@crolopez crolopez requested a review from chemamartinez August 27, 2019 09:01
@crolopez crolopez marked this pull request as ready for review August 27, 2019 09:01
@crolopez crolopez changed the title 3870 fix defects Fix bugs reported by Clang analyzer Aug 27, 2019
@JuantAldea JuantAldea self-assigned this Sep 5, 2019
JuantAldea
JuantAldea approved these changes Sep 5, 2019
@JuantAldea JuantAldea requested a review from snaow September 5, 2019 15:10
@snaow snaow removed the request for review from vikman90 September 12, 2019 13:26
@chemamartinez chemamartinez changed the base branch from 3.10 to 3.11 September 18, 2019 10:46
@chemamartinez chemamartinez merged commit bc8187a into 3.11 Sep 19, 2019
@chemamartinez chemamartinez deleted the 3870-fix-defects branch September 19, 2019 13:10
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.

4 participants