News for hackers. Stuff that matters.
Re:The xz attack shell script by sanderjd on Tuesday April 02, 2024 @08:01PM (#39912167)
Man, this sounds right, but I dunno ... I feel like even "simple" shell scripts tend toward more inscrutability than all but the most questionable python code I've ever written. Just comparing my dotfiles - every bit of which I understood when I wrote them - to the gnarliest sections of a big python app I work on ... I just really feel like at least some of this inscrutability issue can truly be laid at the feet of shell / bash as a language.
Re:The xz attack shell script by clnhlzmn on Tuesday April 02, 2024 @09:48PM (#39912804)
This is totally true and the bash apologists are delusional.
Re:The xz attack shell script by lobocinza on Wednesday April 03, 2024 @12:09AM (#39913520)
It depends on the use case. Bash code can be elegant, Python code can be ugly. I'm not saying those are the average cases but complex code regardless of the language often is ugly even with effort to make it more readable.
Re:The xz attack shell script by clnhlzmn on Wednesday April 03, 2024 @10:40PM (#39925988)
Oh I get it. Sometimes bash is the right tool for the job. I think that’s just mostly an unfortunate historical artifact though. It’s hard to argue it’s intuitive or “clean” or ${POSITIVE_ADJECTIVE} in the average case.
Re:The xz attack shell script by TeMPOraL on Wednesday April 03, 2024 @02:08AM (#39914144)
So are some Python advocates, too. The thing that's worse than a bash script made of Perlish line noise, is a piece of "clean code" dead simple Python that's 80% __language__.boilerplate, 20% logic, smeared over 10x the lines because small functions calling small functions are cool. No one has enough working memory to keep track of what's going on there. Instead, your eyes glaze over it and you convince yourself you understand what's going on.

Also, Python build scripts can be living hell too, full of dancing devils that could be introducing backdoors left and right - just look at your average Conan recipe, particularly for larger/more sensitive libraries, like OpenSSL or libcurl.

Re:The xz attack shell script by _a_a_a_ on Wednesday April 03, 2024 @04:32AM (#39914878)
That's a lot of emotive language, can you actually link to some actual examples.
Re:The xz attack shell script by medstrom on Wednesday April 03, 2024 @06:14AM (#39915500)
I can understand the frustration when those small functions are not well-named, so you have to inspect what they do.
Re:The xz attack shell script by TeMPOraL on Wednesday April 03, 2024 @06:38AM (#39915653)
You already have to inspect everything if you want to review/audit a build script. Small functions - and I specifically mean functions being written small because of misguided ideas of "clean code", as opposed to e.g. useful abstraction or reusability - become especially painful there, as you have that much more code to read, and things that go together logically (or execution-wise) are now smeared around the file.

And you can't really name such small functions well anyway, not when they're broken down for the sake of being small. Case in point, some build script I saw this week had function like `rename_foo_dll_unit_tests` calling `rename_foo_dll_in_folder` calling `rename_foo_dll` calling `rename_dlls`, a distinct call chain of four non-reused functions that should've been at most two functions.

Are all Python build scripts like that? Not really. It's just a style I've seen repeatedly. The same is the case with inscrutable Bash scripts. I think it speaks more about common practices than the language itself (notwithstanding Bash not really being meant for writing longer programs).

Re:The xz attack shell script by medstrom on Wednesday April 03, 2024 @07:27AM (#39916028)
Sounds like DRY run amok indeed. Maybe a compiler or linter could detect these cases and complain "this function is only called from one place" :)
Re:The xz attack shell script by ben_w on Thursday April 04, 2024 @08:16AM (#39929429)
I'm glad I'm not the only one with this particular frustration.
Re:The xz attack shell script by TeMPOraL on Wednesday April 03, 2024 @06:17AM (#39915513)
I mentioned Conan recipes, didn't I? :). Those are my most recent sources of frustration.
Re:The xz attack shell script by _a_a_a_ on Wednesday April 03, 2024 @07:35AM (#39916092)
I've never heard of a conan language, and a couple of URLs to some bad recipes would not go amiss.
Re:The xz attack shell script by TeMPOraL on Wednesday April 03, 2024 @08:20AM (#39916498)
Conan is a package manager for C/C++, written in Python. See: https://conan.io/.

The way it works is that you can provide "recipes", which are Python scripts, that automate the process of collecting source code (usually from a remote Git repository, or a remote source tarball), patching it, making its dependencies and transitive dependencies available, building for specific platform and architecture (via any number of build systems), then packaging up and serving binaries. There's a lot of complexity involved.

Here are the two recipes I mentioned:

libcurl: https://github.com/conan-io/conan-center-index/blob/master/r...

OpenSSL v3: https://github.com/conan-io/conan-center-index/blob/master/r...

Now, for the sake of this thread I want to highlight three things here:

- Conan recipes are usually made by people unaffiliated with the libraries they're packaging;

- The recipes are fully Turing-complete, do a lot of work, have their own bugs - therefore they should really be treated as software comonents themselves, for the purpose of OSS clearing/supply chain verification, except as far as I know, nobody does it;

- The recipes can, and do, patch source code and build scripts. There's supporting infrastruture for this built into Conan, and of course one can also do it by brute-force search and replace. See e.g. ZLib recipe that does it both at the same time:

https://github.com/conan-io/conan-center-index/blob/7b0ac710... -- `_patch_sources` does both direct search-and-replace in source files, and applies the patches from https://github.com/conan-io/conan-center-index/tree/master/r....

Good luck keeping track of what exact code goes into your program, when using Turing-complete "recipe" programs fetched from the Internet, which fetch your libraries from somewhere else on the Internet.

Re:The xz attack shell script by _a_a_a_ on Wednesday April 03, 2024 @09:08AM (#39916971)
That was a really, really good answer, thanks.
Re:The xz attack shell script by sanderjd on Wednesday April 03, 2024 @08:19AM (#39916497)
FWIW, my comment wasn't meant to single out python as particularly good. I think the comparison I drew between its inscrutability and that of shell / bash would apply to nearly all other languages as well.
Re:The xz attack shell script by egorfine on Wednesday April 03, 2024 @04:41AM (#39914904)
I'm a bash apologist and I totally stand by your words. It's delusional. Bash totally has to go.
Re:The xz attack shell script by dboreham on Wednesday April 03, 2024 @01:09AM (#39913792)
Shell is evil mainly because it's so old. It's largely unchanged since 1978 and had to run on incredibly resource limited machines. What it could achieve on those machines was amazing. Tradeoffs would be different today, e.g. PowerShell.
Re:The xz attack shell script by SlightlyLeftPad on Wednesday April 03, 2024 @02:36AM (#39914284)
A big pet peeve of mine is that shell is written off as evil but the only reason I ever hear is basically a variation of “I don’t understand it, therefore it scares me.” The reality is, unlike _really_ old languages like COBOL or RPG, bash is still literally everywhere, it’s installed on practically every linux machine by default which makes deploying a shell script completely trivial. It’s certainly under appreciated and because it’s ubiquitous, widely used in build processes, there’s a responsibility to learn it. It’s not hard, it’s not a wildly complex language.

I don’t think these issues would necessarily be solved at all by waving a hand and replacing it with similarly complex build tools. Bazel, for example, can be a daunting tool to fully grasp. Any tool used should be well understood. Easier said than done of course.

Re:The xz attack shell script by Espressosaurus on Wednesday April 03, 2024 @02:46AM (#39914339)
If a language has more footguns than guns-pointed-at-not-my-feet, I consider that a problem with the language.

And shell has a lot of footguns.

Re:The xz attack shell script by SlightlyLeftPad on Wednesday April 03, 2024 @03:12AM (#39914461)
I’d argue that every language is loaded full of foot guns. If you’re encountering those foot guns on a regular basis, it’s an issue with the author.

That said, what can help drastically here are well-defined best practices and conventions built into the language which, admittedly, bash really doesn’t have.

Re:The xz attack shell script by _a_a_a_ on Wednesday April 03, 2024 @04:30AM (#39914871)
Can you point to 3 python foot guns, for instance?
Re:The xz attack shell script by s1dev on Wednesday April 03, 2024 @04:55AM (#39914977)
I’m generally in agreement with the anti-bash camp, but I can name about that many :)

- Mutating default arguments to functions, so subsequent calls have different behavior

- Somewhat particular rules around creating references vs copies

- Things that look like lambda captures but aren’t quite

Re:The xz attack shell script by sanderjd on Wednesday April 03, 2024 @08:12AM (#39916415)
Yep, every language has footguns and other kinds of quirks, but I contend that the "footguns per character" ratio in shell is unusually high. (It is not unique in having a high ratio though; other popular languages, like c++ for instance, also have this issue.)
Re:The xz attack shell script by eitland on Wednesday April 03, 2024 @03:56PM (#39922262)
The worst (level of nastyness * usage) offenders all probably have a reason for being popular despite their flaws:

- Bash: installed everywhere you want to work (yes, who actually wants to work on Windows ;-)

- C/C++: when speed/size matters there was no alternative except Assembly until recently

- Javascript: until recently this was the most sane option for client side code on the web (Active X and Java applets existed yes but managed to be even worse.)

- PHP: Low cost hosting, Function-As-A-Service way before that became popular, shared nothing architecture, instant reload for local development bliss

Re:The xz attack shell script by sanderjd on Wednesday April 03, 2024 @04:05PM (#39922385)
Couldn't agree more.
Re:The xz attack shell script by _a_a_a_ on Wednesday April 03, 2024 @05:05AM (#39915014)
Touche!
Re:The xz attack shell script by bonzini on Wednesday April 03, 2024 @01:00PM (#39919942)
- string vs. list "in" ('a' in 'a' is True, but 'a' in ['a'] is also True)

- cannot know which object attributes are private or public (and some classes use settable properties so you can't say "just don't set any attributes on non-dataclass objects")

Re:The xz attack shell script by eitland on Wednesday April 03, 2024 @03:48PM (#39922167)
Agree.

As long as you apply the same standards to what seems to be everyones darling: Javascript.

Javascript has the same amount of footguns as PHP and Bash but has gotten away with it by being cute (and having a whole menagerie if support tools around it to make it possible for ordinary people to write workable code in it).

(Yes, I am qualified to rant about Javascript BTW. I wrote a working map rendering system with pan and zoom and automatic panning based on GPS location using ECMAScript and SVG back in the spring of 2005. I think roughly half a year before Google Maps became public. Back before all the modern JS tooling existed. All I had was JEdit with syntax highlighting. Perl at least let me put breakpoints in my code even back then.

And yes, I have written more JS since then.)

Re:The xz attack shell script by Espressosaurus on Wednesday April 03, 2024 @04:00PM (#39922316)
I specifically avoided web development because of Javascript and its plethora and ever-changing set of frameworks. So IMO, it absolutely counts.
Re:The xz attack shell script by eitland on Wednesday April 03, 2024 @04:43PM (#39922842)
FWIW it has actually become better the last few years:

Now you can at least just stick to React and TypeScript and bundle it using Webpack and have months of relative sanity between each time you have to throw something out and replace it.

Re:The xz attack shell script by SlightlyLeftPad on Thursday April 04, 2024 @12:57PM (#39932975)
In the context of build systems and the vulnerabilities that exist in xs, one of server-side JavaScript’s biggest footguns that cannot be ignored is its dependency management. Very few people I know ever really dig into the dependency tree and audit all packages 10 levels deep. The attack surface there is huge and objectively much wider than PHP/Bash. It’s also a built-in automatic entryway into a corporate network.
Re:The xz attack shell script by ElevenLathe on Thursday April 04, 2024 @04:02PM (#39935153)
Shell has a lot of stuff going for it too, though:

-> REPL essentially for free (the language IS a REPL)

-> enormous installed base

-> No compilation (well, unless you have something--like autotools--using shell as essentially a transpilation target)

-> No need for "libraries" in most cases: the ordinary CLI that $vendor already ships can be used right away, with no need for a custom SDK for whatever "real" language you would otherwise be using. For example, if you are already familiar with the "aws" CLI program, it's trivial to treat it as an "API" for a quick shellscript instead of needing to dig into the boto3 docs to do something equivalent the "right" way.

-> Pretty good integration with standard *nix facilities (redirecting STD{ERR,OUT}, checking existence of files/pipes, checking/setting exit codes, etc.)

Re:The xz attack shell script by sanderjd on Wednesday April 03, 2024 @08:10AM (#39916396)
I think a good way to evaluate languages from this perspective is through the lens of how easy it is to maintain understanding over time. I have learned bash well three or four times now, but I know now that I'm never going to remember enough of its quirks through the interim periods where I'm not focused on it, to be able to grok arbitrary scripts without refreshing my memory. This is very different for languages like java, go, python, and some others, which have their quirks, sure, but a much lower quirks per character ratio.

I might agree with "it's not hard to learn it", but I don't agree with "it's not hard to remember it".

Re:The xz attack shell script by bilekas on Wednesday April 03, 2024 @08:23AM (#39916519)
> Shell is evil mainly because it's so old.

I really don't understand this point, its a script language, how old is it doesn't make any difference. I've come accross some Powershell scripts that were unreadable down to its verbosity with certain things, and if you don't already know all the flags and options for it, it's hopeless to try and understand.

Both serve a purpose, neither are 'evil'.

Re:The xz attack shell script by mkesper on Wednesday April 03, 2024 @09:17AM (#39917066)
I don't think PowerShell is a big improvement, though. Still allows no signature checking of functions. Shells are optimized for fast entry, not for writing comprehensible (or even secure) programs.
Re:The xz attack shell script by dheera on Wednesday April 03, 2024 @11:01AM (#39918385)
There is Xonsh which is a Python shell. I don't know why everyone hasn't switched to it already as default.
Re:The xz attack shell script by bayindirh on Wednesday April 03, 2024 @05:32AM (#39915188)
> I feel like even "simple" shell scripts tend toward more inscrutability than all but the most questionable python code I've ever written.

When you use long options in bash (scripts), it becomes very readable, but it's not a widespread practice. I always use long options while writing scripts.

Consider these two examples, which is very straightforward:

- curl -fsSL $URL | bash

- curl --fail --silent --show-error --location $URL | bash

The second one almost "talks you through".

Re:The xz attack shell script by sanderjd on Wednesday April 03, 2024 @08:17AM (#39916468)
IMO, that's not where the inscrutability comes from. Rather, it is things like many useful (and thus used) constructs being implemented with line noise like `"$(foo)"`, `2>&1 &`, `${foo:-bar}`, etc., finicky control flow syntax, surprising defaults that can be changed within unclear scopes, etc.
Re:The xz attack shell script by bayindirh on Wednesday April 03, 2024 @08:21AM (#39916508)
You're right, but you can also expand these. If not syntactically, by adding temporary variables and comments around these complex parts.

It's true that Bash and Perl has one of the most contractible syntax around, but it's not impossible to make it more understandable.

However, these parts of codebases are considered "supportive" and treated as second class citizens, and never receives the same love core parts of the codebases enjoy. That's a big mistake IMO.

When you make something more readable all around, hiding things becomes harder exponentially.

Re:The xz attack shell script by im3w1l on Thursday April 04, 2024 @01:44AM (#39926947)
I have seen people write bash scripts with a lot of love and attention trying really hard to pay attention to modern best practices and avoiding known pitfalls and using shellcheck. It still looked like shit imo.

I challenge you to find a single easily readable >100 line bash script and link it here (I do think small scripts can be fine).

Re:The xz attack shell script by bayindirh on Thursday April 04, 2024 @02:51AM (#39927313)
While not completely up to my own standards, this is pretty neat and readable: https://rclone.org/install.sh

I may add more if I have time today.

Re:The xz attack shell script by im3w1l on Thursday April 04, 2024 @10:10AM (#39930629)
Must say I'm pleasantly surprised.
Re:The xz attack shell script by sanderjd on Thursday April 04, 2024 @08:34AM (#39929607)
Yep, my experience of this was at google, where I heard "gbash is actually pretty good!", so I learned that system well (because shell scripts are incredibly useful!), but still found the results unsatisfyingly inscrutable.
Re:The xz attack shell script by account42 on Wednesday April 10, 2024 @11:38AM (#39991937)
The irony of talking about readability of an example of curl to sh. You really don't need to understand the flags here to understand that this is a voluntary RCE and while I'm generally for long options in scripts, in this case it might make it harder to see the real problem because it increases the distance between the download command and the shell invocation.
Re:The xz attack shell script by bayindirh on Thursday April 11, 2024 @07:41AM (#40001092)
> The irony of talking about readability of an example of curl to sh.

Who says I blindly curl2sh these scripts? I download them, read them and understand what they do before running them actually.

Long options make obscure command lines readable and understandable, actually, and if you vet them, you understand what they are doing.

Short options make things harder because I need to open the man of the command to understand what it is doing.

You don't have to do everything blindly as the quick start documents outline.