1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[ext2fs] fix Coverity warnings

This commit is contained in:
Pete Batard 2019-04-13 17:17:23 +01:00
parent 9610e3a63b
commit 5159b1eb87
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
9 changed files with 43 additions and 130 deletions

View file

@ -305,9 +305,8 @@ errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode,
{
struct ext2_inode inode_buf;
ext2_extent_handle_t handle = 0;
blk_t addr_per_block;
blk_t b, blk32;
blk64_t b64;
blk64_t b64, addr_per_block;
char *buf = 0;
errcode_t retval = 0;
int blocks_alloc = 0, inode_dirty = 0;
@ -331,7 +330,7 @@ errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode,
return retval;
inode = &inode_buf;
}
addr_per_block = (blk_t) fs->blocksize >> 2;
addr_per_block = (blk64_t) fs->blocksize >> 2;
if (ext2fs_file_block_offset_too_big(fs, inode, block))
return EXT2_ET_FILE_TOO_BIG;

View file

@ -592,7 +592,7 @@ typedef struct ext2_icount *ext2_icount_t;
*/
#define EXT2_CHECK_MAGIC(struct, code) \
if ((struct)->magic != (code)) return (code)
if (!(struct) || (struct)->magic != (code)) return (code)
/*
* Features supported by this version of the library

View file

@ -1730,6 +1730,8 @@ size_t ext2fs_max_extent_depth(ext2_extent_handle_t handle)
if (last_blocksize && last_blocksize == handle->fs->blocksize)
return last_result;
if (ul_log2(extents_per_block) == 0)
return last_result;
last_result = 1 + ((ul_log2(EXT_MAX_EXTENT_LBLK) - ul_log2(iblock_extents)) /
ul_log2(extents_per_block));

View file

@ -65,6 +65,7 @@ void ext2fs_free(ext2_filsys fs)
fs->magic = 0;
// coverity[check_return]
ext2fs_zero_blocks2(NULL, 0, 0, NULL, NULL);
ext2fs_free_mem(&fs);
}

View file

@ -553,6 +553,7 @@ ipg_retry:
ext2fs_free_blocks_count_set(super, free_blocks);
c = (char) 255;
// coverity[dead_error_condition]
if (((int) c) == -1) {
super->s_flags |= EXT2_FLAGS_SIGNED_HASH;
} else {

View file

@ -50,7 +50,6 @@ PF_TYPE_DECL(NTAPI, NTSTATUS, NtDelayExecution, (BOOLEAN, PLARGE_INTEGER));
#define BooleanFlagOn(Flags, SingleFlag) ((BOOLEAN)((((Flags) & (SingleFlag)) != 0)))
#define EXT2_CHECK_MAGIC(struct, code) if ((struct)->magic != (code)) return (code)
#define EXT2_ET_MAGIC_NT_IO_CHANNEL 0x10ed
// Private data block
@ -280,16 +279,8 @@ static __inline NTSTATUS _CloseDisk(IN HANDLE Handle)
return (pfNtClose == NULL) ? STATUS_DLL_NOT_FOUND : pfNtClose(Handle);
}
//
// Make NT name from any recognized name
//
static PCSTR _NormalizeDeviceName(IN PCSTR Device, IN PSTR NormalizedDeviceNameBuffer)
{
int PartitionNumber = -1;
UCHAR DiskNumber;
PSTR p;
// Convert non NT paths to NT
if (Device[0] == '\\') {
if ((strlen(Device) < 4) || (Device[3] != '\\'))
@ -302,83 +293,9 @@ static PCSTR _NormalizeDeviceName(IN PCSTR Device, IN PSTR NormalizedDeviceNameB
return NormalizedDeviceNameBuffer;
}
// For now, don't allow the conversion of non absolute paths.
// Don't allow the conversion of non absolute paths.
// Too easy to get a C:\ drive altered on a mishap otherwise...
return NULL;
// Strip leading '/dev/' if any
if ((Device[0] == '/') &&
(Device[1] == 'd') &&
(Device[2] == 'e') &&
(Device[3] == 'v') &&
(Device[4] == '/')) {
Device = &Device[5];
}
if (Device[0] == '\0') {
return NULL;
}
// forms: hda[n], sda[n], fd[n]
if (Device[1] != 'd') {
return NULL;
}
if ((Device[0] == 'h') || (Device[0] == 's')) {
if ((Device[2] < 'a') || (Device[2] > ('a' + 9)) ||
((Device[3] != '\0') &&
((Device[4] != '\0') ||
((Device[3] < '0') || (Device[3] > '9'))
)
)
) {
return NULL;
}
DiskNumber = (UCHAR)(Device[2] - 'a');
if(Device[3] != '\0') {
PartitionNumber = (*(Device + 3) - '0');
}
} else if (Device[0] == 'f') {
// 3-d letter should be a digit.
if ((Device[3] != '\0') ||
(Device[2] < '0') || (Device[2] > '9')) {
return NULL;
}
DiskNumber = (UCHAR)(*(Device + 2) - '0');
} else {
// invalid prefix
return NULL;
}
// Prefix
strcpy(NormalizedDeviceNameBuffer, "\\Device\\");
// Media name
switch(*Device) {
case 'f':
strcat(NormalizedDeviceNameBuffer, "Floppy0");
break;
case 'h':
strcat(NormalizedDeviceNameBuffer, "Harddisk0");
break;
}
p = NormalizedDeviceNameBuffer + strlen(NormalizedDeviceNameBuffer) - 1;
p[0] = (CHAR)(p[0] + DiskNumber);
// Partition nr.
if (PartitionNumber >= 0) {
strcat(NormalizedDeviceNameBuffer, "\\Partition0");
p = NormalizedDeviceNameBuffer + strlen(NormalizedDeviceNameBuffer) - 1;
p[0] = (CHAR)(p[0] + PartitionNumber);
}
return NormalizedDeviceNameBuffer;
}
static VOID _GetDeviceSize(IN HANDLE h, OUT unsigned __int64 *FsSize)
@ -562,60 +479,49 @@ static errcode_t nt_open(const char *name, int flags, io_channel *channel)
if (name == NULL)
return EXT2_ET_BAD_DEVICE_NAME;
// Allocate channel handle
io = (io_channel) malloc(sizeof(struct struct_io_channel));
// Allocate buffers
io = (io_channel) calloc(1, sizeof(struct struct_io_channel));
if (io == NULL) {
errcode = ENOMEM;
goto out;
}
RtlZeroMemory(io, sizeof(struct struct_io_channel));
io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
nt_data = (PNT_PRIVATE_DATA) malloc(sizeof(NT_PRIVATE_DATA));
if (nt_data == NULL) {
errcode = ENOMEM;
goto out;
}
io->manager = nt_io_manager();
io->name = malloc(strlen(name) + 1);
io->name = calloc(strlen(name) + 1, 1);
if (io->name == NULL) {
errcode = ENOMEM;
goto out;
}
strcpy(io->name, name);
io->private_data = nt_data;
io->block_size = 1024;
io->read_error = 0;
io->write_error = 0;
io->refcount = 1;
nt_data = (PNT_PRIVATE_DATA) calloc(1, sizeof(NT_PRIVATE_DATA));
if (nt_data == NULL) {
errcode = ENOMEM;
goto out;
}
// Initialize data
RtlZeroMemory(nt_data, sizeof(NT_PRIVATE_DATA));
nt_data->magic = EXT2_ET_MAGIC_NT_IO_CHANNEL;
nt_data->buffer_block_number = 0xffffffff;
nt_data->buffer_size = 1024;
nt_data->buffer = malloc(nt_data->buffer_size);
nt_data->buffer = malloc(EXT2_MIN_BLOCK_SIZE);
if (nt_data->buffer == NULL) {
errcode = ENOMEM;
goto out;
}
// Initialize data
io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
io->manager = nt_io_manager();
strcpy(io->name, name);
io->block_size = EXT2_MIN_BLOCK_SIZE;
io->refcount = 1;
nt_data->magic = EXT2_ET_MAGIC_NT_IO_CHANNEL;
nt_data->buffer_block_number = 0xffffffff;
nt_data->buffer_size = EXT2_MIN_BLOCK_SIZE;
io->private_data = nt_data;
// Open the device
if (!_Ext2OpenDevice(name, (BOOLEAN)!BooleanFlagOn(flags, EXT2_FLAG_RW), &nt_data->handle, &nt_data->read_only, &errcode))
if (!_Ext2OpenDevice(name, (BOOLEAN)!BooleanFlagOn(flags, EXT2_FLAG_RW), &nt_data->handle, &nt_data->read_only, &errcode)) {
if (!errcode)
errcode = EIO;
goto out;
// Get the size
// _GetDeviceSize(nt_data->handle, &fs_size);
// strcpy(known_device, name);
// Lock/dismount
// if (!NT_SUCCESS(_LockDrive(nt_data->handle)) /*|| !NT_SUCCESS(_DismountDrive(NtData->Handle))*/)
// nt_data->read_only = TRUE;
}
// Done
*channel = io;

