From 376b8c93d887343b21f98454ab4123e6692f690c Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Sun, 19 Feb 2006 01:15:42 +0000 Subject: [PATCH] Correct handling of MS-DOS reserved names. --- nulib2/Binary2.c | 4 ++-- nulib2/ChangeLog.txt | 6 ++++++ nulib2/SysUtils.c | 18 +++++++++++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/nulib2/Binary2.c b/nulib2/Binary2.c index d1e656e..6126b36 100644 --- a/nulib2/Binary2.c +++ b/nulib2/Binary2.c @@ -683,7 +683,7 @@ BNYUnSqueeze(BNYArchive* pBny, BNYEntry* pEntry, FILE* outfp) */ Assert(kSqBufferSize > 1200); #ifdef FULL_SQ_HEADER - err = USQReadShort(&usqState, &magic); + err = USQReadShort(&usqState, (short*) &magic); if (err != kNuErrNone) goto bail; if (magic != kNuSQMagic) { @@ -692,7 +692,7 @@ BNYUnSqueeze(BNYArchive* pBny, BNYEntry* pEntry, FILE* outfp) goto bail; } - err = USQReadShort(&usqState, &fileChecksum); + err = USQReadShort(&usqState, (short*) &fileChecksum); if (err != kNuErrNone) goto bail; diff --git a/nulib2/ChangeLog.txt b/nulib2/ChangeLog.txt index a0846b3..431293b 100644 --- a/nulib2/ChangeLog.txt +++ b/nulib2/ChangeLog.txt @@ -1,3 +1,9 @@ +2006/02/18 ***** v2.1.1 shipped ***** + +2006/02/18 fadden + - Fix handling of MS-DOS reserved names. Besides handling names like + "con", we also need to handle "con.foo.txt". + 2005/09/17 ***** v2.1.0 shipped ***** 2004/10/11 ***** v2.0.3 shipped ***** diff --git a/nulib2/SysUtils.c b/nulib2/SysUtils.c index 69ff0f9..76a0faa 100644 --- a/nulib2/SysUtils.c +++ b/nulib2/SysUtils.c @@ -115,6 +115,9 @@ UNIXNormalizeFileName(NulibState* pState, const char* srcp, long srcLen, * a '_' (if we're not preserving filenames) or "%00" (if we are). The * "%00" sequence gets stripped off during denormalization. * + * For some reason FAT is actually even more picky than that, insisting + * that files like "CON.FOO.TXT" are also illegal. + * * The list comes from the Linux kernel's fs/msdos/namei.c. */ static const char* fatReservedNames3[] = { @@ -135,12 +138,14 @@ Win32NormalizeFileName(NulibState* pState, const char* srcp, long srcLen, const char* startp = srcp; static const char* kInvalid = "\\/:*?\"<>|"; - /* look for an exact match */ - if (srcLen == 3) { + /* look for a match on "aux" or "aux\..*" */ + if (srcLen >= 3) { const char** ppcch; for (ppcch = fatReservedNames3; *ppcch != nil; ppcch++) { - if (strncasecmp(srcp, *ppcch, srcLen) == 0) { + if (strncasecmp(srcp, *ppcch, 3) == 0 && + srcp[3] == '.' || srcLen == 3) + { DBUG(("--- fixing '%s'\n", *ppcch)); if (NState_GetModPreserveType(pState)) { *dstp++ = kForeignIndic; @@ -151,11 +156,14 @@ Win32NormalizeFileName(NulibState* pState, const char* srcp, long srcLen, break; } } - } else if (srcLen == 4) { + } + if (srcLen >= 4) { const char** ppcch; for (ppcch = fatReservedNames4; *ppcch != nil; ppcch++) { - if (strncasecmp(srcp, *ppcch, srcLen) == 0) { + if (strncasecmp(srcp, *ppcch, 4) == 0 && + srcp[4] == '.' || srcLen == 4) + { DBUG(("--- fixing '%s'\n", *ppcch)); if (NState_GetModPreserveType(pState)) { *dstp++ = kForeignIndic;