Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

args-parser.h is somewhat unsafe, and used incorrectly #64

Open
fingolfin opened this issue Oct 11, 2016 · 0 comments
Open

args-parser.h is somewhat unsafe, and used incorrectly #64

fingolfin opened this issue Oct 11, 2016 · 0 comments

Comments

@fingolfin
Copy link
Contributor

The code in args-parser.h is quite unsafe, as it is very easy to specify incorrect types (e.g.TYPE_INT) when using it.

Indeed, this already is the case in lots pf places throughout your codebase: You use TYPE_INT but pass a pointer to a variable of type size_t. But on many systems (e.g. Linux and OS X in 64bit mode) an int is 4 bytes while a size_t is 8 bytes. Now, if the variable that was passed in has its upper bytes cleared, and you are running ona little endian machine, that happens to work right; but in general, it wont'.

At the very least, it would be good to audit all existing uses of the function, to verify the pointers being passed in match the TYPE_FOO specifier. Better would be of course if this was automatically verified. Either by rewriting the existing code (one quick idea that comes to mind is to replace the naive Argument[] array by a std::vector<Argument>, and change `Argument to a proper class, with multiple constructors for the different types; that should get rid of the need to explicitly specify a TYPE_FOO value, too). Or switch to an existing robuse C++ argument parser library (e.g. https://github.com/jarro2783/cxxopts, http://optionparser.sourceforge.net/ or some part of Boost).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant