|
| 1 | +From e9bf329eee94d6d49a17da35aea189179aeed3c6 Mon Sep 17 00:00:00 2001 |
| 2 | +From: sudhanshukumar22 < [email protected]> |
| 3 | +Date: Thu, 24 Dec 2020 09:27:49 -0800 |
| 4 | +Subject: [PATCH] From 5c3479463a919193213213e2d8634c754c09aa51 Mon Sep 17 |
| 5 | + 00:00:00 2001 From: Vincent Bernat < [email protected]> Date: Sun, 6 Dec 2020 |
| 6 | + 14:21:04 +0100 Subject: [PATCH] lib: fix LLDP-MED location parsing in |
| 7 | + liblldpctl |
| 8 | + |
| 9 | +Some bounds were not checked correctly when parsing LLDP-MED civic |
| 10 | +location fields. This triggers out-of-bound reads (no write) in |
| 11 | +lldpcli, ultimately leading to a crash. |
| 12 | + |
| 13 | +Fix #420 |
| 14 | +Signed-off-by: sudhanshukumar22 < [email protected]> |
| 15 | +--- |
| 16 | + src/lib/atoms/med.c | 8 ++++++-- |
| 17 | + 1 file changed, 6 insertions(+), 2 deletions(-) |
| 18 | + |
| 19 | +diff --git a/src/lib/atoms/med.c b/src/lib/atoms/med.c |
| 20 | +index e1b20fd..595dba4 100644 |
| 21 | +--- a/src/lib/atoms/med.c |
| 22 | ++++ b/src/lib/atoms/med.c |
| 23 | +@@ -540,6 +540,7 @@ _lldpctl_atom_get_str_med_location(lldpctl_atom_t *atom, lldpctl_key_t key) |
| 24 | + return NULL; |
| 25 | + case lldpctl_k_med_location_country: |
| 26 | + if (m->location->format != LLDP_MED_LOCFORMAT_CIVIC) break; |
| 27 | ++ if (m->location->data_len < 4) return NULL; |
| 28 | + value = _lldpctl_alloc_in_atom(atom, 3); |
| 29 | + if (!value) return NULL; |
| 30 | + memcpy(value, m->location->data + 2, 2); |
| 31 | +@@ -732,8 +733,11 @@ _lldpctl_atom_iter_med_caelements_list(lldpctl_atom_t *atom) |
| 32 | + { |
| 33 | + struct _lldpctl_atom_med_caelements_list_t *plist = |
| 34 | + (struct _lldpctl_atom_med_caelements_list_t *)atom; |
| 35 | +- struct ca_iter *iter = _lldpctl_alloc_in_atom(atom, sizeof(struct ca_iter)); |
| 36 | +- if (!iter) return NULL; |
| 37 | ++ struct ca_iter *iter; |
| 38 | ++ if (plist->parent->location->data_len < 4 || |
| 39 | ++ *(uint8_t*)plist->parent->location->data < 3 || |
| 40 | ++ !(iter = _lldpctl_alloc_in_atom(atom, sizeof(struct ca_iter)))) |
| 41 | ++ return NULL; |
| 42 | + iter->data = (uint8_t*)plist->parent->location->data + 4; |
| 43 | + iter->data_len = *(uint8_t*)plist->parent->location->data - 3; |
| 44 | + return (lldpctl_atom_iter_t*)iter; |
| 45 | +-- |
| 46 | +2.12.2 |
| 47 | + |
0 commit comments