0

About 10 years ago I've been told by someone that for years Linux used to crash whenever you tried to read /dev/null (ie. cat /dev/null).

Is this actually true? Did such a bug exist? And if it did, did it exist for years?


Edit; I found this in Linux 1.0 (March 1994) in ./drivers/char/mem.c:

/*
 * Special lseek() function for /dev/null and /dev/zero.  Most notably, you can fopen()
 * both devices with "a" now.  This was previously impossible.  SRB.
 */

Perhaps this is it ...? I didn't investigate/trace all the code..

  • 1
    I've been using Linux since the late 90s, and have never heard of that bug. Not an answer, because of course Linux existed for at least 7 years before that. – derobert Feb 27 '15 at 12:31
  • i once ran into a bug in another *nix system where writing more than some big number of gigabytes to /dev/null would result in an I/O error ... and i hit it in a "normal" use case (not just trying to test for it) – Skaperen Feb 27 '15 at 12:59
  • 1
    /dev/null is meant to be read. The whole purpose of it is that such a read returns nothing (and writes to it succeed). Its driver is also the easiest possible to write. There can't reasonably have been such a bug. – Stéphane Chazelas Feb 27 '15 at 13:21
  • Did that someone also ask you to pull their finger or try to sell you a bridge? Reading from /dev/null is so common that a bug like this would be discovered and fixed instantly. – Gilles Feb 28 '15 at 22:05
2

/dev/null is used by countless scripts, such a bug would have become apparent immediately after a kernel with that bug had booted.

Perhaps it did once happen but I expect it was fixed the same day. I've been using Unix since 1983 (and Linux since 1992) and I've never heard of this.

  • 1
    I've never seen a script read /dev/null, it's typically used for writing to it. – Martin Tournoij Feb 27 '15 at 13:09
  • 1
    @Carpetsmoker, You can read from /dev/null too: dd if=/dev/null of=MyFile bs=10M count=1 – Sepahrad Salour Feb 27 '15 at 14:20
  • @SepahradSalour I know it's possible; it's just not as common as writing to it, so I would consider it to be at least possible that such a bug could, perhaps, have existed for an extended period of time (especially if it was present since the start). – Martin Tournoij Feb 27 '15 at 14:26
  • 2
    @Carpetsmoker There are plenty of places where command </dev/null is done. – wurtel Feb 27 '15 at 14:57
  • A common modern use case is while read something; do ssh remote 'commands ...' </dev/null; done <file where the ssh process would read all the remaining contents from file on the first iteration without the redirection. However, this was probably not a widespread problem when ssh and Linux were still new. Anyway, I agree that it is not plausible that such a bug would have existed for any longer time. – tripleee Mar 28 '15 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.