From 3b59b97c5c917df6283665101f08556f4a7978b7 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Fri, 15 Jan 2010 17:43:25 +0100 Subject: [PATCH 1/7] In ntfs_cluster_alloc(), don't set rc to itself. --- libntfs-3g/lcnalloc.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/libntfs-3g/lcnalloc.c b/libntfs-3g/lcnalloc.c index ae67843..9eb907c 100644 --- a/libntfs-3g/lcnalloc.c +++ b/libntfs-3g/lcnalloc.c @@ -473,7 +473,7 @@ done_zones_check: ntfs_log_trace("Switching zone.\n"); pass = 1; if (rlpos) { - LCN tc = tc = rl[rlpos - 1].lcn + + LCN tc = rl[rlpos - 1].lcn + rl[rlpos - 1].length + NTFS_LCNALLOC_SKIP; if (used_zone_pos) -- 1.6.6 From fd4102992080eed0cae1a612888a8d773ee09bb2 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Fri, 15 Jan 2010 17:51:44 +0100 Subject: [PATCH 2/7] Fix a NULL pointer dereference in ntfs_rl_truncate(), provided arl can actually be NULL. --- libntfs-3g/runlist.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/libntfs-3g/runlist.c b/libntfs-3g/runlist.c index f81996b..9364364 100644 --- a/libntfs-3g/runlist.c +++ b/libntfs-3g/runlist.c @@ -1620,7 +1620,12 @@ int ntfs_rl_truncate(runlist **arl, const VCN start_vcn) runlist *rl; BOOL is_end = FALSE; - if (!arl || !*arl) { + if (!arl) { + errno = EINVAL; + ntfs_log_perror("rl_truncate error: arl: %p", arl); + return -1; + } + if (!*arl) { errno = EINVAL; ntfs_log_perror("rl_truncate error: arl: %p *arl: %p", arl, *arl); return -1; -- 1.6.6 From 79787622d2ef80e97bf69d98965eff28dd5eb7ac Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Fri, 15 Jan 2010 17:57:48 +0100 Subject: [PATCH 3/7] Let main() return a defined value if (getuid() && ctx->blkdev) is false. --- src/ntfs-3g.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index 2ec127a..9ceb70e 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -3949,6 +3949,7 @@ int main(int argc, char *argv[]) #ifndef FUSE_INTERNAL if (getuid() && ctx->blkdev) { ntfs_log_error("%s", unpriv_fuseblk_msg); + err = NTFS_VOLUME_NO_PRIVILEGE; goto err2; } #endif -- 1.6.6 From 5d7e49496ea08fbf889a7c27dbadd27385f2b608 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Fri, 15 Jan 2010 18:06:28 +0100 Subject: [PATCH 4/7] Remove write-only variable err in ntfs_attr_record_rm() and let it use errno instead which seems to make more sense. --- libntfs-3g/attrib.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index bf21544..40a0385 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -3416,7 +3416,6 @@ int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx) { ntfs_inode *base_ni, *ni; ATTR_TYPES type; - int err; if (!ctx || !ctx->ntfs_ino || !ctx->mrec || !ctx->attr) { errno = EINVAL; @@ -3441,7 +3440,7 @@ int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx) if (ntfs_attrlist_entry_add(ni, ctx->attr)) ntfs_log_trace("Rollback failed. Leaving inconstant " "metadata.\n"); - err = EIO; + errno = EIO; return -1; } ntfs_inode_mark_dirty(ni); -- 1.6.6 From 721ee1dcc6a44c692b51bd4e4d92b60846e27270 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Fri, 15 Jan 2010 18:09:15 +0100 Subject: [PATCH 5/7] Fix a case where ntfs_attr_make_resident() would set err instead of errno. --- libntfs-3g/attrib.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index 40a0385..ee995ac 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -4563,7 +4563,7 @@ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) if (sle64_to_cpu(a->lowest_vcn)) { ntfs_log_trace("Eeek! Should be called for the first extent of the " "attribute. Aborting...\n"); - err = EINVAL; + errno = EINVAL; return -1; } -- 1.6.6 From ff78ab60e67084b2430740e4f82747d039fde0c9 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Fri, 15 Jan 2010 18:18:11 +0100 Subject: [PATCH 6/7] There's no need for the loop in ntfs_mbstoucs() to set cnt to 0. The value will never be read. Not doing it is also consitent with ntfs_ucstombs(). --- libntfs-3g/unistr.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/libntfs-3g/unistr.c b/libntfs-3g/unistr.c index 22eb2c6..6782adb 100644 --- a/libntfs-3g/unistr.c +++ b/libntfs-3g/unistr.c @@ -976,7 +976,7 @@ int ntfs_mbstoucs(const char *ins, ntfschar **outs) #else mbtowc(NULL, NULL, 0); #endif - for (i = o = cnt = 0; i < ins_size; i += cnt, o++) { + for (i = o = 0; i < ins_size; i += cnt, o++) { /* Reallocate memory if necessary. */ if (o >= ucs_len) { ntfschar *tc; -- 1.6.6 From 7254abf3c0be48241e11a1f70161fd30de1d60ac Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Fri, 15 Jan 2010 18:20:47 +0100 Subject: [PATCH 7/7] Let ntfs_attr_make_resident() set errno back to err after calling ntfs_log_trace(). This is a guess, but otherwise setting err to errno in the first place seems pointless. --- libntfs-3g/attrib.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index ee995ac..4b07320 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -4689,6 +4689,7 @@ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) ntfs_log_perror("Eeek! Failed to release allocated clusters"); ntfs_log_trace("Ignoring error and leaving behind wasted " "clusters.\n"); + errno = err; } /* Throw away the now unused runlist. */ -- 1.6.6