From c4efb22479a17f5298baceb299975c5e198c4b53 Mon Sep 17 00:00:00 2001 From: lyq140 <34637052+lyq140@users.noreply.github.com> Date: Wed, 1 Aug 2018 20:48:36 +0800 Subject: [PATCH] ripd: null check key Fix ripd crash of null pointer. when authenticate a rip packet, the key pointer or the key string pointer may be null, the code have to return then. Signed-off-by: lyq140 <34637052+lyq140@users.noreply.github.com> --- lib/keychain.c | 2 +- ripd/ripd.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/keychain.c b/lib/keychain.c index c3e1a6d3c4..494f6f6430 100644 --- a/lib/keychain.c +++ b/lib/keychain.c @@ -172,7 +172,7 @@ struct key *key_match_for_accept(const struct keychain *keychain, if (key->accept.start == 0 || (key->accept.start <= now && (key->accept.end >= now || key->accept.end == -1))) - if (strncmp(key->string, auth_str, 16) == 0) + if (key->string && (strncmp(key->string, auth_str, 16) == 0)) return key; } return NULL; diff --git a/ripd/ripd.c b/ripd/ripd.c index fa1188d625..f7d6d3d929 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -828,7 +828,7 @@ static int rip_auth_simple_password(struct rte *rte, struct sockaddr_in *from, struct key *key; keychain = keychain_lookup(ri->key_chain); - if (keychain == NULL) + if (keychain == NULL || keychain->key == NULL) return 0; key = key_match_for_accept(keychain, auth_str); -- 2.39.5