Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/lib/libsa In lookup(), don't free "dir" on exit if we fo...



details:   https://anonhg.NetBSD.org/src/rev/00d37cdee8dc
branches:  trunk
changeset: 549517:00d37cdee8dc
user:      scw <scw%NetBSD.org@localhost>
date:      Tue Jul 15 13:27:07 2003 +0000

description:
In lookup(), don't free "dir" on exit if we found a matching entry.
Otherwise the caller ends up with a pointer to free'd memory...

diffstat:

 sys/lib/libsa/dosfs.c |  14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diffs (49 lines):

diff -r e132d44444c6 -r 00d37cdee8dc sys/lib/libsa/dosfs.c
--- a/sys/lib/libsa/dosfs.c     Tue Jul 15 12:33:17 2003 +0000
+++ b/sys/lib/libsa/dosfs.c     Tue Jul 15 13:27:07 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dosfs.c,v 1.5 2002/12/30 16:41:53 veego Exp $  */
+/*     $NetBSD: dosfs.c,v 1.6 2003/07/15 13:27:07 scw Exp $    */
 
 /*
  * Copyright (c) 1996, 1998 Robert Nordier
@@ -467,7 +467,7 @@
 static int
 lookup(DOS_FS * fs, u_int clus, const char *name, const struct direntry ** dep)
 {
-       DOS_DIR *dir;
+       static DOS_DIR *dir = NULL;
        u_char  lfn[261];
        u_char  sfn[13];
        u_int   nsec, lsec, xdn, chk, sec, ent, x;
@@ -480,7 +480,11 @@
                                return 0;
                        }
 
-       dir = alloc(sizeof(DOS_DIR) * DEPSEC);
+       if (dir == NULL) {
+               dir = alloc(sizeof(DOS_DIR) * DEPSEC);
+               if (dir == NULL)
+                       return (ENOMEM);
+       }
 
        if (!clus && fs->fatsz == 32)
                clus = fs->rdcl;
@@ -538,7 +542,7 @@
                                                }
                                                if (ok) {
                                                        *dep = &dir[ent].de;
-                                                       goto out;
+                                                       goto out2;
                                                }
                                        }
                                }
@@ -555,6 +559,8 @@
        err = ENOENT;
  out:
        free(dir, sizeof(DOS_DIR) * DEPSEC);
+       dir = NULL;
+ out2:
        return (err);
 }
 



Home | Main Index | Thread Index | Old Index