Skip to content

Commit

Permalink
net/core: Fix potential memory leak in dev_set_alias()
Browse files Browse the repository at this point in the history
Do not leak memory by updating pointer with potentially NULL realloc return value.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Alexey Khoroshilov authored and David S. Miller committed Aug 8, 2012
1 parent 47dffc7 commit 7364e44
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,8 @@ int dev_change_name(struct net_device *dev, const char *newname)
*/
int dev_set_alias(struct net_device *dev, const char *alias, size_t len)
{
char *new_ifalias;

ASSERT_RTNL();

if (len >= IFALIASZ)
Expand All @@ -1068,9 +1070,10 @@ int dev_set_alias(struct net_device *dev, const char *alias, size_t len)
return 0;
}

dev->ifalias = krealloc(dev->ifalias, len + 1, GFP_KERNEL);
if (!dev->ifalias)
new_ifalias = krealloc(dev->ifalias, len + 1, GFP_KERNEL);
if (!new_ifalias)
return -ENOMEM;
dev->ifalias = new_ifalias;

strlcpy(dev->ifalias, alias, len+1);
return len;
Expand Down

0 comments on commit 7364e44

Please sign in to comment.