Skip to content

Commit

Permalink
sanitize signedness/const for pointers to char in hpfs a bit
Browse files Browse the repository at this point in the history
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Al Viro committed Mar 3, 2010
1 parent 1f70713 commit 7e7742e
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 82 deletions.
2 changes: 1 addition & 1 deletion fs/hpfs/anode.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ int hpfs_ea_read(struct super_block *s, secno a, int ano, unsigned pos,
}

int hpfs_ea_write(struct super_block *s, secno a, int ano, unsigned pos,
unsigned len, char *buf)
unsigned len, const char *buf)
{
struct buffer_head *bh;
char *data;
Expand Down
14 changes: 8 additions & 6 deletions fs/hpfs/dentry.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ static int hpfs_hash_dentry(struct dentry *dentry, struct qstr *qstr)

if (l == 1) if (qstr->name[0]=='.') goto x;
if (l == 2) if (qstr->name[0]=='.' || qstr->name[1]=='.') goto x;
hpfs_adjust_length((char *)qstr->name, &l);
/*if (hpfs_chk_name((char *)qstr->name,&l))*/
hpfs_adjust_length(qstr->name, &l);
/*if (hpfs_chk_name(qstr->name,&l))*/
/*return -ENAMETOOLONG;*/
/*return -ENOENT;*/
x:
Expand All @@ -38,14 +38,16 @@ static int hpfs_compare_dentry(struct dentry *dentry, struct qstr *a, struct qst
{
unsigned al=a->len;
unsigned bl=b->len;
hpfs_adjust_length((char *)a->name, &al);
/*hpfs_adjust_length((char *)b->name, &bl);*/
hpfs_adjust_length(a->name, &al);
/*hpfs_adjust_length(b->name, &bl);*/
/* 'a' is the qstr of an already existing dentry, so the name
* must be valid. 'b' must be validated first.
*/

if (hpfs_chk_name((char *)b->name, &bl)) return 1;
if (hpfs_compare_names(dentry->d_sb, (char *)a->name, al, (char *)b->name, bl, 0)) return 1;
if (hpfs_chk_name(b->name, &bl))
return 1;
if (hpfs_compare_names(dentry->d_sb, a->name, al, b->name, bl, 0))
return 1;
return 0;
}

Expand Down
14 changes: 7 additions & 7 deletions fs/hpfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static int hpfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
struct hpfs_dirent *de;
int lc;
long old_pos;
char *tempname;
unsigned char *tempname;
int c1, c2 = 0;
int ret = 0;

Expand Down Expand Up @@ -158,11 +158,11 @@ static int hpfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
tempname = hpfs_translate_name(inode->i_sb, de->name, de->namelen, lc, de->not_8x3);
if (filldir(dirent, tempname, de->namelen, old_pos, de->fnode, DT_UNKNOWN) < 0) {
filp->f_pos = old_pos;
if (tempname != (char *)de->name) kfree(tempname);
if (tempname != de->name) kfree(tempname);
hpfs_brelse4(&qbh);
goto out;
}
if (tempname != (char *)de->name) kfree(tempname);
if (tempname != de->name) kfree(tempname);
hpfs_brelse4(&qbh);
}
out:
Expand All @@ -187,7 +187,7 @@ static int hpfs_readdir(struct file *filp, void *dirent, filldir_t filldir)

struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
{
const char *name = dentry->d_name.name;
const unsigned char *name = dentry->d_name.name;
unsigned len = dentry->d_name.len;
struct quad_buffer_head qbh;
struct hpfs_dirent *de;
Expand All @@ -197,7 +197,7 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, struct name
struct hpfs_inode_info *hpfs_result;

lock_kernel();
if ((err = hpfs_chk_name((char *)name, &len))) {
if ((err = hpfs_chk_name(name, &len))) {
if (err == -ENAMETOOLONG) {
unlock_kernel();
return ERR_PTR(-ENAMETOOLONG);
Expand All @@ -209,7 +209,7 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, struct name
* '.' and '..' will never be passed here.
*/

de = map_dirent(dir, hpfs_i(dir)->i_dno, (char *) name, len, NULL, &qbh);
de = map_dirent(dir, hpfs_i(dir)->i_dno, name, len, NULL, &qbh);

/*
* This is not really a bailout, just means file not found.
Expand Down Expand Up @@ -250,7 +250,7 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, struct name
hpfs_result = hpfs_i(result);
if (!de->directory) hpfs_result->i_parent_dir = dir->i_ino;

hpfs_decide_conv(result, (char *)name, len);
hpfs_decide_conv(result, name, len);

if (de->has_acl || de->has_xtd_perm) if (!(dir->i_sb->s_flags & MS_RDONLY)) {
hpfs_error(result->i_sb, "ACLs or XPERM found. This is probably HPFS386. This driver doesn't support it now. Send me some info on these structures");
Expand Down
21 changes: 13 additions & 8 deletions fs/hpfs/dnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ static void set_last_pointer(struct super_block *s, struct dnode *d, dnode_secno

/* Add an entry to dnode and don't care if it grows over 2048 bytes */

struct hpfs_dirent *hpfs_add_de(struct super_block *s, struct dnode *d, unsigned char *name,
struct hpfs_dirent *hpfs_add_de(struct super_block *s, struct dnode *d,
const unsigned char *name,
unsigned namelen, secno down_ptr)
{
struct hpfs_dirent *de;
Expand Down Expand Up @@ -223,15 +224,15 @@ static void fix_up_ptrs(struct super_block *s, struct dnode *d)
/* Add an entry to dnode and do dnode splitting if required */

static int hpfs_add_to_dnode(struct inode *i, dnode_secno dno,
unsigned char *name, unsigned namelen,
const unsigned char *name, unsigned namelen,
struct hpfs_dirent *new_de, dnode_secno down_ptr)
{
struct quad_buffer_head qbh, qbh1, qbh2;
struct dnode *d, *ad, *rd, *nd = NULL;
dnode_secno adno, rdno;
struct hpfs_dirent *de;
struct hpfs_dirent nde;
char *nname;
unsigned char *nname;
int h;
int pos;
struct buffer_head *bh;
Expand Down Expand Up @@ -305,7 +306,9 @@ static int hpfs_add_to_dnode(struct inode *i, dnode_secno dno,
pos++;
}
copy_de(new_de = &nde, de);
memcpy(name = nname, de->name, namelen = de->namelen);
memcpy(nname, de->name, de->namelen);
name = nname;
namelen = de->namelen;
for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | pos, 4);
down_ptr = adno;
set_last_pointer(i->i_sb, ad, de->down ? de_down_pointer(de) : 0);
Expand Down Expand Up @@ -368,7 +371,8 @@ static int hpfs_add_to_dnode(struct inode *i, dnode_secno dno,
* I hope, now it's finally bug-free.
*/

int hpfs_add_dirent(struct inode *i, unsigned char *name, unsigned namelen,
int hpfs_add_dirent(struct inode *i,
const unsigned char *name, unsigned namelen,
struct hpfs_dirent *new_de, int cdepth)
{
struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
Expand Down Expand Up @@ -897,7 +901,8 @@ struct hpfs_dirent *map_pos_dirent(struct inode *inode, loff_t *posp,

/* Find a dirent in tree */

struct hpfs_dirent *map_dirent(struct inode *inode, dnode_secno dno, char *name, unsigned len,
struct hpfs_dirent *map_dirent(struct inode *inode, dnode_secno dno,
const unsigned char *name, unsigned len,
dnode_secno *dd, struct quad_buffer_head *qbh)
{
struct dnode *dnode;
Expand Down Expand Up @@ -988,8 +993,8 @@ void hpfs_remove_dtree(struct super_block *s, dnode_secno dno)
struct hpfs_dirent *map_fnode_dirent(struct super_block *s, fnode_secno fno,
struct fnode *f, struct quad_buffer_head *qbh)
{
char *name1;
char *name2;
unsigned char *name1;
unsigned char *name2;
int name1len, name2len;
struct dnode *d;
dnode_secno dno, downd;
Expand Down
7 changes: 4 additions & 3 deletions fs/hpfs/ea.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ static char *get_indirect_ea(struct super_block *s, int ano, secno a, int size)
return ret;
}

static void set_indirect_ea(struct super_block *s, int ano, secno a, char *data,
int size)
static void set_indirect_ea(struct super_block *s, int ano, secno a,
const char *data, int size)
{
hpfs_ea_write(s, a, ano, 0, size, data);
}
Expand Down Expand Up @@ -186,7 +186,8 @@ char *hpfs_get_ea(struct super_block *s, struct fnode *fnode, char *key, int *si
* This driver can't change sizes of eas ('cause I just don't need it).
*/

void hpfs_set_ea(struct inode *inode, struct fnode *fnode, char *key, char *data, int size)
void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
const char *data, int size)
{
fnode_secno fno = inode->i_ino;
struct super_block *s = inode->i_sb;
Expand Down
30 changes: 18 additions & 12 deletions fs/hpfs/hpfs_fn.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ secno hpfs_bplus_lookup(struct super_block *, struct inode *, struct bplus_heade
secno hpfs_add_sector_to_btree(struct super_block *, secno, int, unsigned);
void hpfs_remove_btree(struct super_block *, struct bplus_header *);
int hpfs_ea_read(struct super_block *, secno, int, unsigned, unsigned, char *);
int hpfs_ea_write(struct super_block *, secno, int, unsigned, unsigned, char *);
int hpfs_ea_write(struct super_block *, secno, int, unsigned, unsigned, const char *);
void hpfs_ea_remove(struct super_block *, secno, int, unsigned);
void hpfs_truncate_btree(struct super_block *, secno, int, unsigned);
void hpfs_remove_fnode(struct super_block *, fnode_secno fno);
Expand Down Expand Up @@ -244,13 +244,17 @@ extern const struct file_operations hpfs_dir_ops;

void hpfs_add_pos(struct inode *, loff_t *);
void hpfs_del_pos(struct inode *, loff_t *);
struct hpfs_dirent *hpfs_add_de(struct super_block *, struct dnode *, unsigned char *, unsigned, secno);
int hpfs_add_dirent(struct inode *, unsigned char *, unsigned, struct hpfs_dirent *, int);
struct hpfs_dirent *hpfs_add_de(struct super_block *, struct dnode *,
const unsigned char *, unsigned, secno);
int hpfs_add_dirent(struct inode *, const unsigned char *, unsigned,
struct hpfs_dirent *, int);
int hpfs_remove_dirent(struct inode *, dnode_secno, struct hpfs_dirent *, struct quad_buffer_head *, int);
void hpfs_count_dnodes(struct super_block *, dnode_secno, int *, int *, int *);
dnode_secno hpfs_de_as_down_as_possible(struct super_block *, dnode_secno dno);
struct hpfs_dirent *map_pos_dirent(struct inode *, loff_t *, struct quad_buffer_head *);
struct hpfs_dirent *map_dirent(struct inode *, dnode_secno, char *, unsigned, dnode_secno *, struct quad_buffer_head *);
struct hpfs_dirent *map_dirent(struct inode *, dnode_secno,
const unsigned char *, unsigned, dnode_secno *,
struct quad_buffer_head *);
void hpfs_remove_dtree(struct super_block *, dnode_secno);
struct hpfs_dirent *map_fnode_dirent(struct super_block *, fnode_secno, struct fnode *, struct quad_buffer_head *);

Expand All @@ -259,7 +263,8 @@ struct hpfs_dirent *map_fnode_dirent(struct super_block *, fnode_secno, struct f
void hpfs_ea_ext_remove(struct super_block *, secno, int, unsigned);
int hpfs_read_ea(struct super_block *, struct fnode *, char *, char *, int);
char *hpfs_get_ea(struct super_block *, struct fnode *, char *, int *);
void hpfs_set_ea(struct inode *, struct fnode *, char *, char *, int);
void hpfs_set_ea(struct inode *, struct fnode *, const char *,
const char *, int);

/* file.c */

Expand All @@ -282,7 +287,7 @@ void hpfs_delete_inode(struct inode *);

unsigned *hpfs_map_dnode_bitmap(struct super_block *, struct quad_buffer_head *);
unsigned *hpfs_map_bitmap(struct super_block *, unsigned, struct quad_buffer_head *, char *);
char *hpfs_load_code_page(struct super_block *, secno);
unsigned char *hpfs_load_code_page(struct super_block *, secno);
secno *hpfs_load_bitmap_directory(struct super_block *, secno bmp);
struct fnode *hpfs_map_fnode(struct super_block *s, ino_t, struct buffer_head **);
struct anode *hpfs_map_anode(struct super_block *s, anode_secno, struct buffer_head **);
Expand All @@ -292,12 +297,13 @@ dnode_secno hpfs_fnode_dno(struct super_block *s, ino_t ino);
/* name.c */

unsigned char hpfs_upcase(unsigned char *, unsigned char);
int hpfs_chk_name(unsigned char *, unsigned *);
char *hpfs_translate_name(struct super_block *, unsigned char *, unsigned, int, int);
int hpfs_compare_names(struct super_block *, unsigned char *, unsigned, unsigned char *, unsigned, int);
int hpfs_is_name_long(unsigned char *, unsigned);
void hpfs_adjust_length(unsigned char *, unsigned *);
void hpfs_decide_conv(struct inode *, unsigned char *, unsigned);
int hpfs_chk_name(const unsigned char *, unsigned *);
unsigned char *hpfs_translate_name(struct super_block *, unsigned char *, unsigned, int, int);
int hpfs_compare_names(struct super_block *, const unsigned char *, unsigned,
const unsigned char *, unsigned, int);
int hpfs_is_name_long(const unsigned char *, unsigned);
void hpfs_adjust_length(const unsigned char *, unsigned *);
void hpfs_decide_conv(struct inode *, const unsigned char *, unsigned);

/* namei.c */

Expand Down
4 changes: 2 additions & 2 deletions fs/hpfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void hpfs_read_inode(struct inode *i)
struct fnode *fnode;
struct super_block *sb = i->i_sb;
struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
unsigned char *ea;
void *ea;
int ea_size;

if (!(fnode = hpfs_map_fnode(sb, i->i_ino, &bh))) {
Expand Down Expand Up @@ -112,7 +112,7 @@ void hpfs_read_inode(struct inode *i)
}
}
if (fnode->dirflag) {
unsigned n_dnodes, n_subdirs;
int n_dnodes, n_subdirs;
i->i_mode |= S_IFDIR;
i->i_op = &hpfs_dir_iops;
i->i_fop = &hpfs_dir_ops;
Expand Down
6 changes: 3 additions & 3 deletions fs/hpfs/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ unsigned int *hpfs_map_bitmap(struct super_block *s, unsigned bmp_block,
* lowercasing table
*/

char *hpfs_load_code_page(struct super_block *s, secno cps)
unsigned char *hpfs_load_code_page(struct super_block *s, secno cps)
{
struct buffer_head *bh;
secno cpds;
Expand Down Expand Up @@ -71,7 +71,7 @@ char *hpfs_load_code_page(struct super_block *s, secno cps)
brelse(bh);
return NULL;
}
ptr = (char *)cpd + cpd->offs[cpi] + 6;
ptr = (unsigned char *)cpd + cpd->offs[cpi] + 6;
if (!(cp_table = kmalloc(256, GFP_KERNEL))) {
printk("HPFS: out of memory for code page table\n");
brelse(bh);
Expand Down Expand Up @@ -217,7 +217,7 @@ struct dnode *hpfs_map_dnode(struct super_block *s, unsigned secno,
if ((dnode = hpfs_map_4sectors(s, secno, qbh, DNODE_RD_AHEAD)))
if (hpfs_sb(s)->sb_chk) {
unsigned p, pp = 0;
unsigned char *d = (char *)dnode;
unsigned char *d = (unsigned char *)dnode;
int b = 0;
if (dnode->magic != DNODE_MAGIC) {
hpfs_error(s, "bad magic on dnode %08x", secno);
Expand Down
21 changes: 11 additions & 10 deletions fs/hpfs/name.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

#include "hpfs_fn.h"

static char *text_postfix[]={
static const char *text_postfix[]={
".ASM", ".BAS", ".BAT", ".C", ".CC", ".CFG", ".CMD", ".CON", ".CPP", ".DEF",
".DOC", ".DPR", ".ERX", ".H", ".HPP", ".HTM", ".HTML", ".JAVA", ".LOG", ".PAS",
".RC", ".TEX", ".TXT", ".Y", ""};

static char *text_prefix[]={
static const char *text_prefix[]={
"AUTOEXEC.", "CHANGES", "COPYING", "CONFIG.", "CREDITS", "FAQ", "FILE_ID.DIZ",
"MAKEFILE", "READ.ME", "README", "TERMCAP", ""};

void hpfs_decide_conv(struct inode *inode, unsigned char *name, unsigned len)
void hpfs_decide_conv(struct inode *inode, const unsigned char *name, unsigned len)
{
struct hpfs_inode_info *hpfs_inode = hpfs_i(inode);
int i;
Expand Down Expand Up @@ -71,7 +71,7 @@ static inline unsigned char locase(unsigned char *dir, unsigned char a)
return dir[a];
}

int hpfs_chk_name(unsigned char *name, unsigned *len)
int hpfs_chk_name(const unsigned char *name, unsigned *len)
{
int i;
if (*len > 254) return -ENAMETOOLONG;
Expand All @@ -83,10 +83,10 @@ int hpfs_chk_name(unsigned char *name, unsigned *len)
return 0;
}

char *hpfs_translate_name(struct super_block *s, unsigned char *from,
unsigned char *hpfs_translate_name(struct super_block *s, unsigned char *from,
unsigned len, int lc, int lng)
{
char *to;
unsigned char *to;
int i;
if (hpfs_sb(s)->sb_chk >= 2) if (hpfs_is_name_long(from, len) != lng) {
printk("HPFS: Long name flag mismatch - name ");
Expand All @@ -103,8 +103,9 @@ char *hpfs_translate_name(struct super_block *s, unsigned char *from,
return to;
}

int hpfs_compare_names(struct super_block *s, unsigned char *n1, unsigned l1,
unsigned char *n2, unsigned l2, int last)
int hpfs_compare_names(struct super_block *s,
const unsigned char *n1, unsigned l1,
const unsigned char *n2, unsigned l2, int last)
{
unsigned l = l1 < l2 ? l1 : l2;
unsigned i;
Expand All @@ -120,7 +121,7 @@ int hpfs_compare_names(struct super_block *s, unsigned char *n1, unsigned l1,
return 0;
}

int hpfs_is_name_long(unsigned char *name, unsigned len)
int hpfs_is_name_long(const unsigned char *name, unsigned len)
{
int i,j;
for (i = 0; i < len && name[i] != '.'; i++)
Expand All @@ -134,7 +135,7 @@ int hpfs_is_name_long(unsigned char *name, unsigned len)

/* OS/2 clears dots and spaces at the end of file name, so we have to */

void hpfs_adjust_length(unsigned char *name, unsigned *len)
void hpfs_adjust_length(const unsigned char *name, unsigned *len)
{
if (!*len) return;
if (*len == 1 && name[0] == '.') return;
Expand Down
Loading

0 comments on commit 7e7742e

Please sign in to comment.