diff options
author | 2019-06-27 06:41:36 +0000 | |
---|---|---|
committer | 2019-06-27 06:41:36 +0000 | |
commit | 3cd3751cbbf35a9725bc2480bd34868aea895049 (patch) | |
tree | 3e0716831530bad1e6b6cf309c70437b6bbc7193 | |
parent | fix NULL deference (bzero) on error path added in last commit; (diff) | |
download | wireguard-openbsd-3cd3751cbbf35a9725bc2480bd34868aea895049.tar.xz wireguard-openbsd-3cd3751cbbf35a9725bc2480bd34868aea895049.zip |
Be precise in checking for errors. pclose(3) returns -1 and fclose(3)
EOF in case of errors, not any negative number.
EOF corner case spotted while reviewing a much bigger diff by deraadt
OK deraadt, millert
-rw-r--r-- | bin/ed/io.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/bin/ed/io.c b/bin/ed/io.c index e9d6e1c3007..673a2cad9f9 100644 --- a/bin/ed/io.c +++ b/bin/ed/io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: io.c,v 1.22 2018/06/04 13:29:07 martijn Exp $ */ +/* $OpenBSD: io.c,v 1.23 2019/06/27 06:41:36 florian Exp $ */ /* $NetBSD: io.c,v 1.2 1995/03/21 09:04:43 cgd Exp $ */ /* io.c: This file contains the i/o routines for the ed line editor */ @@ -58,7 +58,7 @@ read_file(char *fn, int n) return ERR; } else if ((size = read_stream(fp, n)) < 0) return ERR; - else if (((*fn == '!') ? pclose(fp) : fclose(fp)) < 0) { + else if ((*fn == '!') ? pclose(fp) == -1 : fclose(fp) == EOF) { perror(fn); seterrmsg("cannot close input file"); return ERR; @@ -160,7 +160,7 @@ write_file(char *fn, char *mode, int n, int m) return ERR; } else if ((size = write_stream(fp, n, m)) < 0) return ERR; - else if (((*fn == '!') ? pclose(fp) : fclose(fp)) < 0) { + else if ((*fn == '!') ? pclose(fp) == -1 : fclose(fp) == EOF) { perror(fn); seterrmsg("cannot close output file"); return ERR; |