Fix SEGV in rename error paths and add tests

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
libnfs-4.0.0-vitalif
Ronnie Sahlberg 2017-07-02 07:48:56 +10:00
parent 903021ed59
commit 0c5732eb26
3 changed files with 73 additions and 4 deletions

View File

@ -434,6 +434,7 @@ nfs3_lookup_path_getattr_cb(struct rpc_context *rpc, int status,
nfs3_lookup_path_async_internal(nfs, &attr, data, &nfs->rootfh);
}
/* This function will free continue_data on error */
static int
nfs3_lookuppath_async(struct nfs_context *nfs, const char *path, int no_follow,
nfs_cb cb, void *private_data,
@ -453,8 +454,9 @@ nfs3_lookuppath_async(struct nfs_context *nfs, const char *path, int no_follow,
if (data == NULL) {
nfs_set_error(nfs, "Out of memory: failed to allocate "
"nfs_cb_data structure");
if (free_continue_data)
free_continue_data(continue_data);
if (continue_data) {
free_continue_data(continue_data);
}
return -1;
}
memset(data, 0, sizeof(struct nfs_cb_data));
@ -1183,6 +1185,7 @@ nfs3_link_continue_1_internal(struct nfs_context *nfs,
link_data, free_nfs_link_data, 0) != 0) {
data->cb(-ENOMEM, nfs, nfs_get_error(nfs),
data->private_data);
data->continue_data = NULL;
free_nfs_cb_data(data);
return -1;
}
@ -1352,6 +1355,7 @@ nfs3_rename_continue_1_internal(struct nfs_context *nfs,
rename_data, free_nfs_rename_data, 0) != 0) {
data->cb(-ENOMEM, nfs, nfs_get_error(nfs),
data->private_data);
data->continue_data = NULL;
free_nfs_cb_data(data);
return -1;
}
@ -1424,7 +1428,6 @@ nfs3_rename_async(struct nfs_context *nfs, const char *oldpath,
return -1;
}
if (nfs3_lookuppath_async(nfs, rename_data->oldparent, 0,
cb, private_data,
nfs3_rename_continue_1_internal,

View File

@ -101,6 +101,11 @@ echo -n "Rename from outside share ... "
./prog_rename "${TESTURL}/" "subdir" ../../testfile ../subdir2/renamed11 2>/dev/null && failure
success
echo -n "Rename to outside share ... "
echo "kangabanga" > "${TESTDIR}/subdir/testfile"
./prog_rename "${TESTURL}/" "subdir" ./testfile ../../subdir2/renamed12 2>/dev/null && failure
success
stop_share

View File

@ -6,6 +6,9 @@ echo "basic valgrind leak check"
start_share
mkdir "${TESTDIR}/subdir"
mkdir "${TESTDIR}/subdir2"
echo -n "Create 100 1M files ... "
for IDX in `seq 1 100`; do
dd if=/dev/zero of="${TESTDIR}/file.$IDX" bs=1M count=10 2>/dev/null || failure
@ -57,10 +60,68 @@ libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ./prog_syml
success
echo -n "test nfs_symlink()/nfs_readlink() for memory leaks (2) ... "
mkdir "${TESTDIR}/subdir"
libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ./prog_symlink "${TESTURL}/" "." kangabanga /subdir/symlink >/dev/null 2>&1 || failure
success
echo -n "test nfs_rename() for memory leaks (1) ... "
echo "kangabanga" > "${TESTDIR}/testfile"
libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ./prog_rename "${TESTURL}/" "." /testfile /renamed1 >/dev/null 2>&1 || failure
success
echo -n "test nfs_rename() for memory leaks (2) ... "
echo "kangabanga" > "${TESTDIR}/testfile"
libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ./prog_rename "${TESTURL}/" "." testfile /renamed2 >/dev/null 2>&1 || failure
success
echo -n "test nfs_rename() for memory leaks (3) ... "
echo "kangabanga" > "${TESTDIR}/testfile"
libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ./prog_rename "${TESTURL}/" "." testfile renamed3 >/dev/null 2>&1 || failure
success
echo -n "test nfs_rename() for memory leaks (4) ... "
echo "kangabanga" > "${TESTDIR}/testfile"
libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ./prog_rename "${TESTURL}/" "." /testfile renamed4 >/dev/null 2>&1 || failure
success
echo -n "test nfs_rename() for memory leaks (5) ... "
echo "kangabanga" > "${TESTDIR}/subdir/testfile"
libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ./prog_rename "${TESTURL}/" "." /subdir/testfile /subdir/renamed5 >/dev/null 2>&1 || failure
success
echo -n "test nfs_rename() for memory leaks (6) ... "
echo "kangabanga" > "${TESTDIR}/subdir/testfile"
libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ./prog_rename "${TESTURL}/" "." subdir/testfile /subdir/renamed6 >/dev/null 2>&1 || failure
success
echo -n "test nfs_rename() for memory leaks (7) ... "
echo "kangabanga" > "${TESTDIR}/subdir/testfile"
libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ./prog_rename "${TESTURL}/" "." subdir/testfile subdir/renamed7 >/dev/null 2>&1 || failure
success
echo -n "test nfs_rename() for memory leaks (8) ... "
echo "kangabanga" > "${TESTDIR}/subdir/testfile"
libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ./prog_rename "${TESTURL}/" "." /subdir/testfile subdir/renamed8 >/dev/null 2>&1 || failure
success
echo -n "test nfs_rename() for memory leaks (9) ... "
echo "kangabanga" > "${TESTDIR}/subdir/testfile"
libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ./prog_rename "${TESTURL}/" "." /subdir/testfile subdir2/renamed9 >/dev/null 2>&1 || failure
success
echo -n "test nfs_rename() for memory leaks (10) ... "
echo "kangabanga" > "${TESTDIR}/subdir/testfile"
libtool --mode=execute valgrind --leak-check=full --error-exitcode=1 ./prog_rename "${TESTURL}/" "subdir" ./testfile ../subdir2/renamed10 >/dev/null 2>&1 || failure
success
echo -n "test nfs_rename() for memory leaks (11) ... "
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_rename "${TESTURL}/" "subdir" ../../testfile ../subdir2/renamed11 >/dev/null 2>&1 || expr $? != 99 >/dev/null || failure
success
echo -n "test nfs_rename() for memory leaks (12) ... "
echo "kangabanga" > "${TESTDIR}/subdir/testfile"
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_rename "${TESTURL}/" "subdir" ./testfile ../../subdir2/renamed12 >/dev/null 2>&1 || expr $? != 99 >/dev/null || failure
success
stop_share
exit 0