calref / cboe

Classic Blades of Exile
http://spiderwebforums.ipbhost.com/index.php?/forum/12-blades-of-exile/
Other
174 stars 42 forks source link

Fix #451 #452

Closed NQNStudios closed 2 months ago

CelticMinstrel commented 2 months ago

This isn't really related, but I just realized that the filename += buffer line might be unsafe. I'm not sure if it correctly accounts for the fact that the buffer is known to be 128 characters.

NQNStudios commented 2 months ago

That's here, for conversational reference:

https://github.com/calref/cboe/blob/f4c34a410d04d53106ee0f230cffc5c859e7810b/src/tools/winutil.linux.cpp#L146

Also, is it reading chunks of 128 characters at a time from a command? Why not just read 1 at a time until it reaches the end rather than request more than is known to be there?

CelticMinstrel commented 2 months ago

I don't really know. I assume that requesting 128 characters when there are only 30 characters is fine though.

NQNStudios commented 2 months ago

So, what would make it safe? Setting the index after the end of the buffer to the zero/null terminator? Constructing a std::string before calling += ?

CelticMinstrel commented 2 months ago

I was thinking using std::append instead of +=, as there's a form of that which takes a count. But then I looked at the fgets documentation and realized that it actually reads only 127 characters and adds a null terminator, so += seems to be safe after all.