Skip to content

Commit

Permalink
Fix Coverity warnings
Browse files Browse the repository at this point in the history
* Also remove the headers we don't actually need from uefi_compat.h.
  • Loading branch information
pbatard committed Dec 2, 2024
1 parent 32ca6ab commit 3007b94
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
59 changes: 26 additions & 33 deletions include/ntfs-3g/uefi_compat.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* uefi_compat.h - Compatibility settings for the NTFS UEFI driver
*
* Copyright (c) 2021 Pete Batard
* Copyright (c) 2021-2024 Pete Batard
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
Expand All @@ -28,47 +28,36 @@
*/
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// Disable fortified strings, as these are only available with glibc
#if defined(__GNUC__) && defined(__fortify_function)
#undef __fortify_function
#endif
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <wchar.h>

#if defined(__MAKEWITH_GNUEFI)
#include <efi.h>
#define VA_LIST va_list
#define VA_START va_start
#define VA_END va_end
#define VA_LIST va_list
#define VA_START va_start
#define VA_END va_end
#else
#include <Base.h>
#endif

#define HAVE_CLOCK_GETTIME 0
#define HAVE_ERRNO_H 1
#define HAVE_CLOCK_GETTIME 1
#define HAVE_INTTYPES_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_LIMITS_H 1
#define HAVE_LIMITS_H 0
#define HAVE_STDARG_H 1
#define HAVE_STDBOOL_H 1
#define HAVE_STDDEF_H 1
#define HAVE_STDBOOL_H 0
#define HAVE_STDDEF_H 0
#define HAVE_STDINT_H 1
#define HAVE_STDIO_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STDLIB_H 0
#define HAVE_SYS_STAT_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_TIME_H 1
#define HAVE_WCHAR_H 1
#define HAVE_WCHAR_H 0

/* Disable reparse plugins */
#define DISABLE_PLUGINS 1
Expand All @@ -93,22 +82,26 @@
/* Number of bits in a file offset, on hosts where this is settable. */
#define _FILE_OFFSET_BITS 64

/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
/* Maximum value for a signed 32-bit integer */
#define INT_MAX 2147483647

/* Inline keyword definitions */
#ifndef __cplusplus
#define inline __inline
#ifndef inline
#define inline __inline
#endif

#ifdef _MSC_VER
typedef unsigned int dev_t;
typedef unsigned long uid_t;
typedef unsigned long gid_t;
typedef unsigned long pid_t;
typedef unsigned short mode_t;
typedef uint32_t clockid_t;
#ifndef __inline__
#define __inline__ __inline
#define __inline__ __inline
#endif
#endif

#ifdef _MSC_VER
typedef unsigned int dev_t;
typedef unsigned long uid_t;
typedef unsigned long gid_t;
typedef unsigned long pid_t;
typedef unsigned short mode_t;
typedef uint32_t clockid_t;
#endif /* _MSC_VER */

struct group {
Expand Down
5 changes: 5 additions & 0 deletions libntfs-3g/attrib.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ s64 ntfs_get_attribute_value(const ntfs_volume *vol,
* needed size, knowing that the whole attribute
* size has been checked to be <= 0x40000.
*/
/* Fix a coverity warning */
if (total > sle64_to_cpu(a->data_size) || total > 0x40000) {
free(rl);
return 0;
}
intlth = (sle64_to_cpu(a->data_size) - total
+ vol->cluster_size - 1)
>> vol->cluster_size_bits;
Expand Down
1 change: 1 addition & 0 deletions libntfs-3g/compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ static unsigned int ntfs_compress_block(const char *inbuf, const int bufsize,

if ((i >= bufsize) && (xout < (NTFS_SB_SIZE + 2))) {
/* Compressed. */
/* coverity[overflow_const] */
outbuf[0] = (xout - 3) & 255;
outbuf[1] = 0xb0 + (((xout - 3) >> 8) & 15);
} else {
Expand Down
2 changes: 1 addition & 1 deletion libntfs-3g/mft.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *vol, ntfs_inode *base_ni)
/* Cap size to pass_end. */
ofs = data_pos >> 3;
ll = ((pass_end + 7) >> 3) - ofs;
if (size > ll)
if (ll > 0 && size > ll)
size = ll;
ll = ntfs_attr_pread(mftbmp_na, ofs, size, buf);
if (ll < 0) {
Expand Down
1 change: 1 addition & 0 deletions libntfs-3g/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ static le32 entersecurityattr(ntfs_volume *vol,
errno = EIO;
}
} else {
/* coverity[overflow_const] */
newkey = le32_to_cpu(keyid) + 1;
securid = cpu_to_le32(newkey);
}
Expand Down
2 changes: 1 addition & 1 deletion libntfs-3g/unistr.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ static int ntfs_utf16_to_utf8(const ntfschar *ins, const int ins_len,
* so the size *without* the terminating null is limited to one less. */
size = utf16_to_utf8_size(ins, ins_len, outs_len - 1);

if (size < 0)
if (size < 0 || size > outs_len - 1)
goto out;

if (!*outs) {
Expand Down

0 comments on commit 3007b94

Please sign in to comment.