[pacman-dev] [PATCH] pacman/upgrade: Check malloc() return value
Allan McRae
allan at archlinux.org
Sat Mar 8 02:02:40 EST 2014
On 07/03/14 16:24, Sören Brinkmann wrote:
> Check the return value of malloc() before dereferencing the returned pointer.
>
> Signed-off-by: Sören Brinkmann <soeren.brinkmann at gmail.com>
> ---
> src/pacman/upgrade.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c
> index 5416f6180b39..19aa17218ce4 100644
> --- a/src/pacman/upgrade.c
> +++ b/src/pacman/upgrade.c
> @@ -51,6 +51,9 @@ int pacman_upgrade(alpm_list_t *targets)
> */
> for(i = targets; i; i = alpm_list_next(i)) {
> int *r = malloc(sizeof(int));
> + if(r == NULL) {
> + return 1;
> + }
>
> if(strstr(i->data, "://")) {
> char *str = alpm_fetch_pkgurl(config->handle, i->data);
>
Fine. Although if malloc of an int fails, I'm not sure we can do a lot!
Allan
More information about the pacman-dev
mailing list