gods breaks the world (a.k.a. sort considered harmful) #123
Labels
No labels
bug
discussion
documentation
duplicate
ignore
new feature
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
golibs/gms-gods#123
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
tl;dr for later readers who come here from google -- see the more concise dockerized example in https://github.com/emirpasic/gods/issues/123#issuecomment-539232054
Can we rename the
sortexample to something likegodsort?sortconflicts with a basic system command....to a project path to install all of the child packages.That combination of factors will break a UNIX or Linux machine. Here's a fun example:
Without the explicit
hash -r, the failure mode is even more subtle, only showing up in new shells. I'm going to take the time to add some detail here, both as background and as google fodder for anyone else hitting this.In my case the first symptoms were that
vim-gowasn't runninggurucorrectly a day after I installed a bunch of go dev bits. I spent a while troubleshootingvim-go, finally tracked it down togoenv, and then noticed that bothpyenv init -andgoenv init -were throwing errors when opening new xterms. Here's one of the error messages:That's it. The entirety of the message. That message was showing up when .bashrc ran
eval "$(pyenv init -)". The message originated several shell scripts deep, in some code which was supposed to collect, sort, and uniq the content of$HOME/.pyenv/libexecand include it to the left of a)in acasestatement in a shell script that is generated on the fly and returned to the aboveeval. (Fun, right?)It happens that goenv and pyenv use the same algorithm and similar shell scripts.
I found myself adding lots of
echostatements to those various shell scripts trying to narrow it down -- never tried actually testing the output ofsortitself until hours later, partly because it's buried in the middle of a pipeline. Even after I broke up the pipeline into little pieces and found the emptysortoutput, it still took me a few minutes to figure out what happened:This library does not export sort as a standalone tool (so it should not go into bin) and looking at the result from
which sortit seems that you have implemented this yourself using GoDS sort only as function. You essentially have to rename this within your code to compile your program into something else thansort. Let me know if I have understood the problem correctly here and if that solves your issue, last things GoDS should do is to break the World ;DBut it does. You have an executable, package
main, with amain()function in it, and the path issort/sort.go. That will build an executable namedsort. That executable will wind up in $GOPATH/bin every time anyone saysgo get github.com/emirpasic/gods/....Actually, that's your code. Here it is again, this time in a pristine container, using Docker's official golang docker image -- nothing from me:
Do you have access to a Linux machine or container where you can duplicate this? If so, please do so. If not, then you might want to take my word for it. I lost an entire afternoon to this, first figuring out what broke, then trying my best to provide a complete description of the problem for you, and even sending you pull request #124 so all you have to do is click a button. I included humor as much as I could to soften the blow, but seriously, this is bad.
@stevegt you are right, missed the fact that you stated this to be part of the example, was looking elsewhere given i glazed at this quickly from work.
yes, i am on a linux machine and i can see why it happens. strangely enough i have never noticed this issue. i suppose it's how i've configured my paths for linux tools to take higher precedence than go's bin path.
i'll merge your PR, but i suppose it's wise to do as i have done, rather than allowing some library to override your default linux commands in the background... that is something really really bad, scary actually! :D
Thank you! Yep, I'm going to change the way I configure $PATH on the machines I manage.
That vulnerable $PATH configuration appears in tutorials, the docker image, and in the setup for goenv, which is where I got it from: https://github.com/syndbg/goenv/blob/master/INSTALL.md.
At least the official Go docs don't have the vulnerability. In there, $GOPATH/bin goes last: https://tip.golang.org/doc/code.html#GOPATH
Just a follow-up note that the
goenvpackage's PATH ordering during install is now fixed via pull request https://github.com/syndbg/goenv/pull/100. Thanks again, @emirpasic.