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

getopt_long returns an int, not a char, and this matters a lot #103

Closed
nwf-msr opened this issue Jun 28, 2022 · 0 comments · Fixed by #104
Closed

getopt_long returns an int, not a char, and this matters a lot #103

nwf-msr opened this issue Jun 28, 2022 · 0 comments · Fixed by #104

Comments

@nwf-msr
Copy link
Contributor

nwf-msr commented Jun 28, 2022

char c;
contains a tragically common and subtle error; it should be int, not char, so that the comparison to -1 in

httpdirfs/src/main.c

Lines 204 to 206 in d1a10d4

while ((c =
getopt_long(argc, argv, short_opts, long_opts,
&long_index)) != -1) {
works portably. As written, it is broken on Arm for example, and the compiler will instead generate an infinite loop; see, for example, https://poudriere.cheribsd.org/hosts/freebsd-arm64/data/latest-per-pkg/fusefs-httpdirfs/1.2.3/cheribsd-aarch64-main.log, which says:

src/main.c:206:39: warning: result of comparison of constant -1 with expression of type 'char' is always true [-Wtautological-constant-out-of-range-compare]
                        &long_index)) != -1) {

Unfortunately, this small error means that we always take the error path at

httpdirfs/src/main.c

Lines 76 to 81 in d1a10d4

if (parse_arg_list(all_argc, all_argv, &fuse_argv, &fuse_argc)) {
/*
* The user basically didn't supply enough arguments, if we reach here
* The point is to print some error messages
*/
goto fuse_start;
and, crucially, skip over the rest of the setup, both of the mountpoint and the network. For maximum confusion, though, because we haven't actually done anything wrong (because we haven't done anything at all, in some sense), the process ends up parked reading from /dev/fuse as it should, but without the mountpoint established, so it's listening for a message that's never coming.

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

Successfully merging a pull request may close this issue.

1 participant