Issue 7547 - Heap buffer overflow in ldap_utf8prev()#7548
Open
IliaKash1 wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="ldap/servers/slapd/str2filter.c" line_range="319-323" />
<code_context>
+ if ((s = strchr(str, '=')) == NULL || s == str) {
return (NULL);
}
+ for (char *p = s; (((unsigned char)p[-1]) & 0xC0) == 0x80; --p) {
+ if (p - 1 == str) {
+ return NULL;
+ }
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Guard the loop against going past the start of the buffer by including the pointer bound in the loop condition instead of relying on the body.
Currently the safety of `p[-1]` depends on `if (p - 1 == str) return NULL;` executing before `--p` makes `p == str`, which is correct but subtle and easy to break with later changes. Encoding the boundary directly in the loop header, for example:
```c
for (char *p = s; p > str && (((unsigned char)p[-1]) & 0xC0) == 0x80; --p) {
if (p - 1 == str) {
return NULL;
}
}
```
keeps the body focused on semantics and makes the safety invariant obvious, reducing the risk of future out-of-bounds access.
```suggestion
for (char *p = s; p > str && (((unsigned char)p[-1]) & 0xC0) == 0x80; --p) {
if (p - 1 == str) {
return NULL;
}
}
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Congratulations! One of the builds has completed. 🍾 You can install the built RPMs by following these steps:
Please note that the RPMs should be used only in a testing environment. |
progier389
requested changes
Jun 3, 2026
| if ((s = strchr(str, '=')) == NULL || s == str) { | ||
| return (NULL); | ||
| } | ||
| for (char *p = s; (((unsigned char)p[-1]) & 0xC0) == 0x80; --p) { |
Contributor
There was a problem hiding this comment.
I do not think that we need a for loop here:
Using:
if (p[-1] & 0x80) {
return NULL;
}
is enough to determine that p[-1] is not an ascii char
and that the filter string is is not compliant to filter ABNF defined in RFC 4515
Bug description: Heap buffer overflow in ldap_utf8prev() can be triggered via str2simple if '=' is not preceded by proper symbols. Fix description: Additional checks are added to account for '=' being preceded by nothing or by non-ASCII bytes. Fixes: 389ds#7547 Author: Ilia Kashintsev Reviewed by: @progier389 (Thanks!)
Contributor
|
This ticket is linked with IDM-6709 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug description:
Heap buffer overflow in ldap_utf8prev() can be triggered via str2simple if '=' is not preceded by proper symbols.
Fix description:
Additional checks are added to account for '=' being preceded by nothing or by non-ASCII bytes.
Fixes: #7547
Author: Ilia Kashintsev
Summary by Sourcery
Bug Fixes: