-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
configuration: improve handling of positional arguments #426
Conversation
Currently getopt_long is configured to support mixing options and positional arguments, but kcov don't use the special "--" argument to tell getopt_long when to stop parsing the executable arguments. Instead the implementation tries to scan the arguments to find an executable, but the implementation is flawed because there are two required positional arguments, and both may be executable. In order to handle positional arguments correctly, configure getopt_long to stop parsing after encountering a positional argument. This change greatly simplified the code, since the pre scanning can be removed. However it may break the workflow of some users. Add a regression test for issue SimonKagstrom#414 Issue SimonKagstrom#414: kcov: error when out-dir is an executable
Thanks a lot, looking good! As for your arch issue, could it be some Linux security change that was made? Before, the yama scope was one thing that affected kcov (and gdb), see https://www.kernel.org/doc/Documentation/security/Yama.txt, although that typically was only for attachment. Here, you're tracing a system binary (python), and maybe there are some new restrictions as to what can be done with those? Sort of like what MacOs does, to prevent people debugging the app store etc... |
Actually, the new test fails in the CI run (not sure why it wasn't run for your PR though?). And I also actually saw an issue with the path resolving with the new master. First before the change:
When I manually pass the full path to the binary to trace, it works, but not the path lookup (sort of what you discussed in the other bug report, but no segv). |
I received an email with the workflow failure, having configured github to run workflows in my fork. Not sure why the workflow was not run in the upstream repository; maybe a bug in github? The link is https://github.com/perillo/kcov/actions/runs/8301507902. As for security, I also tried setting Did you remember if with the current master there are no errors? It master has no errors, IMHO it is better to revert this PR. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry for the previous messages; in the first case I was not sure I rebuild I checkout at 692d41c, but I can not reproduce your output. As for the bug in master (assuming master after this PR was merged), on my system it works correctly. |
The master bug is MacOS-specific, this fixes it:
Basically it ignored the argument passed to it (incorrectly), which no longer works after your fixes. I'll correct that, and it also explains why I saw it and not you. Not sure about the test though. After the fix above, it also works on my Mac, so I'm not sure what's going on with the CI runs. |
This change also removed calling This may change the hashed value and may cause conflicts, but I'm not sure, since this case is not tested. This patch should restore the original behavior: diff --git a/src/configuration.cc b/src/configuration.cc
index a778d72..a418d3c 100644
--- a/src/configuration.cc
+++ b/src/configuration.cc
@@ -482,7 +482,9 @@ public:
std::string binaryName;
std::string binaryPath = path;
- (void)look_path(path, &binaryPath);
+ if (look_path(path, &binaryPath) < 0)
+ binaryPath = get_real_path(path);
+
std::pair<std::string, std::string> tmp = split_path(binaryPath);
setKey("binary-path", tmp.first);
@@ -492,7 +494,7 @@ public:
{
setKey("target-directory",
fmt("%s/%s.%08zx", outDirectory.c_str(), binaryName.c_str(),
- (size_t)hash_file(get_real_path(binaryPath))));
+ (size_t)hash_file(binaryPath)));
}
else
{ It calls |
Commit 4b4cb9c (Merge pull request SimonKagstrom#426 from perillo/fix-argv-parsing) added a regression test, but the test failed due to ptrace errors on Linux. The "Operation not permitted" error was caused by kcov trying to trace the "/bin/usr/python". The solution is to execute an executable having user permission. Restore the short-test.py executable, and use it instead of python. short-test.py always exits with exit status 0.
@SimonKagstrom I have fixed the test failing in #428. |
Currently
getopt_long
is configured to support mixing options and positional arguments, butkcov
don't use the special "--" argument to tellgetopt_long
when to stop parsing the executable arguments. Instead the implementation tries to scan the arguments to find an executable, but the implementation is flawed because there are two required positional arguments, and both may be executable.In order to handle positional arguments correctly, configure
getopt_long
to stop parsing after encountering a positional argument.This change greatly simplified the code, since the pre scanning can be removed. However it may break the workflow of some users.
Add a regression test for issue #414
NOTES
The current implementation does not break the cli interface, but some user workflow may break.
In this case an alternative implementation is to configure
getopt_long
to report the positional arguments, too (using "-" instead of "+" as theoptstring
prefix).Also note that the current configuration of
getopt
is the original UNIX behavior.ISSUES
This PR took longer than expected because I started to fix some issues with the test suite.
Additionally, after a system update (on Arch Linux) I started to see more failures. These failures can be reproduced on the original implementation, commit 895f21d.
Another issue is the regression test that I added.
The test fails with:
The command works correctly when running it maually, so I assume there is an issue in the test suite environment.
P.S.
Issue #414 has been closed incorrectly. This PR is responsible to close it.