[PATCH 4/5] kinput: allocate enough space for null character.
Alan Coopersmith
alan.coopersmith at oracle.com
Wed Oct 19 12:57:51 PDT 2011
On 10/19/11 09:01, Dave Airlie wrote:
> From: Dave Airlie<airlied at redhat.com>
>
> this code wasn't allocating enough space and was assigning the NULL
> one past the end.
>
> Pointed out by coverity.
>
> Signed-off-by: Dave Airlie<airlied at redhat.com>
> ---
> hw/kdrive/src/kinput.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
> index c14dd82..977131c 100644
> --- a/hw/kdrive/src/kinput.c
> +++ b/hw/kdrive/src/kinput.c
> @@ -1054,7 +1054,7 @@ KdGetOptions (InputOption **options, char *string)
> if (strchr(string, '='))
> {
> tam_key = (strchr(string, '=') - string);
> - newopt->key = (char *)malloc(tam_key);
> + newopt->key = (char *)malloc(tam_key + 1);
> strncpy(newopt->key, string, tam_key);
> newopt->key[tam_key] = '\0';
> newopt->value = strdup(strchr(string, '=') + 1);
Is strndup() portable enough to be used here? I don't see any other
instances yet in the xserver git master or any of the other X.Org
trees I have checked out.
It's not in our traditional Unix98 baseline, but
http://pubs.opengroup.org/onlinepubs/9699919799/functions/strdup.html
says it's in the 2008 version of POSIX.
Otherwise, what you have looks best, so:
Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
--
-Alan Coopersmith- alan.coopersmith at oracle.com
Oracle Solaris Platform Engineering: X Window System
More information about the xorg-devel
mailing list