Review at  https://gerrit.osmocom.org/7782

osmux: osmux_xfrm_output_pull: Improve checks and log of malformed packets

Related: SYS#4182

Change-Id: I7dc3aa2b699a783d86aa9a9452b9e74084d7a97f
---
M src/osmux.c
1 file changed, 11 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/82/7782/1

diff --git a/src/osmux.c b/src/osmux.c
index a0563d2..03db469 100644
--- a/src/osmux.c
+++ b/src/osmux.c
@@ -85,8 +85,13 @@
                case OSMUX_FT_VOICE_AMR:
                        break;
                case OSMUX_FT_DUMMY:
-                       msgb_pull(msg, osmux_ft_dummy_size(osmuxh->amr_ft,
-                                                          osmuxh->ctr + 1));
+                       len = osmux_ft_dummy_size(osmuxh->amr_ft, osmuxh->ctr + 
1);
+                       if (msgb_length(msg) < len) {
+                               LOGP(DLMUX, LOGL_ERROR, "Discarding bad Dummy 
FT: %s\n",
+                                       osmo_hexdump(msg->data, 
msgb_length(msg)));
+                               return NULL;
+                       }
+                       msgb_pull(msg, len);
                        goto next;
                default:
                        LOGP(DLMUX, LOGL_ERROR, "Discarding unsupported Osmux 
FT %d\n",
@@ -102,9 +107,10 @@
                len = osmo_amr_bytes(osmuxh->amr_ft) * (osmuxh->ctr+1) +
                        sizeof(struct osmux_hdr);
 
-               if (len > msg->len) {
-                       LOGP(DLMUX, LOGL_ERROR, "Discarding malformed "
-                                               "OSMUX message\n");
+               if (msgb_length(msg) < len) {
+                       LOGP(DLMUX, LOGL_ERROR,
+                               "Discarding malformed OSMUX message: %s\n",
+                               osmo_hexdump(msg->data, msgb_length(msg)));
                        return NULL;
                }
 

-- 
To view, visit https://gerrit.osmocom.org/7782
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7dc3aa2b699a783d86aa9a9452b9e74084d7a97f
Gerrit-PatchSet: 1
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pes...@sysmocom.de>

Reply via email to