From 2294f2fdffcf724cc28653976b8029351e41fd77 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 16 Mar 2014 20:04:11 +0100 Subject: Fix handling of console readlink errors * console-client/trans.c (netfs_attempt_lookup): Look for errors returned by `readlink' before allocating a node. (netfs_attempt_readlink): Look for errors returned by `readlink'. --- console-client/trans.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'console-client') diff --git a/console-client/trans.c b/console-client/trans.c index 00c5407e..d65161c0 100644 --- a/console-client/trans.c +++ b/console-client/trans.c @@ -269,7 +269,20 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir, { if (cn->node == NULL) { - struct netnode *nn = calloc (1, sizeof *nn); + struct netnode *nn; + ssize_t size = 0; + + if (cn->readlink) + { + size = cn->readlink (user, NULL, NULL); + if (size < 0) + { + err = -size; + goto out; + } + } + + nn = calloc (1, sizeof *nn); if (nn == NULL) { err = ENOMEM; @@ -283,15 +296,10 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir, (*node)->nn_stat.st_mode = (netfs_root_node->nn_stat.st_mode & ~S_IFMT & ~S_ITRANS); (*node)->nn_stat.st_ino = 5; if (cn->readlink) - { (*node)->nn_stat.st_mode |= S_IFLNK; - (*node)->nn_stat.st_size = cn->readlink (user, NULL, NULL); - } else - { (*node)->nn_stat.st_mode |= S_IFCHR; - (*node)->nn_stat.st_size = 0; - } + (*node)->nn_stat.st_size = size; cn->node = *node; goto out; } @@ -508,7 +516,13 @@ netfs_attempt_readlink (struct iouser *user, struct node *np, char *buf) { if (np->nn->node && np->nn->node->readlink) - return np->nn->node->readlink (user, np, buf); + { + error_t err = np->nn->node->readlink (user, np, buf); + if (err < 0) + return -err; + else + return 0; + } return EOPNOTSUPP; } -- cgit v1.2.3