Skip to content
New issue

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

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

Already on GitHub? # to your account

Fail early if argc <= 0 or argv[0] is NULL #92

Closed
wants to merge 1 commit into from

Conversation

EliteTK
Copy link

@EliteTK EliteTK commented Jan 26, 2022

Under musl optind will be 1 if getopt is called with argc == 0.
Under glibc it is not quite clear what will happen and I haven't tested
it.

In either case, this triggers a bug where argv ends up pointing at
envp and argc is set to -1 which has further unclear implications on the
execution of the program.

By failing early, these issues can be safely avoided.

fputs and exit are used instead of errx as errx does not have the
information necessary to print a meaningful program name.

Under musl optind will be 1 if getopt is called with argc == 0.
Under glibc it is not quite clear what will happen and I haven't tested
it.

In either case, this triggers a bug where argv ends up pointing at
envp and argc is set to -1 which has further unclear implications on the
execution of the program.

By failing early, these issues can be safely avoided.

fputs and exit are used instead of errx as errx does not have the
information necessary to print a meaningful program name.
@ericonr
Copy link

ericonr commented Jan 26, 2022

fputs and exit are used instead of errx as errx does not have the information necessary to print a meaningful program name.

It calls setprogname before that, though. Is it not enough?

@EliteTK
Copy link
Author

EliteTK commented Jan 26, 2022

@ericonr no. setprogname is handled by libopenbsd and err* are all provided by libc (as bsd extensions). (I first tested this patch with errx and it definitely didn't work which is why I changed to using fputs.)

@Duncaen
Copy link
Owner

Duncaen commented Jan 26, 2022

Thanks, merged this into a new branch for the last release and tagged a release https://github.com/Duncaen/OpenDoas/releases/tag/v6.8.2.

@EliteTK
Copy link
Author

EliteTK commented Jan 26, 2022

I'm closing this since it has been merged in a way which github doesn't appear to understand.

@EliteTK EliteTK closed this Jan 26, 2022
@EliteTK EliteTK deleted the argc-is-zero branch January 26, 2022 22:20
Fr1tzBot added a commit to Fr1tzBot/OpenDoas that referenced this pull request Aug 27, 2024
Fix for empty argv handling.

This release adds a patch[0] from PR[1] to aborting early if argv is not set or
empty.
Nothing else has changed in this patch release.

[0]: Duncaen@7f0205f
[1]: Duncaen#92

# -----BEGIN PGP SIGNATURE-----
#
# iQIzBAABCgAdFiEExLb7qYIR9+/zXetzM1wdF+w9bjUFAmHxcmAACgkQM1wdF+w9
# bjXdZxAArPzkuPrw1/79d+jq8JGbDYYaOYkYcaa+W9+09E6wfCMRNhIwL68v9G9Y
# yPgb0+ZOwqnDsaRX8GsKS417aSKyBwTWruUsdlS1y7bilphqmrw1LaulYjEZd7w3
# GZH/xI+6aBb5F25ZUIGsvPxMnq37AH7E29XHQ463qI1n2jO++8Ucu+EuUd/H7BAn
# sgmzdbLPuvtkio//kwZ0b7crtI4EGXsGn4h0mcE9ETd6gf9HCstOY8N3ntDQXtOG
# LECfAk+IKW6sGzoKwZLGNvi6zU9Dgllcq3avPa2UxqgAw4R85KD49JJHHyOFbC5k
# ZdnmkJypBoK+GnEjw38YOZE+TRumtI4MHn7tRPcQHQ8VahGkjIRedZsmmT7Qfld3
# QWKJKfPWGEhAQ83rka9lXHrhQddWKplwRwt4U4R6eytzAhDdf9HGXUSILBdAUxfJ
# wH9yvfqt5E/Ky7fLI8AajCp7MUEPtGiSm+tsWmsjLV/6hxTbS9l3QpoBcC9hLyG3
# Kfq6uMX1x0nKtKPPJYtNUT7zcNfDSEGfY2KAXFe2rVhhXlXeFe9trNgVMVtSXUV2
# 2fSdKBXH2JmQKkMAWEMhgJb+wr5sJHz73l//KEbxEHlwH+JwETpE1JGkamI/NN+p
# 0W0vc786ZH+irampES2/3HX2QfbqWQ8kuDDAS8t+E8ePxZFPZkU=
# =4mWZ
# -----END PGP SIGNATURE-----
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants