-
Notifications
You must be signed in to change notification settings - Fork 79
[#570] Prevent segfault when accessing scalar config values with dotted keys #580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Do we have a better approach to understand if a result is an invalid object? |
I’m not sure if it's necessarily better, but I can think of a few more possible approaches to handle this:
|
@Jubilee101 Cc: |
This is what we should go for, because it makes the interface consistent (everything is an object) and stable. |
Second this. The value type system is designed on the assumption that users know what types they had put in when they try reading it out. So all the outcome should perhaps be json. |
I explored the idea of modifying the implementation to wrap scalar values before returning them from But after looking into it more deeply, I think this approach would introduce unnecessary complexity. Right now, the code assumes that we know what we’re putting in and getting out — which is why we do things like:
If we start wrapping scalars, we’d need to:
That alone would touch a lot of code and introduce risk. There is a second approach I considered — modifying the (1) Current JSON Structure: {
"Header": {
"ClientVersion": "2.0.0",
"Command": 3,
"Compression": 0,
"Encryption": 0,
"Output": 0,
"Timestamp": "20250715184659"
},
"Request": {}
} (2) Modified JSON Structure (wrapped scalars): {
"Header": {
"ClientVersion": {
"value": "2.0.0"
},
"Command": {
"value": 3
},
"Compression": {
"value": 0
},
"Encryption": {
"value": 0
},
"Output": {
"value": 0
},
"Timestamp": {
"value": "20250715191154"
}
},
"Outcome": {
"Error": {
"value": 2
},
"Status": {
"value": false
}
},
"Request": {}
} This modified format keeps things consistent and simplifies value extraction logic across the board. However, it still comes with some drawbacks:
In the end, this feels like a large change to fix a relatively small issue (a segmentation fault), which already has a simpler workaround (like the iterative approach I proposed earlier). So from a practicality standpoint, I’d suggest sticking with the current implementation. That said, if we do want to move forward with modifying the JSON APIs, we should first have a more detailed discussion:
If we decide to go this route, it should definitely be done in a separate PR, as it touches core behavior. Let me know your thoughts — I’m happy to help implement the change if we agree on a direction. |
@Userfrom1995 I don't like it - it shouldn't be necessary to wrap all JSON values |
@Userfrom1995 What is important is to create a chapter / appendix in the developer that describes the format (name/type) and so on |
@Userfrom1995 this is an excellent and detailed analysis, and while I think wrapping is still the right path to get things done, it requires too many changes so far, and probably has also a runtime impact we don't want for a few scalar values. |
@Jubilee101 will look at it - so hold |
@Userfrom1995 See #592 |
Previously, querying a scalar configuration value (e.g., "port" or "max_connections") with a dotted key (like "port.a") would cause a segmentation fault. This happened because the JSON API returned a scalar value cast as a pointer, which was then incorrectly treated as a JSON object.
This commit adds a defensive check:
if ((uintptr_t)configuration_js < 0x1000)
to ensure that only valid JSON object pointers are passed to the iterator logic. If a scalar or invalid pointer is detected, the code now gracefully returns an error instead of crashing.
Before Changes:
After Changes :