diff options
author | Jeremie Koenig <jk@jk.fr.eu.org> | 2010-08-23 11:33:22 +0000 |
---|---|---|
committer | Jeremie Koenig <jk@jk.fr.eu.org> | 2010-08-30 14:31:31 +0200 |
commit | 2f30d52e2753c4fc854753ee2d0efb895a317c9f (patch) | |
tree | fc8704aadad47a0373258e80a25cf8773110547e /procfs.c | |
parent | 0277bc261796743148769a3f76f9cae51c61e0a4 (diff) |
Detect asprintf's ENOMEM in procfs.c rather than everywhere
* procfs.h: Make CONTENTS_LEN an ssize_t rather than a size_t,
and document the change.
* procfs.c (procfs_get_contents): Initialize CONTENTS_LEN to a
negative value, and fail with ENOMEM if it's still negative after the
callback returns. (everywhere): Update to ssize_t.
* dircat.c, netfs.c, process.c,
procfs_dir.c, proclist.c, rootdir.c: Update to
ssize_t and the new GET_CONTENTS semantics.
Diffstat (limited to 'procfs.c')
-rw-r--r-- | procfs.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -13,20 +13,20 @@ struct netnode /* (cached) contents of the node */ char *contents; - size_t contents_len; + ssize_t contents_len; /* parent directory, if applicable */ struct node *parent; }; void -procfs_cleanup_contents_with_free (void *hook, char *cont, size_t len) +procfs_cleanup_contents_with_free (void *hook, char *cont, ssize_t len) { free (cont); } void -procfs_cleanup_contents_with_vm_deallocate (void *hook, char *cont, size_t len) +procfs_cleanup_contents_with_vm_deallocate (void *hook, char *cont, ssize_t len) { vm_deallocate (mach_task_self (), (vm_address_t) cont, (vm_size_t) len); } @@ -109,7 +109,7 @@ procfs_make_ino (struct node *np, const char *filename) return (unsigned long) jrand48 (x); } -error_t procfs_get_contents (struct node *np, char **data, size_t *data_len) +error_t procfs_get_contents (struct node *np, char **data, ssize_t *data_len) { if (np->nn->ops->enable_refresh_hack_and_break_readdir && np->nn->contents) { @@ -122,12 +122,15 @@ error_t procfs_get_contents (struct node *np, char **data, size_t *data_len) if (! np->nn->contents && np->nn->ops->get_contents) { char *contents; - size_t contents_len; + ssize_t contents_len; error_t err; + contents_len = -1; err = np->nn->ops->get_contents (np->nn->hook, &contents, &contents_len); if (err) return err; + if (contents_len < 0) + return ENOMEM; np->nn->contents = contents; np->nn->contents_len = contents_len; |