On 2023/04/10 12:41, Lianbo Jiang wrote: > The man page of the "fuser" command suggests that the argument can be a > full pathname or inode address. However, the "fuser" command accepts an > invalid argument and prints a bogus result as below: > > crash> fuser x > PID TASK COMM USAGE > 100507 ffff9914431f4c80 "packagekitd" fd > 100508 ffff991574e59980 "gmain" fd > 100509 ffff9914431f3300 "gdbus" fd > 102020 ffff991574400000 "sshd" fd > 102043 ffff991441d19980 "sshd" fd > > The current fuser command has no checking mechanism to determine if an > argument is valid or not. Lets add it to handle such cases. > > With the patch: > crash> fuser x > fuser: invalid argument: x > > In addition, also add a note that fuser does not expect an argument other > than an inode address and full pathname, if others are specified, the output > can be an unexpected result. > > Reported-by: Buland Kumar Singh <bsingh@xxxxxxxxxx> > Signed-off-by: Lianbo Jiang <lijiang@xxxxxxxxxx> > --- > filesys.c | 8 +++++++- > help.c | 3 +++ > 2 files changed, 10 insertions(+), 1 deletion(-) > > diff --git a/filesys.c b/filesys.c > index d64b54a9b822..307da05a774f 100644 > --- a/filesys.c > +++ b/filesys.c > @@ -3421,7 +3421,13 @@ cmd_fuser(void) > > doing_fds = doing_mmap = 0; > while (args[optind]) { > - spec_string = args[optind]; > + ulong spec_addr; > + spec_string = args[optind]; > + spec_addr = htol(spec_string, RETURN_ON_ERROR|QUIET, NULL); > + if ((spec_addr == BADADDR || !IS_KVADDR(spec_addr)) && > + spec_string[0] != '/') > + error(FATAL, "invalid argument: %s\n", args[optind]); > + > if (STRNEQ(spec_string, "0x") && hexadecimal(spec_string, 0)) > shift_string_left(spec_string, 2); > len = strlen(spec_string); > diff --git a/help.c b/help.c > index 9a5cd3615589..ded4ee19d955 100644 > --- a/help.c > +++ b/help.c > @@ -7990,6 +7990,9 @@ char *help_fuser[] = { > " listed.\n", > " pathname the full pathname of the file.", > " inode the hexadecimal inode address for the file.", > +" Note: fuser does not expect an argument other than an inode address", > +" and a full path, and if others are specified, the output can", > +" be an unexpected one.", > "\nEXAMPLES", > " Display the tasks using file /usr/lib/libkfm.so.2.0.0\n", > " %s> fuser /usr/lib/libkfm.so.2.0.0", Thanks for the update, applied with a few tweaks. https://github.com/crash-utility/crash/commit/538b9ed4564d90d133db7694fd49d1bf3be733f0 Thanks, Kazu -- Crash-utility mailing list Crash-utility@xxxxxxxxxx https://listman.redhat.com/mailman/listinfo/crash-utility Contribution Guidelines: https://github.com/crash-utility/crash/wiki