[syslinux:master] com32: fix a ffile descriptor leak on open() of a nonexistent file

syslinux-bot for H. Peter Anvin hpa at linux.intel.com
Mon Dec 6 16:00:33 PST 2010


Commit-ID:  bddb395f4e52f1a0db32a852f1be4a244719f331
Gitweb:     http://syslinux.zytor.com/commit/bddb395f4e52f1a0db32a852f1be4a244719f331
Author:     H. Peter Anvin <hpa at linux.intel.com>
AuthorDate: Mon, 6 Dec 2010 15:54:24 -0800
Committer:  H. Peter Anvin <hpa at linux.intel.com>
CommitDate: Mon, 6 Dec 2010 15:58:49 -0800

com32: fix a ffile descriptor leak on open() of a nonexistent file

If we try to open a nonexistent file, free the resulting file
descriptor.

Reported-by: Antonio Carlini <arcarlini at iee.org>
Signed-off-by: H. Peter Anvin <hpa at linux.intel.com>


---
 com32/lib/sys/open.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/com32/lib/sys/open.c b/com32/lib/sys/open.c
index cb7c1b4..3e7bb6c 100644
--- a/com32/lib/sys/open.c
+++ b/com32/lib/sys/open.c
@@ -56,15 +56,17 @@ int open(const char *pathname, int flags, ...)
     struct file_info *fp;
 
     fd = opendev(&__file_dev, NULL, flags);
-
     if (fd < 0)
 	return -1;
 
     fp = &__file_info[fd];
 
     handle = __com32.cs_pm->open_file(pathname, &fp->i.fd);
-    if (handle < 0)
+    if (handle < 0) {
+	close(fd);
+	errno = ENOENT;
 	return -1;
+    }
 
     fp->i.offset = 0;
     fp->i.nbytes = 0;



More information about the Syslinux-commits mailing list