Commit e1a676424c290b1c8d757e3860170ac7ecd89af4

Authored by Neal Cardwell
Committed by David S. Miller
1 parent 81b401100c

ipv4: avoid passing NULL to inet_putpeer() in icmpv4_xrlim_allow()

inet_getpeer_v4() can return NULL under OOM conditions, and while
inet_peer_xrlim_allow() is OK with a NULL peer, inet_putpeer() will
crash.

This code path now uses the same idiom as the others from:
1d861aa4b3fb08822055345f480850205ffe6170 ("inet: Minimize use of
cached route inetpeer.").

Signed-off-by: Neal Cardwell <ncardwell@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 1 changed file with 2 additions and 1 deletions Side-by-side Diff

... ... @@ -257,7 +257,8 @@
257 257 struct inet_peer *peer = inet_getpeer_v4(net->ipv4.peers, fl4->daddr, 1);
258 258 rc = inet_peer_xrlim_allow(peer,
259 259 net->ipv4.sysctl_icmp_ratelimit);
260   - inet_putpeer(peer);
  260 + if (peer)
  261 + inet_putpeer(peer);
261 262 }
262 263 out:
263 264 return rc;