summaryrefslogtreecommitdiffstats
path: root/winpr/libwinpr
diff options
context:
space:
mode:
Diffstat (limited to 'winpr/libwinpr')
-rw-r--r--winpr/libwinpr/clipboard/synthetic.c2
-rw-r--r--winpr/libwinpr/clipboard/synthetic_file.c2
-rw-r--r--winpr/libwinpr/comm/comm.c3
-rw-r--r--winpr/libwinpr/crt/test/TestUnicodeConversion.c4
-rw-r--r--winpr/libwinpr/file/generic.c3
-rw-r--r--winpr/libwinpr/file/test/TestFileFindFirstFile.c3
-rw-r--r--winpr/libwinpr/sspi/Kerberos/kerberos.c14
-rw-r--r--winpr/libwinpr/timezone/timezone.c40
-rw-r--r--winpr/libwinpr/utils/debug.c2
-rw-r--r--winpr/libwinpr/utils/image.c60
-rw-r--r--winpr/libwinpr/utils/test/TestStream.c6
11 files changed, 84 insertions, 55 deletions
diff --git a/winpr/libwinpr/clipboard/synthetic.c b/winpr/libwinpr/clipboard/synthetic.c
index db8af71..cae5106 100644
--- a/winpr/libwinpr/clipboard/synthetic.c
+++ b/winpr/libwinpr/clipboard/synthetic.c
@@ -379,7 +379,7 @@ static void* clipboard_synthesize_image_format_to_bmp(wClipboard* clipboard, UIN
WINPR_ASSERT(data);
WINPR_ASSERT(pSize);
- void* dst = NULL;
+ BYTE* dst = NULL;
const UINT32 SrcSize = *pSize;
size_t size = 0;
wImage* image = winpr_image_new();
diff --git a/winpr/libwinpr/clipboard/synthetic_file.c b/winpr/libwinpr/clipboard/synthetic_file.c
index 9a1084b..4290d2a 100644
--- a/winpr/libwinpr/clipboard/synthetic_file.c
+++ b/winpr/libwinpr/clipboard/synthetic_file.c
@@ -1105,8 +1105,8 @@ static UINT file_get_range(struct synthetic_file* file, UINT64 offset, UINT32 si
if (!GetFileInformationByHandle(file->fd, &FileInfo))
{
- file->fd = INVALID_HANDLE_VALUE;
CloseHandle(file->fd);
+ file->fd = INVALID_HANDLE_VALUE;
error = GetLastError();
WLog_ERR(TAG, "Get file [%s] information fail: 0x%08" PRIx32, file->local_name, error);
return error;
diff --git a/winpr/libwinpr/comm/comm.c b/winpr/libwinpr/comm/comm.c
index cd68a40..f891ca7 100644
--- a/winpr/libwinpr/comm/comm.c
+++ b/winpr/libwinpr/comm/comm.c
@@ -1343,7 +1343,10 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
return (HANDLE)pComm;
error_handle:
+ WINPR_PRAGMA_DIAG_PUSH
+ WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
CloseHandle(pComm);
+ WINPR_PRAGMA_DIAG_POP
return INVALID_HANDLE_VALUE;
}
diff --git a/winpr/libwinpr/crt/test/TestUnicodeConversion.c b/winpr/libwinpr/crt/test/TestUnicodeConversion.c
index 187a068..eb0acb7 100644
--- a/winpr/libwinpr/crt/test/TestUnicodeConversion.c
+++ b/winpr/libwinpr/crt/test/TestUnicodeConversion.c
@@ -15,9 +15,9 @@
typedef struct
{
- char* utf8;
+ const char* utf8;
size_t utf8len;
- WCHAR* utf16;
+ const WCHAR* utf16;
size_t utf16len;
} testcase_t;
diff --git a/winpr/libwinpr/file/generic.c b/winpr/libwinpr/file/generic.c
index 9318586..e7bc0cf 100644
--- a/winpr/libwinpr/file/generic.c
+++ b/winpr/libwinpr/file/generic.c
@@ -925,7 +925,10 @@ static WIN32_FILE_SEARCH* file_search_new(const char* name, size_t namelen, cons
return pFileSearch;
fail:
+ WINPR_PRAGMA_DIAG_PUSH
+ WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
FindClose(pFileSearch);
+ WINPR_PRAGMA_DIAG_POP
return NULL;
}
diff --git a/winpr/libwinpr/file/test/TestFileFindFirstFile.c b/winpr/libwinpr/file/test/TestFileFindFirstFile.c
index 04829a3..0e5de44 100644
--- a/winpr/libwinpr/file/test/TestFileFindFirstFile.c
+++ b/winpr/libwinpr/file/test/TestFileFindFirstFile.c
@@ -98,7 +98,8 @@ static BOOL find_first_file_success(const char* FilePath)
}
rc = TRUE;
fail:
- FindClose(hFind);
+ if (hFind != INVALID_HANDLE_VALUE)
+ FindClose(hFind);
return rc;
}
diff --git a/winpr/libwinpr/sspi/Kerberos/kerberos.c b/winpr/libwinpr/sspi/Kerberos/kerberos.c
index 3cf7786..cba8038 100644
--- a/winpr/libwinpr/sspi/Kerberos/kerberos.c
+++ b/winpr/libwinpr/sspi/Kerberos/kerberos.c
@@ -1496,7 +1496,7 @@ static SECURITY_STATUS SEC_ENTRY kerberos_EncryptMessage(PCtxtHandle phContext,
KRB_CONTEXT* context = get_context(phContext);
PSecBuffer sig_buffer = NULL;
PSecBuffer data_buffer = NULL;
- BYTE* header = NULL;
+ char* header = NULL;
BYTE flags = 0;
krb5glue_key key = NULL;
krb5_keyusage usage = 0;
@@ -1547,15 +1547,15 @@ static SECURITY_STATUS SEC_ENTRY kerberos_EncryptMessage(PCtxtHandle phContext,
/* Set up the iov array in sig_buffer */
header = sig_buffer->pvBuffer;
encrypt_iov[2].data.data = header + 16;
- encrypt_iov[3].data.data = (BYTE*)encrypt_iov[2].data.data + encrypt_iov[2].data.length;
- encrypt_iov[4].data.data = (BYTE*)encrypt_iov[3].data.data + encrypt_iov[3].data.length;
- encrypt_iov[0].data.data = (BYTE*)encrypt_iov[4].data.data + encrypt_iov[4].data.length;
+ encrypt_iov[3].data.data = encrypt_iov[2].data.data + encrypt_iov[2].data.length;
+ encrypt_iov[4].data.data = encrypt_iov[3].data.data + encrypt_iov[3].data.length;
+ encrypt_iov[0].data.data = encrypt_iov[4].data.data + encrypt_iov[4].data.length;
encrypt_iov[1].data.data = data_buffer->pvBuffer;
/* Write the GSS header with 0 in RRC */
Data_Write_UINT16_BE(header, TOK_ID_WRAP);
header[2] = flags;
- header[3] = 0xFF;
+ header[3] = (char)0xFF;
Data_Write_UINT32(header + 4, 0);
Data_Write_UINT64_BE(header + 8, (context->local_seq + MessageSeqNo));
@@ -1656,8 +1656,8 @@ static SECURITY_STATUS SEC_ENTRY kerberos_DecryptMessage(PCtxtHandle phContext,
iov[0].data.data = header + 16 + rrc + ec;
iov[1].data.data = data_buffer->pvBuffer;
iov[2].data.data = header + 16 + ec;
- iov[3].data.data = (BYTE*)iov[2].data.data + iov[2].data.length;
- iov[4].data.data = (BYTE*)iov[3].data.data + iov[3].data.length;
+ iov[3].data.data = iov[2].data.data + iov[2].data.length;
+ iov[4].data.data = iov[3].data.data + iov[3].data.length;
if (krb_log_exec(krb5glue_decrypt_iov, context->ctx, key, usage, iov, ARRAYSIZE(iov)))
return SEC_E_INTERNAL_ERROR;
diff --git a/winpr/libwinpr/timezone/timezone.c b/winpr/libwinpr/timezone/timezone.c
index 6ca3e54..a727d67 100644
--- a/winpr/libwinpr/timezone/timezone.c
+++ b/winpr/libwinpr/timezone/timezone.c
@@ -23,6 +23,7 @@
#include <winpr/wtypes.h>
#include <winpr/timezone.h>
#include <winpr/crt.h>
+#include <winpr/assert.h>
#include <winpr/file.h>
#include "../log.h"
@@ -308,6 +309,11 @@ static TIME_ZONE_ENTRY* winpr_detect_windows_time_zone(void)
free(tzid);
tzid = NULL;
}
+ else if (tzid[0] == ':')
+ {
+ /* Remove leading colon, see tzset(3) */
+ memmove(tzid, tzid + 1, nSize - sizeof(char));
+ }
}
if (tzid == NULL)
@@ -323,7 +329,14 @@ static TIME_ZONE_ENTRY* winpr_detect_windows_time_zone(void)
char buf[1024] = { 0 };
const char* links[] = { buf };
- snprintf(buf, ARRAYSIZE(buf), "%s%s", zipath, tzid);
+ if (tzid[0] == '/')
+ {
+ /* Full path given in TZ */
+ links[0] = tzid;
+ }
+ else
+ snprintf(buf, ARRAYSIZE(buf), "%s%s", zipath, tzid);
+
ntzid = winpr_get_timezone_from_link(links, 1);
if (ntzid != NULL)
{
@@ -390,17 +403,20 @@ winpr_get_current_time_zone_rule(const TIME_ZONE_RULE_ENTRY* rules, UINT32 count
DWORD GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation)
{
time_t t = 0;
- struct tm tres;
- struct tm* local_time = NULL;
+ struct tm tres = { 0 };
TIME_ZONE_ENTRY* dtz = NULL;
+ const TIME_ZONE_INFORMATION empty = { 0 };
LPTIME_ZONE_INFORMATION tz = lpTimeZoneInformation;
- lpTimeZoneInformation->StandardBias = 0;
- time(&t);
- local_time = localtime_r(&t, &tres);
+
+ WINPR_ASSERT(tz);
+
+ *tz = empty;
+
+ t = time(NULL);
+ struct tm* local_time = localtime_r(&t, &tres);
if (!local_time)
goto out_error;
- memset(tz, 0, sizeof(TIME_ZONE_INFORMATION));
#ifdef WINPR_HAVE_TM_GMTOFF
{
long bias = -(local_time->tm_gmtoff / 60L);
@@ -410,19 +426,14 @@ DWORD GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation)
tz->Bias = (LONG)bias;
}
-#else
- tz->Bias = 0;
#endif
dtz = winpr_detect_windows_time_zone();
if (dtz != NULL)
{
- const TIME_ZONE_INFORMATION empty = { 0 };
-
WLog_DBG(TAG, "tz: Bias=%" PRId32 " sn='%s' dln='%s'", dtz->Bias, dtz->StandardName,
dtz->DaylightName);
- *tz = empty;
tz->Bias = dtz->Bias;
if (ConvertUtf8ToWChar(dtz->StandardName, tz->StandardName, ARRAYSIZE(tz->StandardName)) <
@@ -462,8 +473,9 @@ DWORD GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation)
WLog_DBG(TAG, "tz not found, using computed bias %" PRId32 ".", tz->Bias);
out_error:
free(dtz);
- memcpy(tz->StandardName, L"Client Local Time", sizeof(tz->StandardName));
- memcpy(tz->DaylightName, L"Client Local Time", sizeof(tz->DaylightName));
+ if (ConvertUtf8ToWChar("Client Local Time", tz->StandardName, ARRAYSIZE(tz->StandardName)) <= 0)
+ WLog_WARN(TAG, "Failed to set default timezone name");
+ memcpy(tz->DaylightName, tz->StandardName, sizeof(tz->DaylightName));
return 0; /* TIME_ZONE_ID_UNKNOWN */
}
diff --git a/winpr/libwinpr/utils/debug.c b/winpr/libwinpr/utils/debug.c
index a7c9a13..42d916e 100644
--- a/winpr/libwinpr/utils/debug.c
+++ b/winpr/libwinpr/utils/debug.c
@@ -161,7 +161,7 @@ char** winpr_backtrace_symbols(void* buffer, size_t* used)
*msgptr = msg;
strncpy(msg, support_msg, len);
*used = 1;
- return ppmsg;
+ return msgptr;
#endif
}
diff --git a/winpr/libwinpr/utils/image.c b/winpr/libwinpr/utils/image.c
index cc2e2ad..c609825 100644
--- a/winpr/libwinpr/utils/image.c
+++ b/winpr/libwinpr/utils/image.c
@@ -52,12 +52,12 @@
#include "../log.h"
#define TAG WINPR_TAG("utils.image")
-static SSIZE_T winpr_convert_from_jpeg(const char* comp_data, size_t comp_data_bytes, UINT32* width,
- UINT32* height, UINT32* bpp, char** ppdecomp_data);
-static SSIZE_T winpr_convert_from_png(const char* comp_data, size_t comp_data_bytes, UINT32* width,
- UINT32* height, UINT32* bpp, char** ppdecomp_data);
-static SSIZE_T winpr_convert_from_webp(const char* comp_data, size_t comp_data_bytes, UINT32* width,
- UINT32* height, UINT32* bpp, char** ppdecomp_data);
+static SSIZE_T winpr_convert_from_jpeg(const BYTE* comp_data, size_t comp_data_bytes, UINT32* width,
+ UINT32* height, UINT32* bpp, BYTE** ppdecomp_data);
+static SSIZE_T winpr_convert_from_png(const BYTE* comp_data, size_t comp_data_bytes, UINT32* width,
+ UINT32* height, UINT32* bpp, BYTE** ppdecomp_data);
+static SSIZE_T winpr_convert_from_webp(const BYTE* comp_data, size_t comp_data_bytes, UINT32* width,
+ UINT32* height, UINT32* bpp, BYTE** ppdecomp_data);
static BOOL writeBitmapFileHeader(wStream* s, const WINPR_BITMAP_FILE_HEADER* bf)
{
@@ -484,7 +484,7 @@ int winpr_image_read(wImage* image, const char* filename)
if (pos > 0)
{
- char* buffer = malloc((size_t)pos);
+ BYTE* buffer = malloc((size_t)pos);
if (buffer)
{
size_t r = fread(buffer, 1, (size_t)pos, fp);
@@ -518,9 +518,8 @@ int winpr_image_read_buffer(wImage* image, const BYTE* buffer, size_t size)
(sig[8] == 'W') && (sig[9] == 'E') && (sig[10] == 'B') && (sig[11] == 'P'))
{
image->type = WINPR_IMAGE_WEBP;
- const SSIZE_T rc =
- winpr_convert_from_webp((const char*)buffer, size, &image->width, &image->height,
- &image->bitsPerPixel, ((char**)&image->data));
+ const SSIZE_T rc = winpr_convert_from_webp(buffer, size, &image->width, &image->height,
+ &image->bitsPerPixel, &image->data);
if (rc >= 0)
{
image->bytesPerPixel = (image->bitsPerPixel + 7) / 8;
@@ -533,9 +532,8 @@ int winpr_image_read_buffer(wImage* image, const BYTE* buffer, size_t size)
(sig[10] == 0x00))
{
image->type = WINPR_IMAGE_JPEG;
- const SSIZE_T rc =
- winpr_convert_from_jpeg((const char*)buffer, size, &image->width, &image->height,
- &image->bitsPerPixel, ((char**)&image->data));
+ const SSIZE_T rc = winpr_convert_from_jpeg(buffer, size, &image->width, &image->height,
+ &image->bitsPerPixel, &image->data);
if (rc >= 0)
{
image->bytesPerPixel = (image->bitsPerPixel + 7) / 8;
@@ -547,9 +545,8 @@ int winpr_image_read_buffer(wImage* image, const BYTE* buffer, size_t size)
(sig[4] == '\r') && (sig[5] == '\n') && (sig[6] == 0x1A) && (sig[7] == '\n'))
{
image->type = WINPR_IMAGE_PNG;
- const SSIZE_T rc =
- winpr_convert_from_png((const char*)buffer, size, &image->width, &image->height,
- &image->bitsPerPixel, ((char**)&image->data));
+ const SSIZE_T rc = winpr_convert_from_png(buffer, size, &image->width, &image->height,
+ &image->bitsPerPixel, &image->data);
if (rc >= 0)
{
image->bytesPerPixel = (image->bitsPerPixel + 7) / 8;
@@ -625,11 +622,11 @@ void* winpr_convert_to_jpeg(const void* data, size_t size, UINT32 width, UINT32
jpeg_start_compress(&cinfo, TRUE);
- const unsigned char* cdata = data;
+ const JSAMPLE* cdata = data;
for (size_t x = 0; x < height; x++)
{
const JDIMENSION offset = x * stride;
- const JSAMPROW coffset = &cdata[offset];
+ const JSAMPLE* coffset = &cdata[offset];
if (jpeg_write_scanlines(&cinfo, &coffset, 1) != 1)
goto fail;
}
@@ -643,8 +640,8 @@ fail:
#endif
}
-SSIZE_T winpr_convert_from_jpeg(const char* comp_data, size_t comp_data_bytes, UINT32* width,
- UINT32* height, UINT32* bpp, char** ppdecomp_data)
+SSIZE_T winpr_convert_from_jpeg(const BYTE* comp_data, size_t comp_data_bytes, UINT32* width,
+ UINT32* height, UINT32* bpp, BYTE** ppdecomp_data)
{
WINPR_ASSERT(comp_data || (comp_data_bytes == 0));
WINPR_ASSERT(width);
@@ -658,7 +655,7 @@ SSIZE_T winpr_convert_from_jpeg(const char* comp_data, size_t comp_data_bytes, U
struct jpeg_decompress_struct cinfo = { 0 };
struct jpeg_error_mgr jerr;
SSIZE_T size = -1;
- char* decomp_data = NULL;
+ BYTE* decomp_data = NULL;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
@@ -734,8 +731,8 @@ void* winpr_convert_to_webp(const void* data, size_t size, UINT32 width, UINT32
#endif
}
-SSIZE_T winpr_convert_from_webp(const char* comp_data, size_t comp_data_bytes, UINT32* width,
- UINT32* height, UINT32* bpp, char** ppdecomp_data)
+SSIZE_T winpr_convert_from_webp(const BYTE* comp_data, size_t comp_data_bytes, UINT32* width,
+ UINT32* height, UINT32* bpp, BYTE** ppdecomp_data)
{
WINPR_ASSERT(comp_data || (comp_data_bytes == 0));
WINPR_ASSERT(width);
@@ -751,13 +748,20 @@ SSIZE_T winpr_convert_from_webp(const char* comp_data, size_t comp_data_bytes, U
return -1;
#else
- uint8_t* dst = WebPDecodeBGRA(comp_data, comp_data_bytes, width, height);
- if (!dst)
+ int w = 0;
+ int h = 0;
+ uint8_t* dst = WebPDecodeBGRA(comp_data, comp_data_bytes, &w, &h);
+ if (!dst || (w < 0) || (h < 0))
+ {
+ free(dst);
return -1;
+ }
+ *width = w;
+ *height = h;
*bpp = 32;
*ppdecomp_data = dst;
- return (*width) * (*height) * 4;
+ return 4ll * w * h;
#endif
}
@@ -1006,8 +1010,8 @@ void* winpr_convert_to_png(const void* data, size_t size, UINT32 width, UINT32 h
#endif
}
-SSIZE_T winpr_convert_from_png(const char* comp_data, size_t comp_data_bytes, UINT32* width,
- UINT32* height, UINT32* bpp, char** ppdecomp_data)
+SSIZE_T winpr_convert_from_png(const BYTE* comp_data, size_t comp_data_bytes, UINT32* width,
+ UINT32* height, UINT32* bpp, BYTE** ppdecomp_data)
{
#if defined(WINPR_UTILS_IMAGE_PNG)
size_t len = 0;
diff --git a/winpr/libwinpr/utils/test/TestStream.c b/winpr/libwinpr/utils/test/TestStream.c
index 00130ae..f86996e 100644
--- a/winpr/libwinpr/utils/test/TestStream.c
+++ b/winpr/libwinpr/utils/test/TestStream.c
@@ -124,7 +124,13 @@ static BOOL TestStream_Static(void)
if (v != 2)
return FALSE;
+ // Intentional warning as the stream is not allocated.
+ // Still, Stream_Free should not release such memory, therefore this statement
+ // is required to test that.
+ WINPR_PRAGMA_DIAG_PUSH
+ WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
Stream_Free(s, TRUE);
+ WINPR_PRAGMA_DIAG_POP
return TRUE;
}