[libvirt] [PATCH libvirt-snmp 0/3] fix problems found by coverity

These three problems were found by coverity during the run documented here: https://bugzilla.redhat.com/show_bug.cgi?id=732015 The three fixes are all very simple, but sufficiently unrelated (other than the method used for finding them) to warrant separate patches.

This bug was found by coverity. See: https://bugzilla.redhat.com/show_bug.cgi?id=732015 --- src/libvirtGuestTable_data_get.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/libvirtGuestTable_data_get.c b/src/libvirtGuestTable_data_get.c index 2430f9c..cc31e9e 100644 --- a/src/libvirtGuestTable_data_get.c +++ b/src/libvirtGuestTable_data_get.c @@ -201,7 +201,7 @@ libvirtGuestName_get( libvirtGuestTable_rowreq_ctx *rowreq_ctx, char **libvirtGu if (!rowreq_ctx->data.libvirtGuestName) return MFD_SKIP; - len = strlen(rowreq_ctx->data.libvirtGuestName); + len = strlen(rowreq_ctx->data.libvirtGuestName) + 1; if ((NULL == (* libvirtGuestName_val_ptr_ptr )) || ((* libvirtGuestName_val_ptr_len_ptr ) < len)) { /* -- 1.7.6.4

This is another bug found by coverity in: https://bugzilla.redhat.com/show_bug.cgi?id=732015 Apparently libvirtGuestUUID was originally a pointer, and the code was making sure that it had memory allocated, but now it is an array that is contained in the structure, so checking for NULL makes no sense. --- src/libvirtGuestTable_data_get.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/src/libvirtGuestTable_data_get.c b/src/libvirtGuestTable_data_get.c index cc31e9e..497b3f8 100644 --- a/src/libvirtGuestTable_data_get.c +++ b/src/libvirtGuestTable_data_get.c @@ -83,9 +83,7 @@ libvirtGuestTable_indexes_set_tbl_idx(libvirtGuestTable_mib_index *tbl_idx, char /* * make sure there is enough space for libvirtGuestUUID data */ - if ((NULL == tbl_idx->libvirtGuestUUID) || - (tbl_idx->libvirtGuestUUID_len < - (libvirtGuestUUID_val_ptr_len))) { + if (tbl_idx->libvirtGuestUUID_len < (libvirtGuestUUID_val_ptr_len)) { snmp_log(LOG_ERR,"not enough space for value\n"); return MFD_ERROR; } -- 1.7.6.4

This bug was uncovered by coverity during the run that resulted in the filing of the following bug: https://bugzilla.redhat.com/show_bug.cgi?id=732015 use_syslog was initialized to 0, and then if the "Use stderr" option was selected, it was set to ... "0"! Rather than simply initializing to 1, I decided to reduce confusion by renaming the variable to "use_stderr", leave it initialized to 0, then set to 1 when the user asks for stderr. --- src/libvirtMib_subagent.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libvirtMib_subagent.c b/src/libvirtMib_subagent.c index f5749be..2ce1509 100644 --- a/src/libvirtMib_subagent.c +++ b/src/libvirtMib_subagent.c @@ -60,7 +60,7 @@ main (int argc, char **argv) { /* Defs for arg-handling code: handles setting of policy-related variables */ int ch; extern char *optarg; - int dont_fork = 0, use_syslog = 0; + int dont_fork = 0, use_stderr = 0; char *agentx_socket = NULL; while ((ch = getopt(argc, argv, "D:fHLMx:")) != EOF) @@ -85,7 +85,7 @@ main (int argc, char **argv) { agentx_subagent = 0; break; case 'L': - use_syslog = 0; /* use stderr */ + use_stderr = 1; break; case 'x': agentx_socket = optarg; @@ -134,14 +134,14 @@ main (int argc, char **argv) { } snmp_disable_log(); - if (use_syslog) - snmp_enable_calllog(); - else + if (use_stderr) snmp_enable_stderrlog(); + else + snmp_enable_calllog(); /* daemonize */ if(!dont_fork) { - int rc = netsnmp_daemonize(1,!use_syslog); + int rc = netsnmp_daemonize(1, use_stderr); if(rc) exit(-1); } -- 1.7.6.4

On 10/18/2011 11:13 AM, Laine Stump wrote:
These three problems were found by coverity during the run documented here:
https://bugzilla.redhat.com/show_bug.cgi?id=732015
The three fixes are all very simple, but sufficiently unrelated (other than the method used for finding them) to warrant separate patches.
ACK series. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Laine Stump