View Issue Details

IDProjectCategoryView StatusLast Update
0010253libmicrohttpd2Generalpublic2025-09-06 23:01
Reporterarthurscchan Assigned ToKarlson2k Due Date
PriorityhighSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Fixed in VersionGit master 
Summary0010253: Possible Heap Buffer Overflow in libmicrohttpd2 response_auth_digest.c
DescriptionA heap-buffer-overflow is found when adding a Digest auth challenge header. The root cause is an incorrect allocation size in `response_add_auth_digest_challenge_alg()` function that uses the size of a pointer to the header struct rather than the size of the struct itself. Because the code then does pointer arithmetic `new_hdr + 1` (which advances by the size of the struct), the calculated string buffer (`hdr_str`) starts past the end of the allocated block, and later `memcpy()` writes overflow the heap.

Faulty allocation (https://git.gnunet.org/libmicrohttpd2.git/tree/src/mhd2/response_auth_digest.c#n213)

```c
/* ** Allocate ** */
new_hdr = (struct mhd_RespAuthDigestHeader *)
          malloc (sizeof(struct mhd_RespAuthDigestHeader *)
                  + hdr_maxlen + 1);
if (NULL == new_hdr)
  return MHD_SC_RESPONSE_HEADER_MEM_ALLOC_FAILED;
hdr_str = (char *) (new_hdr + 1);
```

The `sizeof(...)` uses `sizeof(struct mhd_RespAuthDigestHeader *)` instead of `sizeof(struct mhd_RespAuthDigestHeader)` which returns the size of pointer(always 8 bytes in x64) instead of the size of the struct. Immediately after, `hdr_str` is computed as `(char*)(new_hdr + 1)`, and **`new_hdr + 1` advances by the size of the struct**, not by the size of a pointer, placing `hdr_str` outside the allocated region.

After the faulty allocation, the function builds the header by repeatedly copying pieces into `hdr_str` (https://git.gnunet.org/libmicrohttpd2.git/tree/src/mhd2/response_auth_digest.c#n304)

```c
memcpy(hdr_str + pos, hdr_pref_realm_pref.cstr, hdr_pref_realm_pref.len);
```

These writes land beyond the end of the originally allocated block and cause overflow.
Additional InformationFound during the ongoing security audit carried out by Ada Logics and facilitated by OSTIF in the libmicrohttpd2 project.
TagsNo tags attached.

Activities

Karlson2k

2025-09-06 14:44

manager   ~0025839

Fixed by 440a56cbdf25cb4c7bb463095a94307d0f67bdd1

Issue History

Date ModifiedUsernameFieldChange
2025-08-14 18:03arthurscchanNew Issue
2025-08-31 14:15Christian GrothoffStatusnew => confirmed
2025-09-06 14:44Karlson2kNote Added: 0025839
2025-09-06 14:45Karlson2kAssigned To => Karlson2k
2025-09-06 14:45Karlson2kStatusconfirmed => resolved
2025-09-06 14:45Karlson2kResolutionopen => fixed
2025-09-06 14:45Karlson2kFixed in Version => Git master
2025-09-06 23:01rootProjectlibmicrohttpd => libmicrohttpd2
2025-09-06 23:01rootCategorydigest authentication (HTTP) => General