diff --git a/include/ntfs-3g/uefi_compat.h b/include/ntfs-3g/uefi_compat.h index 993cbdf8..0e304b79 100644 --- a/include/ntfs-3g/uefi_compat.h +++ b/include/ntfs-3g/uefi_compat.h @@ -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 @@ -28,47 +28,36 @@ */ #include #include -#include #include -#include -#include #include #include -#include -// Disable fortified strings, as these are only available with glibc -#if defined(__GNUC__) && defined(__fortify_function) -#undef __fortify_function -#endif -#include #include #include #include -#include #if defined(__MAKEWITH_GNUEFI) #include -#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 #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 @@ -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 { diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index 1e729bd7..3aedb6c9 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -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; diff --git a/libntfs-3g/compress.c b/libntfs-3g/compress.c index 27d8b9a3..459dc816 100644 --- a/libntfs-3g/compress.c +++ b/libntfs-3g/compress.c @@ -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 { diff --git a/libntfs-3g/mft.c b/libntfs-3g/mft.c index 04505c29..28ccaea7 100644 --- a/libntfs-3g/mft.c +++ b/libntfs-3g/mft.c @@ -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) { diff --git a/libntfs-3g/security.c b/libntfs-3g/security.c index 08adfaf1..ab867800 100644 --- a/libntfs-3g/security.c +++ b/libntfs-3g/security.c @@ -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); } diff --git a/libntfs-3g/unistr.c b/libntfs-3g/unistr.c index fde0aa1f..ca5859c4 100644 --- a/libntfs-3g/unistr.c +++ b/libntfs-3g/unistr.c @@ -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) {