From a268857bebe544f07833bc997e848b754f98a153 Mon Sep 17 00:00:00 2001 From: Juan Marcos Torero <134594236+juan-marcos-t@users.noreply.github.com> Date: Tue, 16 Dec 2025 12:42:00 +0100 Subject: [PATCH 1/4] Fix issue #6 Fixes potential null pointer dereference, as on the original condition, if pSh2->opData.getProdIds.pProdIds was ever 0 (NULL) code will enter the if body and accessing pSh2->opData.getProdIds.pProdIds->numEntries will cause a null pointer dereference --- sh2.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sh2.c b/sh2.c index 39d055f..cc4e424 100644 --- a/sh2.c +++ b/sh2.c @@ -887,9 +887,11 @@ static void getProdIdRx(sh2_t *pSh2, const uint8_t *payload, uint16_t len) } // Complete this operation if there is no storage for more product ids - if ((pSh2->opData.getProdIds.pProdIds == 0) || - (pSh2->opData.getProdIds.nextEntry >= pSh2->opData.getProdIds.expectedEntries)) { - + if (pSh2->opData.getProdIds.pProdIds == 0){ + opCompleted(pSh2, SH2_OK); + return; + } + if (pSh2->opData.getProdIds.nextEntry >= pSh2->opData.getProdIds.expectedEntries) { pSh2->opData.getProdIds.pProdIds->numEntries = pSh2->opData.getProdIds.nextEntry; opCompleted(pSh2, SH2_OK); } From d0182a277976407a01f1baf16b17770c094c1a2e Mon Sep 17 00:00:00 2001 From: Juan Marcos Torero <134594236+juan-marcos-t@users.noreply.github.com> Date: Tue, 16 Dec 2025 12:46:40 +0100 Subject: [PATCH 2/4] Fixes #16 Fix incorrect order of arguments on q_to_ypr, match header definition on source file --- euler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/euler.c b/euler.c index c689321..0cc9a1f 100644 --- a/euler.c +++ b/euler.c @@ -58,7 +58,7 @@ float q_to_roll(float r, float i, float j, float k) return roll; } -void q_to_ypr(float r, float i, float j, float k, float *pYaw, float *pPitch, float *pRoll) +void q_to_ypr(float r, float i, float j, float k, float *pRoll, float *pPitch, float *pYaw) { // convert to Euler Angles float num = 2.0f * i * j - 2.0f * r * k; From 83449ce14354c4381bc2d838428acbef15872f27 Mon Sep 17 00:00:00 2001 From: Juan Marcos Torero <134594236+juan-marcos-t@users.noreply.github.com> Date: Tue, 16 Dec 2025 14:03:24 +0100 Subject: [PATCH 3/4] Fixes #12 Move channel check in RX assembly before sequence check to avoid possible segmentation fault when accessing pShtp->chan[chan].nextInSeq if channel number is bigger than channel array length --- shtp.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/shtp.c b/shtp.c index ebce552..f372a82 100644 --- a/shtp.c +++ b/shtp.c @@ -198,6 +198,17 @@ static void rxAssemble(shtp_t *pShtp, uint8_t *in, uint16_t len, uint32_t t_us) chan = in[2]; seq = in[3]; + if (chan >= SHTP_MAX_CHANS) { + // Invalid channel id. + pShtp->rxBadChan++; + + if (pShtp->eventCallback) { + pShtp->eventCallback(pShtp->eventCookie, SHTP_BAD_RX_CHAN); + } + return; + } + + if (seq != pShtp->chan[chan].nextInSeq){ if (pShtp->eventCallback) { pShtp->eventCallback(pShtp->eventCookie, @@ -212,16 +223,6 @@ static void rxAssemble(shtp_t *pShtp, uint8_t *in, uint16_t len, uint32_t t_us) } return; } - - if (chan >= SHTP_MAX_CHANS) { - // Invalid channel id. - pShtp->rxBadChan++; - - if (pShtp->eventCallback) { - pShtp->eventCallback(pShtp->eventCookie, SHTP_BAD_RX_CHAN); - } - return; - } // Discard earlier assembly in progress if the received data doesn't match it. if (pShtp->inRemaining) { From f38f53306f972b324c3855817bf10eddb463352a Mon Sep 17 00:00:00 2001 From: Juan Marcos Torero Date: Tue, 16 Dec 2025 14:53:12 +0100 Subject: [PATCH 4/4] Revert d0182a2 and fix #16 instead by changing header, as function name implies yaw-pitch-roll order. --- euler.c | 2 +- euler.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/euler.c b/euler.c index 0cc9a1f..c689321 100644 --- a/euler.c +++ b/euler.c @@ -58,7 +58,7 @@ float q_to_roll(float r, float i, float j, float k) return roll; } -void q_to_ypr(float r, float i, float j, float k, float *pRoll, float *pPitch, float *pYaw) +void q_to_ypr(float r, float i, float j, float k, float *pYaw, float *pPitch, float *pRoll) { // convert to Euler Angles float num = 2.0f * i * j - 2.0f * r * k; diff --git a/euler.h b/euler.h index a694adb..4ac6ac5 100644 --- a/euler.h +++ b/euler.h @@ -29,6 +29,6 @@ float q_to_roll(float r, float i, float j, float k); // Get Yaw, Pitch and Roll from quaternion void q_to_ypr(float r, float i, float j, float k, - float *pRoll, float *pPitch, float *pYaw); + float *pYaw, float *pPitch, float *pRoll); #endif