3 ms·
rc = libcox_exec_fmt(pHandle,&pResult,"ls '%s'",zDir); /*Don't forget the single quotes around 'zDir' */ This is either insecure, or so different from a shell
by geofft 11y ago
rc = libcox_exec_fmt(pHandle,&pResult,"ls '%s'",zDir); /*Don't forget the single quotes around 'zDir' */
This is either insecure, or so different from a shell as to make it not worth using shell syntax.
I really like the concept though. Took me to figure out what the concept is because "system calls" doesn't mean "shell commands" to me, but having figured that out, operating on shell commands has a lot of things going for it.
- symisc_devel 11y agoHi, this is due to the fact that zDir may contain spaces especially under windows which confuse the command processor to interpret it as multiple arguments and not a single one as with single or double quotes (http://libcox.net/arch.html http://libcox.net/arch.html)
- geofft 11y agoWhat happens if zDir contains single quotes?
- stefs 11y agoYou need to escape them, like in every other instance where strings may contain control characters. That'd be my guess, at least, but, i guess, single quotes aren't valid characters for zDir.
- geofft 11y agoSo what are the quote parsing rules for libcox, and given an arbitrary string, how do I correctly escape them? (In the absence of this, and certainly in the absence of official docs/examples that do the right thing, that's a security vulnerability waiting to happen.)
- symisc_devel 11y agoString escaping follows the same rules of C/C++ or you could use the str_escape command to do job for you.
- heinrich5991 11y agoWhy do you take care of space escaping but not others (quotation marks)? This might lead to false expectations, i.e. that you take care of everything, security-wise.