[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Re: memory corruption in new MEMORY keytab



On Sat, 03 Dec 2005 11:49:52 +1100
Andrew Bartlett <abartlet@samba.org> wrote:

> [keytab_memory_fix.patch  text/x-patch (974 bytes)]
> --- /data/heimdal/lib/krb5/keytab_memory.c	2005-12-02 07:58:29.000000000 +1100
> +++ heimdal/lib/krb5/keytab_memory.c	2005-12-03 11:41:04.000000000 +1100
> @@ -214,9 +214,15 @@
>  	krb5_clear_error_string (context);
>  	return KRB5_KT_NOTFOUND;
>      }
> -    e = realloc(d->entries, d->num_entries * sizeof(*d->entries));
> -    if(e != NULL)
> -	      d->entries = e;

I might be missing a lot of context here but all of this looks like a
roundabout way of saying:

       d->entries = realloc(d->entries, d->num_entries * sizeof(*d->entries));

> +    if (d->num_entries == 0) {
> +	      free(d->entries);
> +	      d->entries = NULL;
> +    } else {
> +	      e = realloc(d->entries, d->num_entries * sizeof(*d->entries));
> +	      if(e != NULL)
> +	      d->entries = e;
> +    }
> +
>      return 0;
>  }
>