svn commit: r230197 - stable/9/sys/fs/ntfs

Kevin Lo kevlo at FreeBSD.org
Mon Jan 16 05:22:19 UTC 2012


Author: kevlo
Date: Mon Jan 16 05:22:18 2012
New Revision: 230197
URL: http://svn.freebsd.org/changeset/base/230197

Log:
  MFC r228864:
  Discard local array based on return values.
  
  Pointed out by:	uqs
  Found with:	Coverity Prevent(tm)
  CID:	10089
  
  MFC 228023:
  Add unicode support to ntfs
  
  Obtained from:	imura

Modified:
  stable/9/sys/fs/ntfs/ntfs_subr.c
  stable/9/sys/fs/ntfs/ntfs_subr.h
  stable/9/sys/fs/ntfs/ntfs_vnops.c

Modified: stable/9/sys/fs/ntfs/ntfs_subr.c
==============================================================================
--- stable/9/sys/fs/ntfs/ntfs_subr.c	Mon Jan 16 05:15:13 2012	(r230196)
+++ stable/9/sys/fs/ntfs/ntfs_subr.c	Mon Jan 16 05:22:18 2012	(r230197)
@@ -667,23 +667,18 @@ ntfs_uastricmp(ntmp, ustr, ustrlen, astr
 	const char *astr;
 	size_t astrlen;
 {
-	int len;
+	const char *astrp = astr;
+	char tmpbuf[5];
+	int len, res;
 	size_t i, j, mbstrlen = astrlen;
-	int res;
-	wchar wc;
 
 	if (ntmp->ntm_ic_l2u) {
-		for (i = 0, j = 0; i < ustrlen && j < astrlen; i++, j++) {
-			if (j < astrlen -1) {
-				wc = (wchar)astr[j]<<8 | (astr[j+1]&0xFF);
-				len = 2;
-			} else {
-				wc = (wchar)astr[j]<<8 & 0xFF00;
-				len = 1;
-			}
+		for (i = 0, j = 0; i < ustrlen && j < astrlen; i++) {
+			len = 4;
 			res = ((int) NTFS_TOUPPER(ustr[i])) -
-				((int)NTFS_TOUPPER(NTFS_82U(wc, &len)));
-			j += len - 1;
+			    ((int)NTFS_TOUPPER(NTFS_82U(astrp, &len)));
+			astrp += len;
+			j += len;
 			mbstrlen -= len - 1;
 
 			if (res)
@@ -696,7 +691,8 @@ ntfs_uastricmp(ntmp, ustr, ustrlen, astr
 		 */
 		for (i = 0; i < ustrlen && i < astrlen; i++) {
 			res = ((int) NTFS_TOUPPER(NTFS_82U(NTFS_U28(ustr[i]), &len))) -
-				((int)NTFS_TOUPPER(NTFS_82U((wchar)astr[i], &len)));
+				((int)NTFS_TOUPPER(NTFS_82U(astrp, &len)));
+			astrp++;
 			if (res)
 				return res;
 		}
@@ -715,23 +711,18 @@ ntfs_uastrcmp(ntmp, ustr, ustrlen, astr,
 	const char *astr;
 	size_t astrlen;
 {
-	char u, l;
+	char *c, tmpbuf[5];
 	size_t i, j, mbstrlen = astrlen;
 	int res;
-	wchar wc;
 
-	for (i = 0, j = 0; (i < ustrlen) && (j < astrlen); i++, j++) {
-		res = 0;
-		wc = NTFS_U28(ustr[i]);
-		u = (char)(wc>>8);
-		l = (char)wc;
-		if (u != '\0' && j < astrlen -1) {
-			res = (int) (u - astr[j++]);
+	for (i = 0, j = 0; (i < ustrlen) && (j < astrlen); i++, mbstrlen++) {
+		c = NTFS_U28(ustr[i]);
+		while (*c != '\0') {
+			res = (int) (*c++ - astr[j++]);
+			if (res)
+				return res;
 			mbstrlen--;
 		}
-		res = (res<<8) + (int) (l - astr[j]);
-		if (res)
-			return res;
 	}
 	return (ustrlen - mbstrlen);
 }
@@ -2135,50 +2126,48 @@ ntfs_82u_uninit(struct ntfsmount *ntmp)
 }
 
 /*
- * maps the Unicode char to 8bit equivalent
- * XXX currently only gets lower 8bit from the Unicode char
- * and substitutes a '_' for it if the result would be '\0';
- * something better has to be definitely though out
+ * maps the Unicode char to local character
  */
-wchar
+char *
 ntfs_u28(
+	char *outbuf,
 	struct ntfsmount *ntmp, 
 	wchar wc)
 {
-	char *p, *outp, inbuf[3], outbuf[3];
+	char *p, *outp, inbuf[3];
 	size_t ilen, olen;
 
+	outp = outbuf;
 	if (ntfs_iconv && ntmp->ntm_ic_u2l) {
-		ilen = olen = 2;
+		ilen = 2;
+		olen = 4;
 
 		inbuf[0] = (char)(wc>>8);
 		inbuf[1] = (char)wc;
 		inbuf[2] = '\0';
 		p = inbuf;
-		outp = outbuf;
 		ntfs_iconv->convchr(ntmp->ntm_ic_u2l, (const char **)&p, &ilen,
 				    &outp, &olen);
-		if (olen == 1) {
-			return ((wchar)(outbuf[0]&0xFF));
-		} else if (olen == 0) {
-			return ((wchar)((outbuf[0]<<8) | (outbuf[1]&0xFF)));
-		}
-		return ('?');
+		if (olen == 4)
+			*outp++ = '?';
+		*outp = '\0';
+		outp = outbuf;
+		return (outp);
 	}
 
 	p = ntmp->ntm_u28[(wc>>8)&0xFF];
-	if (p == NULL)
-		return ('_');
-	return (p[wc&0xFF]&0xFF);
+	outbuf[0] = (p == NULL) ? '_' : p[wc&0xFF] & 0xFF;
+	outbuf[1] = '\0';
+	return (outp);
 }
 
 wchar
 ntfs_82u(
 	struct ntfsmount *ntmp, 
-	wchar wc,
+	const char *c,
 	int *len)
 {
-	char *p, *outp, inbuf[3], outbuf[3];
+	char *outp, outbuf[3];
 	wchar uc;
 	size_t ilen, olen;
 
@@ -2186,13 +2175,8 @@ ntfs_82u(
 		ilen = (size_t)*len;
 		olen = 2;
 
-		inbuf[0] = (char)(wc>>8);
-		inbuf[1] = (char)wc;
-		inbuf[2] = '\0';
-		p = inbuf;
 		outp = outbuf;
-		ntfs_iconv->convchr(ntmp->ntm_ic_l2u, (const char **)&p, &ilen,
-				    &outp, &olen);
+		ntfs_iconv->convchr(ntmp->ntm_ic_l2u, &c, &ilen, &outp, &olen);
 		*len -= (int)ilen;
 		uc = (wchar)((outbuf[0]<<8) | (outbuf[1]&0xFF));
 
@@ -2200,7 +2184,7 @@ ntfs_82u(
 	}
 
 	if (ntmp->ntm_82u != NULL)
-		return (ntmp->ntm_82u[wc&0xFF]);
+		return (ntmp->ntm_82u[*c&0xFF]);
 
 	return ('?');
 }

Modified: stable/9/sys/fs/ntfs/ntfs_subr.h
==============================================================================
--- stable/9/sys/fs/ntfs/ntfs_subr.h	Mon Jan 16 05:15:13 2012	(r230196)
+++ stable/9/sys/fs/ntfs/ntfs_subr.h	Mon Jan 16 05:22:18 2012	(r230197)
@@ -112,9 +112,9 @@ int ntfs_u28_init(struct ntfsmount *ntmp
 int ntfs_u28_uninit(struct ntfsmount *ntmp);
 int ntfs_82u_init(struct ntfsmount *ntmp, char *cs_local, char *cs_ntfs);
 int ntfs_82u_uninit(struct ntfsmount *ntmp);
-wchar ntfs_u28(struct ntfsmount *ntmp, wchar wc);
-wchar ntfs_82u(struct ntfsmount *ntmp, wchar wc, int *len);
-#define NTFS_U28(ch)		ntfs_u28(ntmp, (ch))
+char * ntfs_u28(char *outbuf, struct ntfsmount *ntmp, wchar wc);
+wchar ntfs_82u(struct ntfsmount *ntmp, const char *c, int *len);
+#define NTFS_U28(ch)		ntfs_u28(tmpbuf, ntmp, (ch))
 #define NTFS_82U(ch, len)	ntfs_82u(ntmp, (ch), len)
 #define	NTFS_UASTRCMP(ustr, ustrlen, astr, astrlen)	\
 	ntfs_uastrcmp(ntmp, (ustr), (ustrlen), (astr), (astrlen))

Modified: stable/9/sys/fs/ntfs/ntfs_vnops.c
==============================================================================
--- stable/9/sys/fs/ntfs/ntfs_vnops.c	Mon Jan 16 05:15:13 2012	(r230196)
+++ stable/9/sys/fs/ntfs/ntfs_vnops.c	Mon Jan 16 05:22:18 2012	(r230197)
@@ -481,7 +481,7 @@ ntfs_readdir(ap)
 	struct uio *uio = ap->a_uio;
 	struct ntfsmount *ntmp = ip->i_mp;
 	int i, j, error = 0;
-	wchar c;
+	char *c, tmpbuf[5];
 	u_int32_t faked = 0, num;
 	int ncookies = 0;
 	struct dirent cde;
@@ -538,11 +538,10 @@ ntfs_readdir(ap)
 			if(!ntfs_isnamepermitted(ntmp,iep))
 				continue;
 
-			for(i=0, j=0; i<iep->ie_fnamelen; i++, j++) {
+			for(i=0, j=0; i<iep->ie_fnamelen; i++) {
 				c = NTFS_U28(iep->ie_fname[i]);
-				if (c&0xFF00)
-					cde.d_name[j++] = (char)(c>>8);
-				cde.d_name[j] = (char)c&0xFF;
+				while (*c != '\0')
+					cde.d_name[j++] = *c++;
 			}
 			cde.d_name[j] = '\0';
 			dprintf(("ntfs_readdir: elem: %d, fname:[%s] type: %d, flag: %d, ",


More information about the svn-src-stable-9 mailing list