#9585 closed Bugs (fixed)
program_option::environment_iterator moves past terminating NULL pointer
Reported by: | Owned by: | Vladimir Prus | |
---|---|---|---|
Milestone: | To Be Determined | Component: | program_options |
Version: | Boost 1.55.0 | Severity: | Problem |
Keywords: | Cc: |
Description
The get() method increments m_environment outside of the else scope:
void get() {
if (*m_environment == 0)
found_eof();
else {
std::string s(*m_environment);
std::string::size_type n = s.find('=');
assert(n != s.npos);
value().first = s.substr(0, n);
value().second = s.substr(n+1);
}
++m_environment;
}
This means the iterator will move past the terminating pointer. A simple fix seems to include the increment in the else's scope.
Change History (2)
comment:1 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 by , 9 years ago
No, I did not. I noticed it when working on a dirty hack to get program_options to work with c++0x using Windows' GetEnvironmentStrings where I consequently had to touch this routine.
A segmentation fault might obviously occur when other codes doesn't just use the pointer semantics as get() is public, but that's probably not what's considered a practical issue. Thanks for the quick response tho!
Fixed in https://github.com/boostorg/program_options/commit/f50b02750a7b17ec6a149c0264bef5727a8df1f6
Did you see any practical issues as result of this?