The way we use diskfs_make_node is currently unsafe: we almost never check the return value, however, we really should. The following patches fix this. However, rather than simply correcting the problems, I opted to fix the error at its root: the interface. Now, we return an error code and place the node structure in an argument. This has precedence with the iohelp_create_iouser changes back in April of this year.
I made a second small tweak in the interface to fshelp_transbox_init, iohelp_initialize_conch and fshelp_lock_init. These all now return an error_t instead of simply void. libdiskfs: 2001-11-16 Neal H Walfield <[EMAIL PROTECTED]> * diskfs.h (diskfs_make_node): Change the prototype. The node is now returned in a local argument and the function itself returns an error_t. * node-make.c (diskfs_make_node): Up date to new semantics. Do more through error checking. libfshelp: 2001-11-16 Neal H Walfield <[EMAIL PROTECTED]> * fshelp.h (fshelp_transbox_init): Return an error_t, not void. (fshelp_lock_init): Likewise. * lock-init.c (fshelp_lock_init): Likewise and return 0 on succcess. * transbox-init.c (fshelp_transbox_init): Likewise. iohelp: 2001-11-16 Neal H Walfield <[EMAIL PROTECTED]> * iohelp.c (iohelp_initialize_conch): Return an error_t, not void. * initialize-conch.c (iohelp_initialize_conch): Likewise and return 0 on success. ext2fs: 2001-11-16 Neal H Walfield <[EMAIL PROTECTED]> * inode.c (diskfs_cached_lookup): Implement the new semantics of diskfs_make_node and check the result. Only use the contents of NP if it was successfully read from disk. isofs: 2001-11-16 Neal H Walfield <[EMAIL PROTECTED]> * inode.c (diskfs_cached_lookup): Implement the new semantics of diskfs_make_node. (load_inode): Likewise. tmpfs: 2001-11-16 Neal H Walfield <[EMAIL PROTECTED]> * node.c (diskfs_cached_lookup): Implement the new semantics of diskfs_make_node and check the result. ufs: 2001-11-16 Neal H Walfield <[EMAIL PROTECTED]> * inode.c (diskfs_cached_lookup): Implement the new semantics of diskfs_make_node and check the result. Check the return of malloc. (Do you prefer all the change log entries at the top of the patch like this or at the top of each section, i.e. the libdiskfs change log entries followed by all of the changes pertaining to libdiskfs, then the change log for libfshelp and its changes, etc?) Index: libdiskfs/diskfs.h =================================================================== RCS file: /cvsroot/hurd/hurd/libdiskfs/diskfs.h,v retrieving revision 1.92 diff -u -r1.92 diskfs.h --- libdiskfs/diskfs.h 2001/08/20 22:44:13 1.92 +++ libdiskfs/diskfs.h 2001/11/16 12:52:20 @@ -654,7 +654,7 @@ /* Create a new node structure with DS as its physical disknode. The new node will have one hard reference and no light references. */ -struct node *diskfs_make_node (struct disknode *dn); +error_t diskfs_make_node (struct disknode *dn, struct node **np); /* The library also exports the following functions; they are not generally Index: libdiskfs/node-make.c =================================================================== RCS file: /cvsroot/hurd/hurd/libdiskfs/node-make.c,v retrieving revision 1.15 diff -u -r1.15 node-make.c --- libdiskfs/node-make.c 1998/08/10 17:42:39 1.15 +++ libdiskfs/node-make.c 2001/11/16 12:52:20 @@ -1,5 +1,5 @@ /* - Copyright (C) 1994, 1995, 1996 Free Software Foundation + Copyright (C) 1994, 1995, 1996, 2001 Free Software Foundation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -21,10 +21,15 @@ /* Create a and return new node structure with DN as its physical disknode. The node will have one hard reference and no light references. */ -struct node * -diskfs_make_node (struct disknode *dn) +error_t +diskfs_make_node (struct disknode *dn, struct node **npp) { - struct node *np = malloc (sizeof (struct node)); + error_t err; + struct node *np; + + *npp = np = malloc (sizeof (struct node)); + if (! np) + return ENOMEM; np->dn = dn; np->dn_set_ctime = 0; @@ -40,11 +45,20 @@ np->dirmod_reqs = 0; np->filemod_reqs = 0; - - fshelp_transbox_init (&np->transbox, &np->lock, np); - iohelp_initialize_conch (&np->conch, &np->lock); - fshelp_lock_init (&np->userlock); + if ((err = fshelp_transbox_init (&np->transbox, &np->lock, np))) + goto error; + + if ((err = iohelp_initialize_conch (&np->conch, &np->lock)) + || (err = fshelp_lock_init (&np->userlock))) + goto error_with_transbox; + + return err; + + error_with_transbox: + fshelp_drop_transbox (&np->transbox); + error: + free (np); - return np; + return err; } Index: libfshelp/fshelp.h =================================================================== RCS file: /cvsroot/hurd/hurd/libfshelp/fshelp.h,v retrieving revision 1.48 diff -u -r1.48 fshelp.h --- libfshelp/fshelp.h 2001/07/03 01:10:17 1.48 +++ libfshelp/fshelp.h 2001/11/16 12:52:21 @@ -135,10 +135,9 @@ fshelp_fetch_root_callback2_t callback2, retry_type *retry, char *retryname, mach_port_t *root); -void -fshelp_transbox_init (struct transbox *transbox, - struct mutex *lock, - void *cookie); +error_t fshelp_transbox_init (struct transbox *transbox, + struct mutex *lock, + void *cookie); /* Return true iff there is an active translator on this box */ int fshelp_translated (struct transbox *box); @@ -179,7 +178,7 @@ /* Initialize lock_box BOX. (The user int passed to fshelp_acquire_lock should be initialized with LOCK_UN.). */ -void fshelp_lock_init (struct lock_box *box); +error_t fshelp_lock_init (struct lock_box *box); Index: libfshelp/lock-init.c =================================================================== RCS file: /cvsroot/hurd/hurd/libfshelp/lock-init.c,v retrieving revision 1.2 diff -u -r1.2 lock-init.c --- libfshelp/lock-init.c 1994/02/11 18:52:27 1.2 +++ libfshelp/lock-init.c 2001/11/16 12:52:21 @@ -1,5 +1,5 @@ /* - Copyright (C) 1993, 1994 Free Software Foundation + Copyright (C) 1993, 1994, 2001 Free Software Foundation This file is part of the GNU Hurd. @@ -22,11 +22,12 @@ #include "locks.h" /* Initialize a lock box. */ -void +error_t fshelp_lock_init (struct lock_box *box) { box->type = LOCK_UN; condition_init (&box->wait); box->waiting = 0; box->shcount = 0; + return 0; } Index: libfshelp/transbox-init.c =================================================================== RCS file: /cvsroot/hurd/hurd/libfshelp/transbox-init.c,v retrieving revision 1.3 diff -u -r1.3 transbox-init.c --- libfshelp/transbox-init.c 1995/09/29 22:46:04 1.3 +++ libfshelp/transbox-init.c 2001/11/16 12:52:21 @@ -1,5 +1,5 @@ /* - Copyright (C) 1995 Free Software Foundation, Inc. + Copyright (C) 1995, 2001 Free Software Foundation, Inc. Written by Michael I. Bushnell. This file is part of the GNU Hurd. @@ -21,7 +21,7 @@ #include "fshelp.h" #include <cthreads.h> -void +error_t fshelp_transbox_init (struct transbox *transbox, struct mutex *lock, void *cookie) @@ -31,5 +31,6 @@ transbox->lock = lock; condition_init (&transbox->wakeup); transbox->cookie = cookie; + return 0; } Index: libiohelp/iohelp.h =================================================================== RCS file: /cvsroot/hurd/hurd/libiohelp/iohelp.h,v retrieving revision 1.11 diff -u -r1.11 iohelp.h --- libiohelp/iohelp.h 2001/06/16 20:22:14 1.11 +++ libiohelp/iohelp.h 2001/11/16 12:52:22 @@ -33,7 +33,7 @@ }; /* Initialize a conch box */ -void iohelp_initialize_conch (struct conch *, struct mutex *); +error_t iohelp_initialize_conch (struct conch *, struct mutex *); /* These routines are not reentrant. The server is responsible for ensuring that all calls to these routines are serialized Index: libiohelp/initialize_conch.c =================================================================== RCS file: /cvsroot/hurd/hurd/libiohelp/initialize_conch.c,v retrieving revision 1.6 diff -u -r1.6 initialize_conch.c --- libiohelp/initialize_conch.c 1996/05/06 20:31:35 1.6 +++ libiohelp/initialize_conch.c 2001/11/16 12:52:21 @@ -1,5 +1,5 @@ /* - Copyright (C) 1993, 1994, 1996 Free Software Foundation + Copyright (C) 1993, 1994, 1996, 2001 Free Software Foundation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -19,12 +19,13 @@ /* Called by an I/O server to initialize a conch structure C; M will be used to lock conch data structures. */ -void +error_t iohelp_initialize_conch (struct conch *c, struct mutex *m) { c->lock = m; condition_init (&c->wait); c->holder = 0; c->holder_shared_page = 0; + return 0; } Index: ext2fs/inode.c =================================================================== RCS file: /cvsroot/hurd/hurd/ext2fs/inode.c,v retrieving revision 1.58 diff -u -r1.58 inode.c --- ext2fs/inode.c 2001/08/17 00:30:08 1.58 +++ ext2fs/inode.c 2001/11/16 12:52:16 @@ -94,7 +94,14 @@ pokel_init (&dn->indir_pokel, diskfs_disk_pager, disk_image); /* Create the new node. */ - np = diskfs_make_node (dn); + err = diskfs_make_node (dn, &np); + if (err) + { + pokel_finalize (&dn->indir_pokel); + spin_unlock (&diskfs_node_refcnt_lock); + return err; + } + np->cache_id = inum; mutex_lock (&np->lock); @@ -111,7 +118,7 @@ /* Get the contents of NP off disk. */ err = read_node (np); - if (!diskfs_check_readonly () && !np->dn_stat.st_gen) + if (!err && !diskfs_check_readonly () && !np->dn_stat.st_gen) { spin_lock (&generation_lock); if (++next_generation < diskfs_mtime->seconds) Index: isofs/inode.c =================================================================== RCS file: /cvsroot/hurd/hurd/isofs/inode.c,v retrieving revision 1.14 diff -u -r1.14 inode.c --- isofs/inode.c 2001/02/20 19:37:28 1.14 +++ isofs/inode.c 2001/11/16 12:52:17 @@ -1,5 +1,5 @@ /* - Copyright (C) 1997, 1998 Free Software Foundation, Inc. + Copyright (C) 1997, 1998, 2001 Free Software Foundation, Inc. Written by Thomas Bushnell, n/BSG. This file is part of the GNU Hurd. @@ -198,13 +198,13 @@ dn->fileinfo = 0; dn->dr = c->dr; dn->file_start = c->file_start; - np = diskfs_make_node (dn); - if (!np) + err = diskfs_make_node (dn, &np); + if (err) { free (dn); spin_unlock (&diskfs_node_refcnt_lock); release_rrip (&rr); - return ENOMEM; + return err; } np->cache_id = id + 1; /* see above for rationale for increment */ mutex_lock (&np->lock); @@ -357,12 +357,12 @@ dn->dr = record; dn->file_start = file_start; - np = diskfs_make_node (dn); - if (!np) + err = diskfs_make_node (dn, &np); + if (err) { free (dn); spin_unlock (&diskfs_node_refcnt_lock); - return ENOMEM; + return err; } mutex_lock (&np->lock); Index: tmpfs/node.c =================================================================== RCS file: /cvsroot/hurd/hurd/tmpfs/node.c,v retrieving revision 1.9 diff -u -r1.9 node.c --- tmpfs/node.c 2001/10/01 01:05:06 1.9 +++ tmpfs/node.c 2001/11/16 12:52:26 @@ -156,6 +156,7 @@ error_t diskfs_cached_lookup (int inum, struct node **npp) { + error_t err; struct disknode *dn = (void *) inum; struct node *np; @@ -174,7 +175,10 @@ { struct stat *st; - np = diskfs_make_node (dn); + err = diskfs_make_node (dn, &np); + if (err) + return err; + np->cache_id = (ino_t) dn; spin_lock (&diskfs_node_refcnt_lock); Index: ufs/inode.c =================================================================== RCS file: /cvsroot/hurd/hurd/ufs/inode.c,v retrieving revision 1.57 diff -u -r1.57 inode.c --- ufs/inode.c 2001/08/10 04:43:01 1.57 +++ ufs/inode.c 2001/11/16 12:52:29 @@ -67,6 +67,11 @@ } dn = malloc (sizeof (struct disknode)); + if (! dn) + { + spin_unlock (&diskfs_node_refcnt_lock); + return ENOMEM; + } dn->number = inum; dn->dirents = 0; @@ -76,7 +81,13 @@ dn->dirty = 0; dn->fileinfo = 0; - np = diskfs_make_node (dn); + err = diskfs_make_node (dn, &np); + if (err) + { + spin_unlock (&diskfs_node_refcnt_lock); + return ENOMEM; + } + np->cache_id = inum; mutex_lock (&np->lock); _______________________________________________ Bug-hurd mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/bug-hurd