From 3a50e66a59343d2d187f8d33ce1e7d45171a6269 Mon Sep 17 00:00:00 2001 From: antona Date: Sat, 24 Sep 2005 20:28:23 +0000 Subject: [PATCH] Fix a very(!) longstanding bug in ntfs_attr_find() and co. Also reapply fix to unistr.c name collation. --- libntfs/attrib.c | 24 +++++++----------------- libntfs/unistr.c | 2 +- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/libntfs/attrib.c b/libntfs/attrib.c index d06d199c..3c04870c 100644 --- a/libntfs/attrib.c +++ b/libntfs/attrib.c @@ -1559,23 +1559,10 @@ static int ntfs_attr_find(const ATTR_TYPES type, const ntfschar *name, const u8 *val, const u32 val_len, ntfs_attr_search_ctx *ctx) { ATTR_RECORD *a; - ntfs_volume *vol; - ntfschar *upcase; - u32 upcase_len; + ntfs_volume *vol = ctx->ntfs_ino->vol; + ntfschar *upcase = vol->upcase; + u32 upcase_len = vol->upcase_len; - if (!ctx || !ctx->mrec || !ctx->attr) { - errno = EINVAL; - return -1; - } - if (ic == IGNORE_CASE) { - vol = ctx->ntfs_ino->vol; - upcase = vol->upcase; - upcase_len = vol->upcase_len; - } else { - vol = NULL; - upcase = NULL; - upcase_len = 0; - } /* * Iterate over attributes in mft record starting at @ctx->attr, or the * attribute following that, if @ctx->is_first is TRUE. @@ -2176,9 +2163,12 @@ int ntfs_attr_lookup(const ATTR_TYPES type, const ntfschar *name, const VCN lowest_vcn, const u8 *val, const u32 val_len, ntfs_attr_search_ctx *ctx) { + ntfs_volume *vol; ntfs_inode *base_ni; - if (!ctx || !ctx->mrec || !ctx->attr) { + if (!ctx || !ctx->mrec || !ctx->attr || (name && (!ctx->ntfs_ino || + !(vol = ctx->ntfs_ino->vol) || !vol->upcase || + !vol->upcase_len))) { errno = EINVAL; return -1; } diff --git a/libntfs/unistr.c b/libntfs/unistr.c index c488ba6d..7fc7f64f 100644 --- a/libntfs/unistr.c +++ b/libntfs/unistr.c @@ -115,7 +115,7 @@ int ntfs_names_collate(const ntfschar *name1, const u32 name1_len, ntfschar c1, c2; #ifdef DEBUG - if (!name1 || !name2 || (ic && !upcase && upcase_len)) { + if (!name1 || !name2 || (ic && (!upcase || !upcase_len))) { Dputs("ntfs_names_collate received NULL pointer!"); exit(1); }