-
-
Notifications
You must be signed in to change notification settings - Fork 673
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
Fix exporting LESSOPEN #288
Conversation
Thank you for your contribution! I think the check for an empty
|
I didn't found it in lesspipe script code.
If we are talking about "original" lesspipe then this is code responsible for output when no arguments are supplied to script:
Only difference is when dealing with csh. Since we are dealing here with bash exclusively we can just use this code. I think it is safer not to use eval as much as possible and it solves problems between lesspipe implementations. It also causes less overhead as we do not spawn another processes. Moreover Gentoo handles setting LESSOPEN itself and maybe some others distributions do this also.
Yes I am Gentoo user and I've made this fix because of those errors. This blind fix is what is says: blind. It does not solve anything because error is generated by Gentoo flavor of lesspipe not by defining which SHELL we are going to use. |
I'm not sure which is the original lesspipe and which version of the original lesspipe you are talking about, but there seem to be systems whose
Do you mean these errors are still present after "the blind fix #74"? If so, I'm not sure if this PR is the right fix. According to the man pages, Could you explain why |
I was referring to https://github.com/wofr06/lesspipe. I used quotes for word "original" because I didn't found better maybe I should use "most popular". Gentoo have available this version in packages and saves it as lesspipe.sh. According to links You have provided the only difference in output is existence of aforementioned LESSCLOSE variable which seems be missing in today implementations at least those I've managed to find out - others must be not very popular it seems. Other thing is that links are very old also and represents outdated informations.
Yes they are.
If so then problem exists in not standardized lesspipe implementations. Man page is referring to implementation that You are mentioning I think it is not standard - fix me if I am wrong on this.
Gentoo use it's own implementation of lesspipe which expects arguments and produces message if not provided. This message is evaluated and this produces error message "bash: syntax error near unexpected token `newline'". Gentoo sets itself LESSOPEN variable, never LESSCLOSE. Using eval is insecure in my opinion. We are trusting that all implementations will behave the same and output of executed command without arguments will be valid and safe shell code. |
For readability I will put my edit in separate message:
I am not using "result of lesspipe of the specific version in the specific system" - Value of LESSOPEN for less is consistent between all versions from at least 10 years. It contains pipe character '|' then path to or name of script lesspipe and %s parameter. Gentoo set is as:
I think if devs of Gentoo put this to base system env variables we can also trust that it will not change. Aforementioned: |
Thank you for your explanation! OK, I think I now see the problem. So, the Gentoo
I have checked Maybe
Yes, I think so.
You are right. Last night I've quickly checked several man pages of different lesspipe implementations and found that at least two or three implementations accept this type of initialization. But this morning, I checked the real implementations and found that it seems the Fedora/RHEL/CentOS implementation and the FreeBSD don't output anything when it's called without arguments. Instead, they provide
Thanks for the explanation. As I have written above, I now understood the situation. Now I'm wondering why Gentoo's implementation outputs the error message to
I'm not sure if we can say insecure in the sense that we are finally going to run the
What do you mean by all versions? I don't think you have checked "all" the Unix-like systems of the last decade, which include Linux distributions, *BSD, macOS/OS X/Mac OS X, Minix, AIX, Solaris, Cygwin/MSYS2/MSYS, etc. It's evident from the fact that $ lesspipe
export LESSOPEN="| /usr/bin/lesspipe %s";
export LESSCLOSE="/usr/bin/lesspipe %s %s"; In the five systems I've checked---Fedora 35 and 30, RHEL 8.5, CentOS 8.3, and Scientific Linux 7.7 (where the initialization is made in $ declare -p ${!LESS@}
declare -x LESSOPEN="||/usr/bin/lesspipe.sh %s"
Yeah, I've also noticed this inconsistency in working on this PR and was thinking of addressing it as a separate issue. Also, it seems there are two variations, I feel we need to collect more information on Gentoo's own implementation. Why do they output error messages to stdout instead of stderr? Is there a chance that the configuration of the upstream Gentoo would be updated? Besides, we also need to think about how to work around the problem in existing Gentoo systems. |
Wow great job checking all those systems! I should do a better research. I will change this PR to Draft for now. First quick clarification on one thing:
It is not error message it is just message.
But from our point of view this behavior is also unwelcome because we are need to set up LESSOPEN. So summarizing differences between those implementations and systems that You have checked are:
As I said above this isn't error message it's just usage message. Personally I do not see anything wrong with this. If we must stay with eval then my proposed solution (based on points above): |
Thank you for the nice summary!
Oh, I see. Then
Some remark: In some systems, the default
OK, the behavior isn't that strange as a Unix command. But I still think we may ask if they would change the behavior or not since outputting usage to stderr for the unexpected usage is also another understandable behavior. Or maybe we can suggest outputting the shell initialization code for the execution without arguments in line with other implementations, which is more constructive.
What happens in Gentoo with this treatment? I think this solves the problem if In addition, maybe we can check the output of lesspipe/lesspipe.sh before passing it to For example, we store the result of |
You are right - incorrect usage / missing argument should be reported to stderr.
We can recognize Gentoo system and do according so. AFAIK file /etc/gentoo-release should be present on Gentoo system.
I feel it is a hacky solution. But if we are suppose to search for keywords it's better to search for I was curious why double pipe || is present on RedHat-like distros and found this: I've recreated mentioned bug and fixed it by adding second pipe at the begin. I've tested also behavior on some pdfs and bins and it also worked correctly as it should. I've also studied less man pages (which should I do at the very beginning) where everything is nicely explained why and when we use LESSOPEN, LESSCLOSE, single, double and no pipes. So basing on all this I am pretty sure that we could use version with double pipe |
The nice investigation, thank you!
Are you going to ask it to the upstream? If not, maybe I can ask it to the Gentoo upstream, but I don't know which Gentoo package provides
What do you mean by the default one? If I'd write a new implementation of Anyway, I think now you can update the PR to cover the above discussions. Then I'll again review it. |
I've already found where this file came from. Theoretically it's part of the sys-apps/less package but script itself is added after compilation during intallation from portage tree files directly. It is not in less source files. I will take care of this in a free moment.
Scratch that. It does not works. |
Et voilà monsieur! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I think this is mostly fine. I have additional comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Now LGTM. This is still marked as a draft, but do you have any plan to update it further?
Nope. |
OK, thank you for your PR and quick responses to requests. Let us now merge the PR. |
Do not use eval and export LESSOPEN directly only when is empty.
This will prevent problems on distributions using different lesspipe
and/or defining LESSOPEN variable on their own.
Issue #46 #69
Fixes #46 / Fixes #69 / Fixes #296