Bug: Fix memory leak on param handling#7539
Merged
Merged
Conversation
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
Member
|
I checked how this was handled for other services. For WFS a helper function is used: static int msWFSSetParam(char **ppszOut, cgiRequestObj *request, int i,
const char *pszExpectedParamName) {
if (strcasecmp(request->ParamNames[i], pszExpectedParamName) == 0) {
if (*ppszOut == NULL)
*ppszOut = msStrdup(request->ParamValues[i]);
return 1;
}
return 0;
}
// if (msWFSSetParam(&(wfsparams->pszVersion), request, i, "VERSION")) {}This has slightly different logic as it keeps the first parameter supplied in the querystring. We should also add some tests for duplicated parameters. |
Contributor
Author
|
I have changed the logic mirror the msWFSSetParam approach. |
Contributor
|
just pushed in https://github.com/arthurscchan/MapServer/tree/fix-memleak a modified msautotest check exercising duplicated parameters in WCS queries |
jratike80
reviewed
Jul 3, 2026
| # RUN_PARMS: wcs_cap.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WCS&VERSION=1.0.0&REQUEST=GetCapabilities" > [RESULT_DEVERSION] [RESULT_DEMIME] | ||
| # RUN_PARMS: wcs_cap.txt [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WCS&VERSION=1.0.0&REQUEST=GetCapabilities" > [RESULT_DEVERSION] [RESULT] | ||
| # Also test duplicated parameter not to cause memory leak | ||
| # RUN_PARMS: wcs_cap.txt [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WCS&VERSION=1.0.0&VERSION=1.0.0&REQUEST=GetCapabilities" > [RESULT_DEVERSION] [RESULT] |
There was a problem hiding this comment.
Should we test also `&VERSION=1.0.0&VERSION=2.0.0, if the aim is to keep just the first parameter value?
Member
There was a problem hiding this comment.
Yes probably best to have a test that confirms this. I'm not sure what the spec says about this case.
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.
When a parameter is matched, its value is duplicated and stored in the param object, overwriting any existing value without first freeing the previously allocated pointer. This causes a direct memory leak whenever the same parameter name appears more than once in a request.
This PR fixes the leak by always clearing the target pointer before assigning the new value during each parameter's processing. The change is safe even for null pointers, as msFree() accepts a null pointer and is a no-op in that case.
This memory leak is discovered by the new fuzzer introduced in #7525.