Fix #334 - Do not allow fs.link on directories

This commit is contained in:
Gideon Thomas 2014-12-06 01:16:22 -05:00
parent 68070d0768
commit 8c4de99a98
2 changed files with 16 additions and 0 deletions

View File

@ -942,6 +942,8 @@ function link_node(context, oldpath, newpath, callback) {
oldDirectoryData = result; oldDirectoryData = result;
if(!_(oldDirectoryData).has(oldname)) { if(!_(oldDirectoryData).has(oldname)) {
callback(new Errors.ENOENT('a component of either path prefix does not exist', oldname)); callback(new Errors.ENOENT('a component of either path prefix does not exist', oldname));
} else if(oldDirectoryData[oldname].type === 'DIRECTORY') {
callback(new Errors.EPERM('oldpath refers to a directory'));
} else { } else {
find_node(context, newParentPath, read_new_directory_data); find_node(context, newParentPath, read_new_directory_data);
} }

View File

@ -69,4 +69,18 @@ describe('fs.link', function() {
}); });
}); });
}); });
it('should not allow links to a directory', function(done) {
var fs = util.fs();
fs.mkdir('/mydir', function(error) {
if(error) throw error;
fs.link('/mydir', '/mydirlink', function(error) {
expect(error).to.exist;
expect(error.code).to.equal('EPERM');
done();
});
});
});
}); });