Git Product home page Git Product logo

Comments (3)

bergzand avatar bergzand commented on June 19, 2024

Thanks for the report, this is indeed a bug.

It is caused by the nanocbor_skip call that overwrites the res value returned by the nanocbor_get_key_tstr call. This means that if the final element of the map is skipped with nanocbor_skip and the key is not found, the res value is taken from the nanocbor_skip call and returned.

I'll have a fix out asap

from nanocbor.

bergzand avatar bergzand commented on June 19, 2024

I have to check if I don't cause a regression here, but I think this patch should fix your issue:

diff --git a/src/decoder.c b/src/decoder.c
index 80e69f2..2fc2282 100644
--- a/src/decoder.c
+++ b/src/decoder.c
@@ -433,8 +433,9 @@ int nanocbor_get_key_tstr(nanocbor_value_t *start, const char *key,
         const uint8_t *s = NULL;
         size_t s_len = 0;
 
-        if ((res = nanocbor_get_tstr(value, &s, &s_len)) < 0) {
-            break;
+        int call_res = NANOCBOR_OK;
+        if ((call_res = nanocbor_get_tstr(value, &s, &s_len)) < 0) {
+            return call_res;
         }
 
         if (s_len == len && !strncmp(key, (const char *)s, len)) {
@@ -442,8 +443,8 @@ int nanocbor_get_key_tstr(nanocbor_value_t *start, const char *key,
             break;
         }
 
-        if ((res = nanocbor_skip(value)) < 0) {
-            break;
+        if ((call_res = nanocbor_skip(value)) < 0) {
+            return call_res;
         }
     }

from nanocbor.

CromSoldier avatar CromSoldier commented on June 19, 2024

Hi, I also stubbled upon the same issue.
Did you test for regression ?

from nanocbor.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.