From: Derrick Brashear Date: Tue, 10 Sep 2013 01:27:54 +0000 (-0400) Subject: libuafs: return error on symlink to self X-Git-Tag: upstream/1.8.0_pre1^2~1009 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=286065f6d2fd5338252bf06b7ab6b4627a7bc4c9;p=packages%2Fo%2Fopenafs.git libuafs: return error on symlink to self if we are symlinked to ourself directly, return ELOOP. Change-Id: I408012c4a9afb6bab0e917677c940f65ad59c697 Reviewed-on: http://gerrit.openafs.org/10240 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- diff --git a/src/afs/UKERNEL/afs_usrops.c b/src/afs/UKERNEL/afs_usrops.c index efb52eaa8..f6195b9eb 100644 --- a/src/afs/UKERNEL/afs_usrops.c +++ b/src/afs/UKERNEL/afs_usrops.c @@ -1657,12 +1657,13 @@ uafs_RPCStatsClearPeer(void) * Lookup the target of a symbolic link * Call VN_HOLD on the output vnode if successful. * Returns zero on success, error code on failure. + * If provided, use a path for confirming we are not linked to ourself. * * Note: Caller must hold the AFS global lock. */ -int -uafs_LookupLink(struct usr_vnode *vp, struct usr_vnode *parentVp, - struct usr_vnode **vpp) +static int +uafs_LookupLinkPath(struct usr_vnode *vp, struct usr_vnode *parentVp, + char *ppathP, struct usr_vnode **vpp) { int code; int len; @@ -1699,6 +1700,16 @@ uafs_LookupLink(struct usr_vnode *vp, struct usr_vnode *parentVp, len = MAX_OSI_PATH + 1 - uio.uio_resid; pathP[len] = '\0'; + /* are we linked to ourname or ./ourname? ELOOP */ + if (ppathP) { + if ((strcmp(pathP, ppathP) == 0) || + ((pathP[0] == '.') && + (pathP[1] == '/') && + (strcmp(&(pathP[2]), ppathP) == 0))) { + return ELOOP; + } + } + /* * Find the target of the symbolic link */ @@ -1829,7 +1840,7 @@ uafs_LookupName(char *path, struct usr_vnode *parentVp, afs_osi_Free(tmpPath, strlen(path) + 1); return code; } - code = uafs_LookupLink(nextVp, vp, &linkVp); + code = uafs_LookupLinkPath(nextVp, vp, NULL, &linkVp); if (code) { VN_RELE(vp); VN_RELE(nextVp); @@ -1860,6 +1871,13 @@ uafs_LookupName(char *path, struct usr_vnode *parentVp, return 0; } +int +uafs_LookupLink(struct usr_vnode *vp, struct usr_vnode *parentVp, + struct usr_vnode **vpp) +{ + return uafs_LookupLinkPath(vp, parentVp, NULL, vpp); +} + /* * Lookup the parent of a file or directory given its path * Call VN_HOLD on the output vnode if successful.