[PATCH] 2.4.0-test7: Small NTFS fixes

From: Anton Altaparmakov (aia21@cus.cam.ac.uk)
Date: Sun Aug 27 2000 - 16:44:25 EST


Linus,

Please apply attached patch to the next 2.4.0 release.

- Patch fixes two bugs which I came across reading fs/ntfs/inode.c. They
fix only very rarely (possibly never) occuring events but still having
code that can lead to dereferencing a NULL pointer in the kernel is a Bad
Thing (tm) and I have hence eliminated these cases...

- Also, I have added myself to the Credits file. (-:

Regards,

        Anton

-- 

Anton Altaparmakov Phone: +44-(0)1223-333541 (lab) Christ's College eMail: AntonA@bigfoot.com Cambridge CB2 3BU WWW: http://www-stu.christs.cam.ac.uk/~aia21/ United Kingdom ICQ: 8561279

diff -ru linux-2.4.0-test7/CREDITS linux/CREDITS --- linux-2.4.0-test7/CREDITS Tue Aug 22 23:21:53 2000 +++ linux/CREDITS Sun Aug 27 22:25:48 2000 @@ -62,6 +62,15 @@ S: B-2610 Wilrijk-Antwerpen S: Belgium +N: Anton Altaparmakov +E: aia21@cus.cam.ac.uk +W: http://www-stu.christs.cam.ac.uk/~aia21/ +D: NTFS fixes and temporal maintainer +D: Other random tiny fixes +S: Christ's College +S: Cambridge CB2 3BU +S: United Kingdom + N: C. Scott Ananian E: cananian@alumni.princeton.edu W: http://www.pdos.lcs.mit.edu/~cananian diff -ru linux-2.4.0-test7/fs/ntfs/Makefile linux/fs/ntfs/Makefile --- linux-2.4.0-test7/fs/ntfs/Makefile Wed Jul 5 20:21:54 2000 +++ linux/fs/ntfs/Makefile Sun Aug 27 22:27:36 2000 @@ -3,7 +3,7 @@ O_TARGET := ntfs.o O_OBJS := fs.o sysctl.o support.o util.o inode.o dir.o super.o attr.o M_OBJS := $(O_TARGET) -EXTRA_CFLAGS = -DNTFS_IN_LINUX_KERNEL -DNTFS_VERSION=\"000607\" +EXTRA_CFLAGS = -DNTFS_IN_LINUX_KERNEL -DNTFS_VERSION=\"000827\" include $(TOPDIR)/Rules.make diff -ru linux-2.4.0-test7/fs/ntfs/inode.c linux/fs/ntfs/inode.c --- linux-2.4.0-test7/fs/ntfs/inode.c Wed Jun 21 18:10:02 2000 +++ linux/fs/ntfs/inode.c Sun Aug 27 18:56:55 2000 @@ -58,30 +58,27 @@ NTFS_PUTU32(mft + attr_offset, 0xffffffff); /* End marker */ } -/* Search in an inode an attribute by type and name */ -ntfs_attribute* -ntfs_find_attr(ntfs_inode *ino,int type,char *name) +/* Search in an inode an attribute by type and name. */ +ntfs_attribute *ntfs_find_attr(ntfs_inode *ino, int type, char *name) { int i; - if(!ino){ + if (!ino) { ntfs_error("ntfs_find_attr: NO INODE!\n"); return 0; } - for(i=0;i<ino->attr_count;i++) + for (i = 0; i < ino->attr_count; i++) { - if(type==ino->attrs[i].type) - { - if(!name && !ino->attrs[i].name) - return ino->attrs+i; - if(name && !ino->attrs[i].name) - return 0; - if(!name && ino->attrs[i].name) - return 0; - if(ntfs_ua_strncmp(ino->attrs[i].name,name,strlen(name))==0) - return ino->attrs+i; - } - if(type<ino->attrs[i].type) + if (type < ino->attrs[i].type) return 0; + if (type == ino->attrs[i].type) { + if (!name) { + if (!ino->attrs[i].name) + return ino->attrs + i; + } else if (ino->attrs[i].name && + !ntfs_ua_strncmp(ino->attrs[i].name, + name, strlen(name))) + return ino->attrs + i; + } } return 0; } @@ -343,7 +340,7 @@ } /* Return (in result) the value indicating the next available attribute - chunk number. Works for inodes w/o extension records only */ + chunk number. Works for inodes w/o extension records only. */ int ntfs_allocate_attr_number(ntfs_inode *ino, int *result) { if(ino->record_count!=1) @@ -353,35 +350,38 @@ return 0; } -/* find the location of an attribute in the inode. A name of NULL indicates - unnamed attributes. Return pointer to attribute or NULL if not found */ -char * -ntfs_get_attr(ntfs_inode *ino,int attr,char *name) +/* Find the location of an attribute in the inode. A name of NULL indicates + unnamed attributes. Return pointer to attribute or NULL if not found. */ +char *ntfs_get_attr(ntfs_inode *ino, int attr, char *name) { - /* location of first attribute */ - char *it= ino->attr + NTFS_GETU16(ino->attr + 0x14); + /* Location of first attribute. */ + char *it = ino->attr + NTFS_GETU16(ino->attr + 0x14); int type; int len; /* Only check for magic DWORD here, fixup should have happened before */ - if(!IS_MFT_RECORD(ino->attr))return 0; + if (!IS_MFT_RECORD(ino->attr)) return 0; do{ - type=NTFS_GETU32(it); - len=NTFS_GETU16(it+4); + type = NTFS_GETU32(it); + len = NTFS_GETU16(it+4); /* We found the attribute type. Is the name correct, too? */ - if(type==attr) - { - int namelen=NTFS_GETU8(it+9); + if (type==attr) { + int namelen = NTFS_GETU8(it+9); char *name_it; - /* match given name and attribute name if present, - make sure attribute name is Unicode */ - for(name_it=it+NTFS_GETU16(it+10);namelen; - name++,name_it+=2,namelen--) - if(*name_it!=*name || name_it[1])break; - if(!namelen)break; + char *n = name; + /* Match given name and attribute name if present. + Make sure attribute name is Unicode. */ + if (!name) { + if (!namelen) break; + } else if (namelen) { + for (name_it = it+NTFS_GETU16(it+10); namelen; + n++, name_it += 2, namelen--) + if (*name_it != *n || name_it[1]) break; + if (!namelen) break; + } } - it+=len; - }while(type!=-1); /* attribute list end with type -1 */ - if(type==-1)return 0; + it += len; + } while (type != -1); /* Attribute lists end with type -1. */ + if (type == -1) return 0; return it; } - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Aug 31 2000 - 21:00:19 EST