aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2019-04-10 15:26:08 +0200
committerHarald Welte <laforge@gnumonks.org>2019-04-11 19:27:17 +0200
commit549417e67559410d235d75c403b7652859063c38 (patch)
tree9deb12caded9887e0b594d96e6dafef77bcb146d
parent42c9fa495852e674c0d5e9dc51bdc12e5025b4f0 (diff)
ggsn: Remove magic numbers from ipcp_contains_option()
Let's remove some magic numbers and use a data structure instead. Change-Id: I5b1abc6f403f85986407e9e8359924dfcb58031a
-rw-r--r--ggsn/ggsn.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c
index a439d01..59523ac 100644
--- a/ggsn/ggsn.c
+++ b/ggsn/ggsn.c
@@ -419,14 +419,15 @@ static const uint8_t *ipcp_contains_option(const uint8_t *ipcp, size_t ipcp_len,
const uint8_t *cur_opt = ipcp + sizeof(struct ipcp_hdr);
/* iterate over Options and check if protocol contained */
- while (cur_opt + 2 <= ipcp + ipcp_len) {
- uint8_t type = cur_opt[0];
- uint8_t len = cur_opt[1]; /* length value includes 2 bytes type/length */
- if (len < 2)
+ while (cur_opt + sizeof(struct ipcp_option_hdr) <= ipcp + ipcp_len) {
+ const struct ipcp_option_hdr *cur_opt_hdr = (const struct ipcp_option_hdr *)cur_opt;
+ /* length value includes 2 bytes type/length */
+ if (cur_opt_hdr->len < sizeof(struct ipcp_option_hdr))
return NULL;
- if (type == opt && len >= 2 + opt_minlen)
+ if (cur_opt_hdr->type == opt &&
+ cur_opt_hdr->len >= sizeof(struct ipcp_option_hdr) + opt_minlen)
return cur_opt;
- cur_opt += len;
+ cur_opt += cur_opt_hdr->len;
}
return NULL;
}