From: Kyrylo Tkachov Date: Tue, 18 Sep 2018 09:02:14 +0000 (+0000) Subject: [libgfortran] Fix uninitialized variable use in fallback_access X-Git-Tag: releases/gcc-7.4.0~155 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d13b786617560179ad6833d01d2c28fe733127c;p=thirdparty%2Fgcc.git [libgfortran] Fix uninitialized variable use in fallback_access Backport from trunk 2018-09-14 Kyrylo Tkachov * io/unix.c (fallback_access): Avoid calling close on uninitialized file descriptor. From-SVN: r264384 --- diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index afe561b2162d..004b25865b61 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,11 @@ +2018-09-18 Kyrylo Tkachov + + Backport from trunk + 2018-09-14 Kyrylo Tkachov + + * io/unix.c (fallback_access): Avoid calling close on + uninitialized file descriptor. + 2018-06-22 Jakub Jelinek Backported from mainline diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index bb9bc9a5c125..993797e6d1f8 100644 --- a/libgfortran/io/unix.c +++ b/libgfortran/io/unix.c @@ -149,13 +149,21 @@ fallback_access (const char *path, int mode) { int fd; - if ((mode & R_OK) && (fd = open (path, O_RDONLY)) < 0) - return -1; - close (fd); + if (mode & R_OK) + { + if ((fd = open (path, O_RDONLY)) < 0) + return -1; + else + close (fd); + } - if ((mode & W_OK) && (fd = open (path, O_WRONLY)) < 0) - return -1; - close (fd); + if (mode & W_OK) + { + if ((fd = open (path, O_WRONLY)) < 0) + return -1; + else + close (fd); + } if (mode == F_OK) {