com32: fix a ffile descriptor leak on open() of a nonexistent file
authorH. Peter Anvin <hpa@linux.intel.com>
Mon, 6 Dec 2010 23:54:24 +0000 (15:54 -0800)
committerH. Peter Anvin <hpa@linux.intel.com>
Mon, 6 Dec 2010 23:58:49 +0000 (15:58 -0800)
If we try to open a nonexistent file, free the resulting file
descriptor.

Reported-by: Antonio Carlini <arcarlini@iee.org>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
com32/lib/sys/open.c

index cb7c1b4..3e7bb6c 100644 (file)
@@ -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;