Module Name: src Committed By: spz Date: Tue Dec 3 17:06:52 UTC 2013
Modified Files: src/bin/cat: cat.c Log Message: Coverity complaint fixes: bin/cat/cat.c 976654 Argument cannot be negative (missing check for fileno result, stdout) bin/cat/cat.c 976653 Improper use of negative value (missing check for fileno result, stdin) To generate a diff of this commit: cvs rdiff -u -r1.52 -r1.53 src/bin/cat/cat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/cat/cat.c diff -u src/bin/cat/cat.c:1.52 src/bin/cat/cat.c:1.53 --- src/bin/cat/cat.c:1.52 Mon Nov 19 19:41:31 2012 +++ src/bin/cat/cat.c Tue Dec 3 17:06:51 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: cat.c,v 1.52 2012/11/19 19:41:31 christos Exp $ */ +/* $NetBSD: cat.c,v 1.53 2013/12/03 17:06:51 spz Exp $ */ /* * Copyright (c) 1989, 1993 @@ -44,7 +44,7 @@ __COPYRIGHT( #if 0 static char sccsid[] = "@(#)cat.c 8.2 (Berkeley) 4/27/95"; #else -__RCSID("$NetBSD: cat.c,v 1.52 2012/11/19 19:41:31 christos Exp $"); +__RCSID("$NetBSD: cat.c,v 1.53 2013/12/03 17:06:51 spz Exp $"); #endif #endif /* not lint */ @@ -250,9 +250,11 @@ raw_args(char **argv) filename = "stdin"; do { if (*argv) { - if (!strcmp(*argv, "-")) + if (!strcmp(*argv, "-")) { fd = fileno(stdin); - else if (fflag) { + if (fd < 0) + goto skip; + } else if (fflag) { struct stat st; fd = open(*argv, O_RDONLY|O_NONBLOCK, 0); if (fd < 0) @@ -279,7 +281,8 @@ skipnomsg: filename = *argv++; } raw_cat(fd); - if (fd != fileno(stdin)) + /* fd > 0 would be cuter but let's priorize human-readability */ + if (fd >= 0 && fd != fileno(stdin)) (void)close(fd); } while (*argv); } @@ -294,6 +297,8 @@ raw_cat(int rfd) int wfd; wfd = fileno(stdout); + if (wfd < 0) + err(EXIT_FAILURE, "stdout"); if (buf == NULL) { struct stat sbuf;