[libvirt] [PATCH] Avoid Coverity DEADCODE warning

Commit '922b7fda' resulted in two DEADCODE warnings from Coverity in remoteDispatchAuthPolkit and virAccessDriverPolkitFormatProcess. Commit '604ae657' modified the daemon.c code to remove the deadcode issue, but did not do so for viracessdriverpolkit.c. This just mimics the same changes Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/access/viraccessdriverpolkit.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/access/viraccessdriverpolkit.c b/src/access/viraccessdriverpolkit.c index ff82583..b9907ba 100644 --- a/src/access/viraccessdriverpolkit.c +++ b/src/access/viraccessdriverpolkit.c @@ -76,8 +76,9 @@ virAccessDriverPolkitFormatProcess(const char *actionid) const char *callerTime = NULL; const char *callerUid = NULL; char *ret = NULL; - bool supportsuid = false; - static bool polkitInsecureWarned; +#ifndef PKCHECK_SUPPORTS_UID + static bool polkitInsecureWarned = false; +#endif if (!identity) { virAccessError(VIR_ERR_ACCESS_DENIED, @@ -109,19 +110,17 @@ virAccessDriverPolkitFormatProcess(const char *actionid) } #ifdef PKCHECK_SUPPORTS_UID - supportsuid = true; -#endif - if (supportsuid) { - if (virAsprintf(&ret, "%s,%s,%s", callerPid, callerTime, callerUid) < 0) - goto cleanup; - } else { - if (!polkitInsecureWarned) { - VIR_WARN("No support for caller UID with pkcheck. This deployment is known to be insecure."); - polkitInsecureWarned = true; - } - if (virAsprintf(&ret, "%s,%s", callerPid, callerTime) < 0) - goto cleanup; + if (virAsprintf(&ret, "%s,%s,%s", callerPid, callerTime, callerUid) < 0) + goto cleanup; +#else + if (!polkitInsecureWarned) { + VIR_WARN("No support for caller UID with pkcheck. " + "This deployment is known to be insecure."); + polkitInsecureWarned = true; } + if (virAsprintf(&ret, "%s,%s", callerPid, callerTime) < 0) + goto cleanup; +#endif cleanup: virObjectUnref(identity); -- 1.8.3.1

Ping On 10/18/2013 06:59 AM, John Ferlan wrote:
Commit '922b7fda' resulted in two DEADCODE warnings from Coverity in remoteDispatchAuthPolkit and virAccessDriverPolkitFormatProcess. Commit '604ae657' modified the daemon.c code to remove the deadcode issue, but did not do so for viracessdriverpolkit.c. This just mimics the same changes
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/access/viraccessdriverpolkit.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/src/access/viraccessdriverpolkit.c b/src/access/viraccessdriverpolkit.c index ff82583..b9907ba 100644 --- a/src/access/viraccessdriverpolkit.c +++ b/src/access/viraccessdriverpolkit.c @@ -76,8 +76,9 @@ virAccessDriverPolkitFormatProcess(const char *actionid) const char *callerTime = NULL; const char *callerUid = NULL; char *ret = NULL; - bool supportsuid = false; - static bool polkitInsecureWarned; +#ifndef PKCHECK_SUPPORTS_UID + static bool polkitInsecureWarned = false; +#endif
if (!identity) { virAccessError(VIR_ERR_ACCESS_DENIED, @@ -109,19 +110,17 @@ virAccessDriverPolkitFormatProcess(const char *actionid) }
#ifdef PKCHECK_SUPPORTS_UID - supportsuid = true; -#endif - if (supportsuid) { - if (virAsprintf(&ret, "%s,%s,%s", callerPid, callerTime, callerUid) < 0) - goto cleanup; - } else { - if (!polkitInsecureWarned) { - VIR_WARN("No support for caller UID with pkcheck. This deployment is known to be insecure."); - polkitInsecureWarned = true; - } - if (virAsprintf(&ret, "%s,%s", callerPid, callerTime) < 0) - goto cleanup; + if (virAsprintf(&ret, "%s,%s,%s", callerPid, callerTime, callerUid) < 0) + goto cleanup; +#else + if (!polkitInsecureWarned) { + VIR_WARN("No support for caller UID with pkcheck. " + "This deployment is known to be insecure."); + polkitInsecureWarned = true; } + if (virAsprintf(&ret, "%s,%s", callerPid, callerTime) < 0) + goto cleanup; +#endif
cleanup: virObjectUnref(identity);

On 10/18/2013 11:59 AM, John Ferlan wrote:
Commit '922b7fda' resulted in two DEADCODE warnings from Coverity in remoteDispatchAuthPolkit and virAccessDriverPolkitFormatProcess. Commit '604ae657' modified the daemon.c code to remove the deadcode issue, but did not do so for viracessdriverpolkit.c. This just mimics the same changes
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/access/viraccessdriverpolkit.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
+#ifndef PKCHECK_SUPPORTS_UID + static bool polkitInsecureWarned = false;
Since this variable is static, C guarantees this already starts life as false, without needing the explicit initializer. But up to you if you want to reduce typing. ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Fri, Oct 18, 2013 at 06:59:51AM -0400, John Ferlan wrote:
Commit '922b7fda' resulted in two DEADCODE warnings from Coverity in remoteDispatchAuthPolkit and virAccessDriverPolkitFormatProcess. Commit '604ae657' modified the daemon.c code to remove the deadcode issue, but did not do so for viracessdriverpolkit.c. This just mimics the same changes
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/access/viraccessdriverpolkit.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
ACK, Martin
participants (3)
-
Eric Blake
-
John Ferlan
-
Martin Kletzander