Removed member 'extension' from direntry_t structure and increased 'name' size

to 11. Accessing 'extension' data using 'name' index is illegal and at least
gcc version 7.5.0 has produced incorrect code for creating short file name.
This commit is contained in:
Volker Ruppert 2020-06-18 11:18:35 +00:00
parent af09838514
commit 4b27cc1103
2 changed files with 8 additions and 12 deletions

View File

@ -473,13 +473,11 @@ static void set_begin_of_direntry(direntry_t* direntry, Bit32u begin)
static inline Bit8u fat_chksum(const direntry_t* entry)
{
Bit8u chksum = 0;
Bit8u c, chksum = 0;
int i;
for (i = 0; i < 11; i++) {
unsigned char c;
c = (i < 8) ? entry->name[i] : entry->extension[i-8];
c = entry->name[i];
chksum = (((chksum & 0xfe) >> 1) | ((chksum & 0x01) ? 0x80:0)) + c;
}
@ -567,7 +565,7 @@ direntry_t* vvfat_image_t::create_short_and_long_name(
if (j > 0)
for (i = 0; i < 3 && tempfn[j+1+i]; i++)
entry->extension[i] = tempfn[j+1+i];
entry->name[i + 8] = tempfn[j+1+i];
// upcase & remove unwanted characters
for (i=10;i>=0;i--) {
@ -942,8 +940,7 @@ int vvfat_image_t::init_directories(const char* dirname)
entry->attributes = 0x28; // archive | volume label
entry->mdate = 0x3d81; // 01.12.2010
entry->mtime = 0x6000; // 12:00:00
memcpy(entry->name, "BOCHS VV", 8);
memcpy(entry->extension, "FAT", 3);
memcpy(entry->name, "BOCHS VVFAT", 11);
}
// Now build FAT, and write back information into directory
@ -1406,8 +1403,8 @@ direntry_t* vvfat_image_t::read_direntry(Bit8u *buffer, char *filename)
memcpy(filename, entry->name, 8);
i = 7;
while ((i > 0) && (filename[i] == ' ')) filename[i--] = 0;
if (entry->extension[0] != ' ') strcat(filename, ".");
memcpy(filename+i+2, entry->extension, 3);
if (entry->name[8] != ' ') strcat(filename, ".");
memcpy(filename+i+2, entry->name + 8, 3);
i = strlen(filename) - 1;
while (filename[i] == ' ') filename[i--] = 0;
for (i = 0; i < (int)strlen(filename); i++) {

View File

@ -6,7 +6,7 @@
// ported from QEMU block driver with some additions (see vvfat.cc)
//
// Copyright (c) 2004,2005 Johannes E. Schindelin
// Copyright (C) 2010-2012 The Bochs Project
// Copyright (C) 2010-2020 The Bochs Project
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@ -53,8 +53,7 @@ typedef
__declspec(align(1))
#endif
struct direntry_t {
Bit8u name[8];
Bit8u extension[3];
Bit8u name[8 + 3];
Bit8u attributes;
Bit8u reserved[2];
Bit16u ctime;