Skip to content

Commit

Permalink
udf: Get rid of 0-length arrays in struct fileIdentDesc
Browse files Browse the repository at this point in the history
Get rid of 0-length arrays in struct fileIdentDesc. This requires a bit
of cleaning up as the second variable length array in this structure is
often used and the code abuses the fact that the first two arrays have
the same type and offset in struct fileIdentDesc.

Signed-off-by: Jan Kara <jack@suse.cz>
  • Loading branch information
Jan Kara committed Aug 11, 2021
1 parent b3c8c98 commit 979a6e2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
5 changes: 2 additions & 3 deletions fs/udf/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "udf_i.h"
#include "udf_sb.h"


static int udf_readdir(struct file *file, struct dir_context *ctx)
{
struct inode *dir = file_inode(file);
Expand Down Expand Up @@ -135,7 +134,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
lfi = cfi.lengthFileIdent;

if (fibh.sbh == fibh.ebh) {
nameptr = fi->fileIdent + liu;
nameptr = udf_get_fi_ident(fi);
} else {
int poffset; /* Unpaded ending offset */

Expand All @@ -153,7 +152,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
}
}
nameptr = copy_name;
memcpy(nameptr, fi->fileIdent + liu,
memcpy(nameptr, udf_get_fi_ident(fi),
lfi - poffset);
memcpy(nameptr + lfi - poffset,
fibh.ebh->b_data, poffset);
Expand Down
6 changes: 3 additions & 3 deletions fs/udf/ecma_167.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,9 @@ struct fileIdentDesc {
uint8_t lengthFileIdent;
struct long_ad icb;
__le16 lengthOfImpUse;
uint8_t impUse[0];
uint8_t fileIdent[0];
uint8_t padding[0];
uint8_t impUse[];
/* uint8_t fileIdent[]; */
/* uint8_t padding[]; */
} __packed;

/* File Characteristics (ECMA 167r3 4/14.4.3) */
Expand Down
3 changes: 1 addition & 2 deletions fs/udf/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,7 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode,
dfibh.eoffset += (sfibh.eoffset - sfibh.soffset);
dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset);
if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse,
sfi->fileIdent +
le16_to_cpu(sfi->lengthOfImpUse))) {
udf_get_fi_ident(sfi))) {
iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
brelse(dbh);
return NULL;
Expand Down
13 changes: 6 additions & 7 deletions fs/udf/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,

if (fileident) {
if (adinicb || (offset + lfi < 0)) {
memcpy((uint8_t *)sfi->fileIdent + liu, fileident, lfi);
memcpy(udf_get_fi_ident(sfi), fileident, lfi);
} else if (offset >= 0) {
memcpy(fibh->ebh->b_data + offset, fileident, lfi);
} else {
memcpy((uint8_t *)sfi->fileIdent + liu, fileident,
-offset);
memcpy(udf_get_fi_ident(sfi), fileident, -offset);
memcpy(fibh->ebh->b_data, fileident - offset,
lfi + offset);
}
Expand All @@ -88,11 +87,11 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
offset += lfi;

if (adinicb || (offset + padlen < 0)) {
memset((uint8_t *)sfi->padding + liu + lfi, 0x00, padlen);
memset(udf_get_fi_ident(sfi) + lfi, 0x00, padlen);
} else if (offset >= 0) {
memset(fibh->ebh->b_data + offset, 0x00, padlen);
} else {
memset((uint8_t *)sfi->padding + liu + lfi, 0x00, -offset);
memset(udf_get_fi_ident(sfi) + lfi, 0x00, -offset);
memset(fibh->ebh->b_data, 0x00, padlen + offset);
}

Expand Down Expand Up @@ -226,7 +225,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
lfi = cfi->lengthFileIdent;

if (fibh->sbh == fibh->ebh) {
nameptr = fi->fileIdent + liu;
nameptr = udf_get_fi_ident(fi);
} else {
int poffset; /* Unpaded ending offset */

Expand All @@ -246,7 +245,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
}
}
nameptr = copy_name;
memcpy(nameptr, fi->fileIdent + liu,
memcpy(nameptr, udf_get_fi_ident(fi),
lfi - poffset);
memcpy(nameptr + lfi - poffset,
fibh->ebh->b_data, poffset);
Expand Down
4 changes: 4 additions & 0 deletions fs/udf/udfdecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ static inline unsigned int udf_dir_entry_len(struct fileIdentDesc *cfi)
le16_to_cpu(cfi->lengthOfImpUse) + cfi->lengthFileIdent,
UDF_NAME_PAD);
}
static inline uint8_t *udf_get_fi_ident(struct fileIdentDesc *fi)
{
return ((uint8_t *)(fi + 1)) + le16_to_cpu(fi->lengthOfImpUse);
}

/* file.c */
extern long udf_ioctl(struct file *, unsigned int, unsigned long);
Expand Down

0 comments on commit 979a6e2

Please sign in to comment.