diff --git a/vfs/ChangeLog b/vfs/ChangeLog index 789347d38..a743e374a 100644 --- a/vfs/ChangeLog +++ b/vfs/ChangeLog @@ -1,3 +1,12 @@ +2003-08-29 Andrew V. Samoilov + + * direntry.c (vfs_s_dump): Commented out. + * extfs.c (s_readlink): Fix return value and possible buffer + overflow. + * mcfs.c (mcfs_readlink): Fix return value. + * mcserv.c (do_readlink): Fix possible off-by-one. + (commands): Make const array and remove needless comma. + 2003-08-29 Pavel Roskin * ftpfs.c (initconn): Use more portable initialization. diff --git a/vfs/direntry.c b/vfs/direntry.c index fda48627f..f9241afaa 100644 --- a/vfs/direntry.c +++ b/vfs/direntry.c @@ -1011,6 +1011,7 @@ vfs_s_ferrno (vfs *me) return me->verrno; } +#if 0 void vfs_s_dump (vfs *me, char *prefix, vfs_s_inode *ino) { @@ -1030,6 +1031,7 @@ vfs_s_dump (vfs *me, char *prefix, vfs_s_inode *ino) } } } +#endif char * vfs_s_getlocalcopy (vfs *me, char *path) diff --git a/vfs/extfs.c b/vfs/extfs.c index ec0bb968b..4f6ed1b5d 100644 --- a/vfs/extfs.c +++ b/vfs/extfs.c @@ -997,7 +997,8 @@ static int s_fstat (void *data, struct stat *buf) return 0; } -static int s_readlink (vfs *me, char *path, char *buf, int size) +static int +s_readlink (vfs *me, char *path, char *buf, int size) { struct archive *archive; char *q; @@ -1008,10 +1009,11 @@ static int s_readlink (vfs *me, char *path, char *buf, int size) return -1; entry = find_entry (archive->root_entry, q, 0, 0); if (entry == NULL) - return -1; - if (!S_ISLNK (entry->inode->mode)) ERRNOR (EINVAL, -1); - if (size > (i = strlen (entry->inode->linkname))) { - size = i; + return -1; + if (!S_ISLNK (entry->inode->mode)) + ERRNOR (EINVAL, -1); + if (size < (i = strlen (entry->inode->linkname))) { + i = size; } strncpy (buf, entry->inode->linkname, i); return i; diff --git a/vfs/mcfs.c b/vfs/mcfs.c index 7ba82ec89..6789fc64b 100644 --- a/vfs/mcfs.c +++ b/vfs/mcfs.c @@ -985,9 +985,12 @@ mcfs_readlink (vfs *me, char *path, char *buf, int size) if (!rpc_get (mc->sock, RPC_STRING, &stat_str, RPC_END)) return the_error (-1, EIO); + status = strlen (stat_str); + if (status < size) + size = status; strncpy (buf, stat_str, size); g_free (stat_str); - return strlen (buf); + return size; } static int diff --git a/vfs/mcserv.c b/vfs/mcserv.c index a64ff1e9a..07d5500ea 100644 --- a/vfs/mcserv.c +++ b/vfs/mcserv.c @@ -582,7 +582,7 @@ do_readlink (void) int n; rpc_get (msock, RPC_STRING, &file, RPC_END); - n = readlink (file, buffer, 2048); + n = readlink (file, buffer, 2048 - 1); send_status (n, errno); if (n >= 0) { buffer[n] = 0; @@ -1080,7 +1080,7 @@ do_login (void) /* This structure must be kept in synch with mcfs.h enums */ -static struct _command { +static const struct _command { char *command; void (*callback) (void); } commands[] = { @@ -1111,7 +1111,7 @@ static struct _command { "getupdir", do_getupdir}, { "login", do_login}, { "quit", do_quit}, { -"utime", do_utime},}; +"utime", do_utime}}; static int ncommands = sizeof (commands) / sizeof (struct _command);