From: chip Date: Thu, 28 Nov 2002 00:17:15 +0000 (+0000) Subject: 2002-11-27 Chip Salzenberg X-Git-Tag: nfs-utils-1-0-2-pre5~3 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=2032d4680d3d0862a728ee0fa0b0675beccdf844;p=nfs-utils.git 2002-11-27 Chip Salzenberg * utils/mountd/rmtab.c (slink_safe_rename): Fix off-by-one buffer overflow bug. Reformat per rest of source file. --- diff --git a/ChangeLog b/ChangeLog index ee7d4d5..9fae2b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2002-11-27 Chip Salzenberg + + * utils/mountd/rmtab.c (slink_safe_rename): Fix off-by-one buffer + overflow bug. Reformat per rest of source file. + 2002-11-19 NeilBrown * utils/exportfs/exports.man: Correct notes about whether the wild diff --git a/utils/mountd/rmtab.c b/utils/mountd/rmtab.c index 0a4ed4c..869b5f8 100644 --- a/utils/mountd/rmtab.c +++ b/utils/mountd/rmtab.c @@ -29,30 +29,21 @@ static int slink_safe_rename(const char * oldpath, const char * newpath) { - int r; - struct stat s; - char slink_path[PATH_MAX]; - char real_newpath = newpath; - - if((lstat(newpath, &s) == 0) && (S_ISLNK(s.st_mode))) { - - /* New path is a symbolic link, do not destroy but follow */ - - if((r = readlink(newpath, slink_path, PATH_MAX))==-1) { - - return -1; - - } - - slink_path[ (r < PATH_MAX) ? (r + 1) : (PATH_MAX - 1)] = '\0'; - - real_newpath = slink_path; - - } - - return rename(oldpath, real_newpath); + int r; + struct stat s; + char slink_path[PATH_MAX]; + char real_newpath = newpath; + + if ((lstat(newpath, &s) == 0) && S_ISLNK(s.st_mode)) { + /* New path is a symbolic link, do not destroy but follow */ + if ((r = readlink(newpath, slink_path, PATH_MAX - 1)) == -1) + return -1; + slink_path[r] = '\0'; + real_newpath = slink_path; + } -}/* static int slink_safe_rename() */ + return rename(oldpath, real_newpath); +} void mountlist_add(nfs_export *exp, const char *path)