Article View: net.bugs.usg
Article #228Yet ANOTHER null pointer dereference problem (in "cat")
From: Guy Harris
Date: Thu, 26 Sep 1985 04:45
Date: Thu, 26 Sep 1985 04:45
31 lines
1739 bytes
1739 bytes
PLEASE, people: argv[argc] does NOT point to a string. It is a null pointer.
Code which dereferences it is illegal. If you want to write a program which
reads standard input if 1) no arguments are given or 2) an argument of "-"
is given, PLEASE check whether any arguments were given before checking if
an argument of "-" was given! (One would think that it was obvious that one
should first check if something exists before checking if it has a
particular property, but there's a hell of a lot of code that seems not
to...)
*** cat.c.BAK Mon Sep 23 13:06:36 1985
--- cat.c Wed Sep 25 11:57:05 1985
***************
*** 85,91
for (argv = &argv[optind];
optind < argc && !ferror(stdout); optind++, argv++) {
filenm = *argv;
! if (filenm[0]=='-' && filenm[1]=='\0' || stdinflg) {
filenm = "standard input";
fi = stdin;
} else {
--- 85,91 -----
for (argv = &argv[optind];
optind < argc && !ferror(stdout); optind++, argv++) {
filenm = *argv;
! if (stdinflg || (filenm[0]=='-' && filenm[1]=='\0')) {
filenm = "standard input";
fi = stdin;
} else {
Guy Harris
Technical Details
Message-ID:
<2826@sun.uucp>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbosgd!ihnp4!mhuxn!mhuxr!ulysses!allegra!mit-eddie!genrad!decvax!decwrl!sun!guyShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbosgd!ihnp4!mhuxn!mhuxr!ulysses!allegra!mit-eddie!genrad!decvax!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: net.bugs.usg Subject: Yet ANOTHER null pointer dereference problem (in "cat") Message-ID: <2826@sun.uucp> Date: Thu, 26-Sep-85 00:45:28 EDT Article-I.D.: sun.2826 Posted: Thu Sep 26 00:45:28 1985 Date-Received: Sun, 29-Sep-85 04:41:00 EDT Distribution: net Organization: Sun Microsystems, Inc. Lines: 31