patch looks good for commit.

regards
-steve
On Wed, 2008-08-20 at 06:54 +1200, angus salkeld wrote:
> Display strings safely, even if they are invalid, e.g. data in a
> received
> message was corrupted.
> 
> Author: Tim Beale <[EMAIL PROTECTED]>
> ---
>  exec/util.c |   19 ++++++++-----------
>  1 files changed, 8 insertions(+), 11 deletions(-)
> 
> diff --git a/exec/util.c b/exec/util.c
> index 593cdba..7939a4a 100644
> --- a/exec/util.c
> +++ b/exec/util.c
> @@ -86,21 +86,18 @@ void _corosync_exit_error (
>         exit (EXIT_FAILURE);
>  }
>  
> +#define min(a,b) ((a) < (b) ? (a) : (b))
> +
>  char *getSaNameT (SaNameT *name)
>  {
> -#if 0
> -       static char ret_name[300];
> -
> -       memset (ret_name, 0, sizeof (ret_name));
> -       if (name->length > 299) {
> -               memcpy (ret_name, name->value, 299);
> -       } else {
> +       static char ret_name[SA_MAX_NAME_LENGTH];
>  
> -               memcpy (ret_name, name->value, name->length);
> +       /* if string is corrupt (non-terminated), ensure it's
> displayed safely */
> +       if (name->length >= SA_MAX_NAME_LENGTH ||
> name->value[name->length] != '\0') {
> +               memset (ret_name, 0, sizeof (ret_name));
> +               memcpy (ret_name, name->value, min(name->length,
> SA_MAX_NAME_LENGTH -1));
> +               return (ret_name);
>         }
> -       return (ret_name);
> -#endif
> -// TODO
>         return ((char *)name->value);
>  }
>  
> -- 
> 1.5.6
> 
> 
> _________________ 

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

Reply via email to