View file

@ -284,7 +284,9 @@ static errcode_t ext2fs_punch_extent(ext2_filsys fs, ext2_ino_t ino,
* there aren't any blocks mapped past this point in the file, so we're
* done.
*/
ext2fs_extent_goto(handle, start);
retval = ext2fs_extent_goto(handle, start);
if (retval)
goto errout;
retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent);
if (retval == EXT2_ET_NO_CURRENT_NODE) {
retval = 0;

View file

@ -329,6 +329,8 @@ struct rb_node *ext2fs_rb_augment_erase_begin(struct rb_node *node)
deepest = node->rb_right;
else {
deepest = ext2fs_rb_next(node);
if (!deepest)
return NULL;
if (deepest->rb_right)
deepest = deepest->rb_right;
else if (ext2fs_rb_parent(deepest) != node)

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 3.6.1520"
CAPTION "Rufus 3.6.1521"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -394,8 +394,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,6,1520,0
PRODUCTVERSION 3,6,1520,0
FILEVERSION 3,6,1521,0
PRODUCTVERSION 3,6,1521,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -413,13 +413,13 @@ BEGIN
VALUE "Comments", "https://akeo.ie"
VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.6.1520"
VALUE "FileVersion", "3.6.1521"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2019 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus-3.6.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.6.1520"
VALUE "ProductVersion", "3.6.1521"
END
END
BLOCK "VarFileInfo"