Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 0 additions & 187 deletions contrib/windows/codeql/Invoke-CodeQLZFSinAnalysis.ps1

This file was deleted.

2 changes: 1 addition & 1 deletion include/os/windows/spl/sys/kmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extern uint64_t physmem;
*/

#define MALLOC(A, C, S, T, F) \
(A) = (C)ExAllocatePoolUninitialized(NonPagedPoolNx, (S), '!SFZ')
(A) = (C)ExAllocatePoolWithTag(NonPagedPoolNx, (S), '!SFZ')
#define FREE(A, T) \
ExFreePoolWithTag((A), '!SFZ')

Expand Down
90 changes: 2 additions & 88 deletions include/os/windows/spl/sys/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,96 +96,10 @@ typedef uintptr_t pc_t;
#include <ntddk.h>


#include <stdarg.h>
#ifndef va_copy
/*
* clang-cl provides va_copy as a compiler builtin, but the WDK's own
* kernel-mode CRT stdarg.h (km\crt\stdarg.h, used when this header is
* compiled with plain cl.exe rather than clang-cl) does not define it at
* all. This driver is AMD64/x64-only, where va_list is a plain pointer
* and a direct assignment is a correct, equivalent substitute.
*/
#define va_copy(dest, src) ((dest) = (src))
#endif
/*
* _snprintf()/_vsnprintf() (the legacy MSVCRT functions snprintf/vsnprintf
* were aliased to below) do not null-terminate the destination buffer when
* the formatted output is truncated - unlike the POSIX snprintf/vsnprintf
* this portable code is written against. Wrap them instead of aliasing
* directly, so truncation is always still safely null-terminated. The
* existing "-1 on truncation" return value is preserved unchanged (every
* caller in this tree only checks `if (n < 0)`), so this is purely additive.
*/
/*
* "Measure the required length without writing" (the buf==NULL/size==0
* idiom used by kmem_asprintf()/kmem_vasprintf()/zfs_dbgmsg()). Neither
* _vscprintf (declared in the WDK headers but not exported by the
* kernel-mode CRT import lib - confirmed via a link failure) nor
* _vsnprintf_s (its count==0 case triggers the invalid-parameter handler)
* can do this directly in kernel mode. Measure into a generously-sized
* scratch buffer instead: every caller in this tree builds short, bounded
* strings (dataset/snapshot names, log messages), so 1024 bytes is never
* exceeded in practice. If a caller's format+args ever did exceed it, the
* result here is a consistently-truncated (safely null-terminated) length
* - the caller's later real write with the same format+args into a
* same-size-or-larger buffer would truncate identically, not silently
* disagree with what was measured.
*/
static inline int
zfs_vscprintf(const char *fmt, va_list ap)
{
char scratch[1024];
va_list ap_copy;
int ret;

va_copy(ap_copy, ap);
ret = _vsnprintf_s(scratch, sizeof (scratch), (size_t)-1, fmt, ap_copy);
va_end(ap_copy);

return (ret >= 0 ? ret : (int)sizeof (scratch) - 1);
}

static inline int
zfs_vsnprintf(char *buf, size_t size, const char *fmt, va_list ap)
{
int ret;

if (size == 0) {
va_list ap_copy;
va_copy(ap_copy, ap);
ret = zfs_vscprintf(fmt, ap_copy);
va_end(ap_copy);
return (ret);
}

/*
* _TRUNCATE ((size_t)-1): _vsnprintf_s always null-terminates buf
* itself on truncation (returning -1), so no separate fallback
* write is needed here - callers such as lstrlib.c's str_sprintf()
* pass INT_MAX as a "the caller already pre-sized the real buffer"
* sentinel, not the true size of buf, so a manual buf[size - 1]
* write here would be a wild out-of-bounds write on truncation.
*/
return (_vsnprintf_s(buf, size, (size_t)-1, fmt, ap));
}

static inline int
zfs_snprintf(char *buf, size_t size, const char *fmt, ...)
{
va_list ap;
int ret;

va_start(ap, fmt);
ret = zfs_vsnprintf(buf, size, fmt, ap);
va_end(ap);

return (ret);
}

#define snprintf zfs_snprintf
#define snprintf _snprintf
#define vprintf(...) vKdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, \
__VA_ARGS__))
#define vsnprintf zfs_vsnprintf
#define vsnprintf _vsnprintf

#ifndef ULLONG_MAX
#define ULLONG_MAX (~0ULL)
Expand Down
12 changes: 0 additions & 12 deletions lib/libspl/include/os/windows/sys/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,4 @@ typedef uint64_t zoff_t;
#include <wosix.h>
#endif

/*
* Several source files under module/ (module/zfs, module/lua, ...) are
* shared between the ZFSin kernel driver and this user-mode build (e.g.
* libzpool) and call zfs_vsnprintf() directly by name - the kernel-side
* include/os/windows/spl/sys/types.h defines that name as a safe wrapper
* around the legacy, non-null-terminating-on-truncation kernel-mode
* _vsnprintf. This user-mode types.h has no such problem (the real UCRT
* vsnprintf() is already POSIX-conformant), so just alias the name to it.
*/
#include <stdio.h>
#define zfs_vsnprintf vsnprintf

#endif
12 changes: 6 additions & 6 deletions lib/os/windows/zlib-1.2.3/gzio.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ gz_open(
if (s->path == NULL) {
return (destroy(s), (gzFile)Z_NULL);
}
strlcpy(s->path, path, strlen(path)+1); /* do this early for debugging */
strcpy(s->path, path); /* do this early for debugging */

s->mode = '\0';
do {
Expand Down Expand Up @@ -234,7 +234,7 @@ gzdopen(

if (fd < 0)
return ((gzFile)Z_NULL);
zlib_snprintf(name, sizeof (name), "<fd:%d>", fd); /* for debugging */
sprintf(name, "<fd:%d>", fd); /* for debugging */

return (gz_open(name, mode, fd));
}
Expand Down Expand Up @@ -666,7 +666,7 @@ gzprintf(gzFile file, const char *format, /* args */ ...)
va_end(va);
len = strlen(buf);
#else
len = zlib_vsnprintf(buf, sizeof (buf), format, va);
len = vsnprintf(buf, sizeof (buf), format, va);
va_end(va);
#endif
#endif
Expand Down Expand Up @@ -1094,9 +1094,9 @@ gzerror(
s->msg = (char *)ALLOC(strlen(s->path) + strlen(m) + 3);
if (s->msg == Z_NULL)
return ((const char *)ERR_MSG(Z_MEM_ERROR));
strlcpy(s->msg, s->path, strlen(s->path) + strlen(m) + 3);
strlcat(s->msg, ": ", strlen(s->path) + strlen(m) + 3);
strlcat(s->msg, m, strlen(s->path) + strlen(m) + 3);
strcpy(s->msg, s->path);
strcat(s->msg, ": ");
strcat(s->msg, m);
return ((const char *)s->msg);
}

Expand Down
Loading
Loading