[Libvirt-cim] [PATCH 6/8] Fix misuse of signed variables
Sharad Mishra
snmishra at us.ibm.com
Thu Nov 3 22:37:12 UTC 2011
+1
> "Eduardo Lima (Etrunko)" <eblima at linux.vnet.ibm.com>
> Sent by: libvirt-cim-bounces at redhat.com
>
> 11/03/2011 10:48 AM
>
> Please respond to
> List for discussion and development of libvirt CIM
<libvirt-cim at redhat.com>
>
> To
>
> libvirt-cim at redhat.com
>
> cc
>
> "Eduardo Lima \(Etrunko\)" <eblima at br.ibm.com>
>
> Subject
>
> [Libvirt-cim] [PATCH 6/8] Fix misuse of signed variables
>
> From: Eduardo Lima (Etrunko) <eblima at br.ibm.com>
>
> As revealed by Coverity scan report:
>
> https://bugzilla.redhat.com/show_bug.cgi?id=728245#c8
> https://bugzilla.redhat.com/attachment.cgi?id=530435
>
> Error: NEGATIVE_RETURNS:
> infostore.c:183: negative_return_fn: Function "open(filename, 66,
> 384)" returns
> a negative number.
> infostore.c:183: var_assign: Assigning: signed variable "isc->fd" =
"open".
> infostore.c:214: negative_returns: "isc->fd" is passed to a parameter
that
> cannot be negative.
> infostore.c:53: neg_sink_parm_call: Passing "ctx->fd" to "close", which
cannot
> accept a negative.
>
> Error: NEGATIVE_RETURNS:
> Virt_ComputerSystemIndication.c:518: negative_return_fn: Function
> "platform_from_class(args->
classname)"
> returns a negative number.
> Virt_ComputerSystemIndication.c:503: return_negative_constant: Explicitly
> returning negative value "-1".
> Virt_ComputerSystemIndication.c:518: var_assign: Assigning: signed
variable
> "platform" = "platform_from_class".
> Virt_ComputerSystemIndication.c:539: negative_returns: Using
> variable "platform"
> as an index to array
"active_filters".
>
> Error: NEGATIVE_RETURNS:
> Virt_ComputerSystemIndication.c:518: negative_return_fn: Function
> "platform_from_class(args->
classname)"
> returns a negative number.
> Virt_ComputerSystemIndication.c:503: return_negative_constant: Explicitly
> returning negative value "-1".
> Virt_ComputerSystemIndication.c:518: var_assign: Assigning: signed
variable
> "platform" = "platform_from_class".
> Virt_ComputerSystemIndication.c:596: negative_returns: Using
> variable "platform"
> as an index to array "thread_id".
>
> Error: NEGATIVE_RETURNS:
> Virt_VSMigrationService.c:512: negative_return_fn: Function "mkstemp
> (filename)"
> returns a negative number.
> Virt_VSMigrationService.c:512: var_assign: Assigning: signed variable
> "fd" = "mkstemp".
> Virt_VSMigrationService.c:547: negative_returns: "fd" is passed to
aparameter
> that cannot be negative.
>
> Signed-off-by: Eduardo Lima (Etrunko) <eblima at br.ibm.com>
> ---
> libxkutil/infostore.c | 4 +++-
> src/Virt_ComputerSystemIndication.c | 12 +++++++++---
> src/Virt_VSMigrationService.c | 3 ++-
> 3 files changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/libxkutil/infostore.c b/libxkutil/infostore.c
> index 716dedd..dd1e38c 100644
> --- a/libxkutil/infostore.c
> +++ b/libxkutil/infostore.c
> @@ -50,7 +50,9 @@ static void infostore_cleanup_ctx(struct infostore_ctx
*ctx)
> {
> xmlXPathFreeContext(ctx->xpathctx);
> xmlFreeDoc(ctx->doc);
> - close(ctx->fd);
> +
> + if (ctx->fd >= 0)
> + close(ctx->fd);
>
> free(ctx);
> }
> diff --git a/src/Virt_ComputerSystemIndication.c b/src/
> Virt_ComputerSystemIndication.c
> index 337f20a..9b3b80b 100644
> --- a/src/Virt_ComputerSystemIndication.c
> +++ b/src/Virt_ComputerSystemIndication.c
> @@ -518,11 +518,14 @@ static CMPI_THREAD_RETURN lifecycle_thread(void
*params)
> char *prefix = class_prefix_name(args->classname);
> int platform = platform_from_class(args->classname);
>
> + if (prefix == NULL || platform == -1)
> + goto init_out;
> +
> conn = connect_by_classname(_BROKER, args->classname, &s);
> if (conn == NULL) {
> CU_DEBUG("Unable to start lifecycle thread: "
> "Failed to connect (cn: %s)", args->classname);
> - goto out;
> + goto conn_out;
> }
>
> pthread_mutex_lock(&lifecycle_mutex);
> @@ -591,16 +594,19 @@ static CMPI_THREAD_RETURN lifecycle_thread(void
*params)
> }
> }
>
> - out:
> CU_DEBUG("Exiting CSI event loop (%s)", prefix);
>
> thread_id[platform] = 0;
>
> pthread_mutex_unlock(&lifecycle_mutex);
> stdi_free_ind_args(&args);
> - free(prefix);
> +
> + conn_out:
> virConnectClose(conn);
>
> + init_out:
> + free(prefix);
> +
> return NULL;
> }
>
> diff --git a/src/Virt_VSMigrationService.c
b/src/Virt_VSMigrationService.c
> index 414feda..be9bb7c 100644
> --- a/src/Virt_VSMigrationService.c
> +++ b/src/Virt_VSMigrationService.c
> @@ -544,7 +544,8 @@ static char *write_params(CMPIArray *array)
> if (file != NULL)
> fclose(file);
>
> - close(fd);
> + if (fd >= 0)
> + close(fd);
>
> return filename;
> }
> --
> 1.7.4.4
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim
>
More information about the Libvirt-cim
mailing list