diff -Naurp ncpfs-2.2.6/sutil/ncpm_common.c ncpfs-2.2.6.oden/sutil/ncpm_common.c --- ncpfs-2.2.6/sutil/ncpm_common.c 2012-05-29 10:18:52.000000000 +0000 +++ ncpfs-2.2.6.oden/sutil/ncpm_common.c 2012-05-29 10:18:22.000000000 +0000 @@ -1447,6 +1447,7 @@ void add_mnt_entry(char* mount_name, cha struct mntent ment; int fd; FILE* mtab; + off_t goodoffset; if (check_name(mount_name) == -1 || check_name(mpnt) == -1) errexit(107, _("Illegal character in mount entry\n")); @@ -1481,14 +1482,25 @@ void add_mnt_entry(char* mount_name, cha if ((mtab = setmntent(MOUNTED, "a+")) == NULL) { + unlink(MOUNTED "~"); errexit(59, _("Can't open %s\n"), MOUNTED); } + fseek (mtab, 0, SEEK_END); + goodoffset = ftell(mtab); if (addmntent(mtab, &ment) == 1) { + /* restore good state */ + ftruncate(fileno(mtab), goodoffset); + endmntent(mtab); + unlink(MOUNTED "~"); errexit(60, _("Can't write mount entry\n")); } if (fchmod(fileno(mtab), 0644) == -1) { + /* restore good state */ + ftruncate(fileno(mtab), goodoffset); + endmntent(mtab); + unlink(MOUNTED "~"); errexit(61, _("Can't set perms on %s\n"), MOUNTED); } endmntent(mtab); diff -Naurp ncpfs-2.2.6/sutil/ncpumount.c ncpfs-2.2.6.oden/sutil/ncpumount.c --- ncpfs-2.2.6/sutil/ncpumount.c 2012-05-29 10:18:52.000000000 +0000 +++ ncpfs-2.2.6.oden/sutil/ncpumount.c 2012-05-29 10:18:22.000000000 +0000 @@ -208,7 +208,12 @@ static int __clearMtab (const char* moun i++; } if (!found) { - addmntent(new_mtab, mnt); + if (addmntent(new_mtab, mnt)) { + eprintf(_("Can't addmntent to %s: %s\n"), MOUNTED_TMP, + strerror(errno)); + endmntent(mtab); + return 1; + } } }