Use after free in Util : GetServerName (called by CreateUser) #8575
Replies: 1 comment 1 reply
-
@bevanweiss For not having C/C++ as your strong suite, you do have eagle eyes. As of right now, there's only one caller to that method, and the caller does not explicitly free the returned string. In the case where You're right that the fix needs to be to dup the returned string and have the caller always explicitly free it. My vote would be to fix it. I'd be willing to submit a PR if the maintainers assign an issue to me. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I wouldn't say that C/C++ is my strong suite, and perhaps there's tricks around the Microsoft memory allocations that I'm just not aware of
In the code chunk below, it appears there's two situations with a use after free on the server name.
https://github.com/wixtoolset/wix/blob/64fc1bc29460db8b525d2817078e1a40a197b4c9/src/ext/Util/ca/scaexec.cpp#L718-L754
Can someone correct me on my error here..?
It seems the safest thing to do would have been to declare pwzDomain as LPCWSTR, and then in all three exit cases do a _wcsdup instead of the assignment.
In this way when the NetApiBuffer is returned, we don't touch it afterwards, and there's no confusion in the caller around whether it should free ppwzServerName's string, or pwzDomain.
Beta Was this translation helpful? Give feedback.
All reactions