Skip to content

Veracode Flaw (static): Numeric Errors in 5.4.0 #3050

Open

Description

@brookheather

This issue is a follow-up to my previous issue #2925.

We would like to move to the latest jemalloc 5.4.0 which included Veracode fixes for issues found in 5.3.1 but our latest Veracode scan of 5.4.0 has found an issue in jemalloc.c:1137:

This arithmetic operation results in an integer overflow error. Because the result of this calculation is larger than the maximum possible value for this data type, the result may wrap to become a very small, or negative number, therefore providing an unintended value. Integer overflows can often trigger buffer overflows, which can be exploited to execute arbitrary code.

Is it possible to fix this error and release a patched version of 5.4.0 please?

Image

Activity

  1. spredolac commented on Oct 23, 2026

    @spredolac
    Contributor

    @brookheather , any chance you can test the attached PR and if it fails can you attach the full trace ? Thanks

  2. brookheather commented on Oct 27, 2026

    @brookheather
    Author

    @spredolac unfortunately the latest Veracode scan on that PR has found another issue in rtree.c:299 (though I see this code hasn't changed since the last scan?). The original issue is fixed though.

    Image
  3. spredolac commented on Oct 27, 2026

    @spredolac
    Contributor

    @brookheather , thanks, Do you have a expanded path or more details (if you can click on that Data Path column where it says "1 path" and send me expanded text it would be helpful)?

  4. brookheather commented on Oct 27, 2026

    @brookheather
    Author

    This is all I see under the data path:
    Image

  5. spredolac commented on Oct 27, 2026

    @spredolac
    Contributor

    Thanks, the additional details confirm the finding concerns the L2 cache memmove (which is what we suspected).

    The reported memmove appears correctly bounded to us and our tools. l2_cache is declared as rtree_ctx_cache_elm_t l2_cache[RTREE_CTX_NCACHE_L2], with RTREE_CTX_NCACHE_L2 = 8. The operation copies seven entries from indices 0–6 to 1–7, entirely within that array; memmove supports the overlap.

    On a typical 64-bit build, this is a 112-byte copy into 112 bytes of remaining array space. The stack fallback contains the complete rtree_ctx_t object and remains alive throughout the lookup. The copy length is compile-time constant and independent of runtime input.

    Could Veracode review finding 14 / CWE-121 as a potential false positive and provide the destination size and copy length inferred by its analysis? I suspect not, but wanted to check. Without further evidence of an overflow, I would prefer to keep memmove, since it expresses the intent more clearly than a loop.

  6. brookheather commented on Oct 28, 2026

    @brookheather
    Author

    I have raised a false positive review with Veracode using your analysis - I will inform you of their reply. Would it make much difference to just use a loop here?

  7. spredolac commented on Oct 29, 2026

    @spredolac
    Contributor

    This gets auto-closed when I merge associated PR. So, loop would be semantically equivalent and compiler would in some cases generate exactly the same code (on my server it did for something like this)

    for (unsigned i = RTREE_CTX_NCACHE_L2 - 1; i > 0; --i) {
          rtree_ctx->l2_cache[i] = rtree_ctx->l2_cache[i - 1];
    }
    

    but we find

    memmove(&rtree_ctx->l2_cache[1],
          &rtree_ctx->l2_cache[0],
          sizeof(rtree_ctx->l2_cache[0]) * (RTREE_CTX_NCACHE_L2 - 1));
    

    expressing intent a bit more clearly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions