verify: fix segmentation fault
authorHATAYAMA Daisuke <d.hatayama@fujitsu.com>
Wed, 13 Nov 2019 11:30:58 +0000 (06:30 -0500)
committerLennart Poettering <lennart@poettering.net>
Wed, 13 Nov 2019 21:20:01 +0000 (22:20 +0100)
commitfc9de36a3b60c69a17442aabf215e2d87e697e6f
tree5bfe08dd9971fe6df5454d326102562a4503f2c0
parenta53c38f1a22f41603ddc36c54359dd9bb7b15378
verify: fix segmentation fault

systemd-analyze verify command now results in segmentation fault if two
consecutive non-existent unit file names are given:

    # ./build/systemd-analyze a.service b.service
    ...<snip irrelevant part>...
    Unit a.service not found.
    Unit b.service not found.
    Segmentation fault (core dumped)

The cause of this is a wrong handling of return value of
manager_load_startable_unit_or_warn() in verify_units() in failure case.

It looks that the current logic wants to assign the first error status
throughout verify_units() into variable r and count up variable count only when
a given unit file exists.

However, due to the wrong handling of the return value of
manager_load_startable_unit_or_warn() in verify_units(), the variable count is
unexpectedly incremented even when there is no such unit file because the
variable r already contains non-zero value in the 2nd failure, set by the 1st
failure, and then the condition k < 0 && r == 0 evaluates to false.

This commit fixes the wrong handling of return value of
manager_load_startable_unit_or_warn() in verify_units().
src/analyze/analyze-verify.c