looks good

On Fri, 2009-04-03 at 21:28 +0200, Jim Meyering wrote:
> From: Jim Meyering <[email protected]>
> 
> * lib/confdb.c (MIN): Define.
> (confdb_write): Use new errbuf_len parameter.
> Also note bugs (Chrissie confirms) that error_text is not
> set in two error-return cases.
> * test/testconfdb.c (do_write_tests): Update use of confdb_write.
> ---
>  include/corosync/confdb.h |    3 ++-
>  lib/confdb.c              |   18 +++++++++++++-----
>  test/testconfdb.c         |    4 ++--
>  3 files changed, 17 insertions(+), 8 deletions(-)
> 
> diff --git a/include/corosync/confdb.h b/include/corosync/confdb.h
> index f3e24fa..ca52ae8 100644
> --- a/include/corosync/confdb.h
> +++ b/include/corosync/confdb.h
> @@ -109,7 +109,8 @@ cs_error_t confdb_finalize (
>   */
>  cs_error_t confdb_write (
>       confdb_handle_t handle,
> -     char *error_text);
> +     char *error_text,
> +     size_t errbuf_len);
> 
>  /*
>   * Reload the configuration
> diff --git a/lib/confdb.c b/lib/confdb.c
> index a06f3a1..77e32ce 100644
> --- a/lib/confdb.c
> +++ b/lib/confdb.c
> @@ -53,6 +53,9 @@
> 
>  #include "sa-confdb.h"
> 
> +#undef MIN
> +#define MIN(x,y) ((x) < (y) ? (x) : (y))
> +
>  /* Hold the information for iterators so that
>     callers can do recursive tree traversals.
>     each object_handle can have its own iterator */
> @@ -1397,7 +1400,8 @@ error_exit:
> 
>  cs_error_t confdb_write (
>       confdb_handle_t handle,
> -     char *error_text)
> +     char *error_text,
> +     size_t errbuf_len)
>  {
>       cs_error_t error;
>       struct confdb_inst *confdb_inst;
> @@ -1407,13 +1411,14 @@ cs_error_t confdb_write (
> 
>       error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void 
> *)&confdb_inst);
>       if (error != CS_OK) {
> +             /* FIXME: set error_text */
>               return (error);
>       }
> 
>       if (confdb_inst->standalone) {
>               error = CS_OK;
> 
> -             if (confdb_sa_write(error_text))
> +             if (confdb_sa_write(error_text, errbuf_len))
>                       error = CS_ERR_ACCESS;
>               goto error_exit;
>       }
> @@ -1435,12 +1440,16 @@ cs_error_t confdb_write (
> 
>       pthread_mutex_unlock (&confdb_inst->response_mutex);
>       if (error != CS_OK) {
> +             /* FIXME: set error_text */
>               goto error_exit;
>       }
> 
>       error = res_lib_confdb_write.header.error;
> -     if (res_lib_confdb_write.error.length)
> -             memcpy(error_text, res_lib_confdb_write.error.value, 
> res_lib_confdb_write.error.length);
> +     if (res_lib_confdb_write.error.length) {
> +             memcpy(error_text, res_lib_confdb_write.error.value,
> +                    MIN(res_lib_confdb_write.error.length,errbuf_len));
> +             error_text[errbuf_len-1] = '\0';
> +     }
> 
>  error_exit:
>       (void)saHandleInstancePut (&confdb_handle_t_db, handle);
> @@ -1600,4 +1609,3 @@ error_exit:
> 
>       return (error);
>  }
> -
> diff --git a/test/testconfdb.c b/test/testconfdb.c
> index 5cfb146..436dd69 100644
> --- a/test/testconfdb.c
> +++ b/test/testconfdb.c
> @@ -1,5 +1,5 @@
>  /*
> - * Copyright (c) 2008 Red Hat Inc
> + * Copyright (c) 2008, 2009 Red Hat Inc
>   *
>   * All rights reserved.
>   *
> @@ -188,7 +188,7 @@ static void do_write_tests(confdb_handle_t handle)
>               return;
>       }
> 
> -     res = confdb_write(handle, error_string);
> +     res = confdb_write(handle, error_string, sizeof error_string);
>       printf("confdb_write returned %d: %s\n", res, error_string);
>  }
> 

_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to