When vp->v_type == VDIR we jump to out where newdp is freed
via the drele call but newdp has yet to be initialized. We
solve this by checking the output of namei first.
Signed-off-by: Constantin Raducanu <raducanu.costi@gmail.com>
Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
vp = olddp->d_vnode;
vn_lock(vp);
- if (vp->v_type == VDIR) {
- error = EPERM;
- goto out;
- }
-
/* If newpath exists, it shouldn't be overwritten */
if (!namei(newpath, &newdp)) {
error = EEXIST;
goto out;
}
+ if (vp->v_type == VDIR) {
+ error = EPERM;
+ goto out;
+ }
+
/* Get pointer to the parent dentry of newpath */
if ((error = lookup(newpath, &newdirdp, &name)) != 0)
goto out;