balena-io-modules / drivelist

List all connected drives in your computer, in all major operating systems
Apache License 2.0
239 stars 90 forks source link

windows: GetEnumeratorName() returns pointer to stack #382

Closed maxnet closed 3 years ago

maxnet commented 3 years ago

https://github.com/balena-io-modules/drivelist/blob/master/src/windows/list.cpp#L71

In GetEnumeratorName() you create a char array variable "buffer" on the stack. What you put on the stack is only guaranteed to be there during the scope of the function. At the end of the function you return a pointer to said variable.

That does not look quite right... Suggest you let your functions return std::string instead of "char *"