5

You can do a lot with an empty file

 3 years ago
source link: http://rachelbythebay.com/w/2022/04/06/text/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

You can do a lot with an empty file

Yesterday's post about "pipefail" also involved some systems which treated an empty file as a valid file. This turns out to be surprisingly common. I think people might be shocked at exactly how much you can get away with, and how many different things will accept such a beast.

One of the failure modes I used to see with certain package-based systems at a job with a large number of computers is that sometimes it would just fail to populate it with actual data. This might've been due to a reboot during the package install process, or maybe the packager got killed for some reason, but it meant all kinds of badness would happen.

In particular, I saw times where it would drop a file on the disk in the right place, with the right permissions (readable + executable) but totally empty! Then, later on, something or other would ask if the package was installed, and as far as the package database was concerned, it was. Also, then the cron job would try to run one of these binaries... and it wouldn't fail. Nope, it was perfectly happy running exactly nothing.

Yes, if you weren't already aware of this, an empty file that's executable will totally "run" to "completion" and will even yield an exitcode of 0. If you are checking that exitcode for success or failure, it's going to think everything is just fine.

No, really, look:

linux$ touch empty
linux$ chmod a+rx empty
linux$ ls -l empty
-rwxr-xr-x 1 rkroll rkroll 0 Apr  6 12:07 empty
linux$ ./empty
linux$ echo $?
0

Awesome, right? This works just fine on Macs as well. I don't have quite the assortment of shell accounts on other flavors of Unix that I did back in the '90s to test further, but I have to assume it'll probably work most of the time. It's probably something funny involving how the interpreter is spun up - looking for #! and that kind of stuff.

I mean, what would the error be, anyway?

Does this mean the smallest /bin/true is actually an empty file?


Recommend

  • 14

    A little bit of plain Javascript can do a lot I’ve never worked as a professional frontend developer, so even though I’ve been writing HTML/CSS/JS for 15 years for little side projects, all of the projects have be...

  • 21

    Quick Tip - Strip Empty Lines Out Of A File Here’s a quick one-liner that will remove all of the blank lines from a file. get-content $PathToInput | % { if (-not [string]::IsNullOrWhiteSpace($_)...

  • 10

    Newer C++ features can create a lot of system yak shaving I've been slowly easing myself back into the world of programming on my own time now that new things I would create are no longer encumbered by a certain former employer....

  • 9
    • quuxplusone.github.io 3 years ago
    • Cache

    Removing an empty base class can break ABI

    Removing an empty base class can break ABI

  • 10

    Adding text to an empty copied file using Robocopy advertisements I have a script that copies all wildcard defined files from one place to ano...

  • 7
    • tomtunguz.com 3 years ago
    • Cache

    Why You Should Repeat Yourself, A Lot

    Why You Should Repeat Yourself, A Lot Posted on 2021, Oct 05 2 mins read If you’re part of a management team, repeating yourself is a...

  • 8
    • rjlipton.wpcomstaging.com 3 years ago
    • Cache

    We Believe A Lot, But Can Prove Little

    We Believe A Lot, But Can Prove Little January 19, 2011 The gap between what we believe and what we can prove Stan Eisenstat is a numerical analyst who works on v...

  • 2
    • bothsidesofthetable.com 3 years ago
    • Cache

    Why Titles Matter a Lot if You’re a Blogger

    Why Titles Matter a Lot if You’re a BloggerGabe Rivera wrote a post on why TechMeme is now using its editors to curate titles that appear on its site.

  • 8
    • www.secpulse.com 3 years ago
    • Cache

    Empty Passwordin Configuration File

    Empty Passwordin Configuration File 早在2017年,苹果MacOS的Sierra就出现过类似漏洞问题, 它允许任何人在root账户中输入一个空白密码或任意字符串作为密码即可进入系统。未授权的用户可以...

  • 12

    Lots of feedback about /bin/true, and more empty file fun Okay, wow, my post about an empty file has generated a lot of feedback, mostly for the throwaway line at the botto...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK