wsutil: Use snprintf() and ws_strdup_printf()

Replace GLib I/O with C library I/O.
This commit is contained in:
João Valverde 2021-12-17 18:23:34 +00:00
parent 612c0cff60
commit 7160b4b177
19 changed files with 72 additions and 89 deletions

View File

@ -9,9 +9,6 @@
*/
#include "config.h"
#include <glib.h>
#include "802_11-utils.h"
typedef struct freq_cvt_s {
@ -95,9 +92,9 @@ ieee80211_mhz_to_str(guint freq){
gboolean is_bg = FREQ_IS_BG(freq);
if (chan < 0) {
return g_strdup_printf("%u", freq);
return ws_strdup_printf("%u", freq);
} else {
return g_strdup_printf("%u [%s %u]", freq, is_bg ? "BG" : "A",
return ws_strdup_printf("%u [%s %u]", freq, is_bg ? "BG" : "A",
chan);
}
}

View File

@ -11,7 +11,7 @@
#ifndef __802_11_UTILS_H__
#define __802_11_UTILS_H__
#include "ws_symbol_export.h"
#include <wireshark.h>
#ifdef __cplusplus
extern "C" {

View File

@ -114,7 +114,7 @@ ws_buffer_remove_start(Buffer* buffer, gsize bytes)
{
ws_assert(buffer);
if (buffer->start + bytes > buffer->first_free) {
ws_error("ws_buffer_remove_start trying to remove %" G_GINT64_MODIFIER "u bytes. s=%" G_GINT64_MODIFIER "u ff=%" G_GINT64_MODIFIER "u!\n",
ws_error("ws_buffer_remove_start trying to remove %" PRIu64 " bytes. s=%" PRIu64 " ff=%" PRIu64 "!\n",
(guint64)bytes, (guint64)buffer->start,
(guint64)buffer->first_free);
/** ws_error() does an abort() and thus never returns **/

View File

@ -131,12 +131,12 @@ ws_vadd_crash_info(const char *fmt, va_list ap)
{
char *m, *old_info, *new_info;
m = g_strdup_vprintf(fmt, ap);
m = ws_strdup_vprintf(fmt, ap);
if (__crashreporter_info__ == NULL)
__crashreporter_info__ = m;
else {
old_info = __crashreporter_info__;
new_info = g_strdup_printf("%s\n%s", old_info, m);
new_info = ws_strdup_printf("%s\n%s", old_info, m);
g_free(m);
__crashreporter_info__ = new_info;
g_free(old_info);

View File

@ -8,15 +8,14 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <config.h>
#include "config.h"
#include "filesystem.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <glib.h>
#ifdef _WIN32
#include <windows.h>
#include <tchar.h>
@ -39,12 +38,10 @@
#include <pwd.h>
#endif /* _WIN32 */
#include "filesystem.h"
#include <wsutil/report_message.h>
#include <wsutil/privileges.h>
#include <wsutil/file_util.h>
#include <wsutil/utf8_entities.h>
#include <wsutil/ws_assert.h>
#include <wiretap/wtap.h> /* for WTAP_ERR_SHORT_WRITE */
@ -507,7 +504,7 @@ init_progfile_dir(
/*
* OK, no. What do we do now?
*/
return g_strdup_printf("No \\ in executable pathname \"%s\"",
return ws_strdup_printf("No \\ in executable pathname \"%s\"",
prog_pathname);
}
} else {
@ -520,7 +517,7 @@ init_progfile_dir(
/*
* Gak. We can't format the message.
*/
return g_strdup_printf("GetModuleFileName failed: %u (FormatMessage failed: %u)",
return ws_strdup_printf("GetModuleFileName failed: %u (FormatMessage failed: %u)",
error, GetLastError());
}
msg = utf_16to8(msg_w);
@ -534,7 +531,7 @@ init_progfile_dir(
msg[msglen - 1] = '\0';
msg[msglen - 2] = '\0';
}
return g_strdup_printf("GetModuleFileName failed: %s (%u)",
return ws_strdup_printf("GetModuleFileName failed: %s (%u)",
msg, error);
}
#else
@ -597,7 +594,7 @@ init_progfile_dir(
* We have no idea how big a buffer to
* allocate for the current directory.
*/
return g_strdup_printf("pathconf failed: %s\n",
return ws_strdup_printf("pathconf failed: %s\n",
g_strerror(errno));
}
curdir = (char *)g_malloc(path_max);
@ -607,10 +604,10 @@ init_progfile_dir(
* with DATA_DIR.
*/
g_free(curdir);
return g_strdup_printf("getcwd failed: %s\n",
return ws_strdup_printf("getcwd failed: %s\n",
g_strerror(errno));
}
path = g_strdup_printf("%s/%s", curdir, execname);
path = ws_strdup_printf("%s/%s", curdir, execname);
g_free(curdir);
prog_pathname = path;
} else {
@ -656,7 +653,7 @@ init_progfile_dir(
/*
* Program not found in path.
*/
return g_strdup_printf("\"%s\" not found in \"%s\"",
return ws_strdup_printf("\"%s\" not found in \"%s\"",
execname, pathstr);
}
} else {
@ -696,7 +693,7 @@ init_progfile_dir(
*/
if (strcmp(dir_end, "/run") == 0) {
gchar *cmake_file;
cmake_file = g_strdup_printf("%.*s/CMakeCache.txt",
cmake_file = ws_strdup_printf("%.*s/CMakeCache.txt",
(int)(dir_end - prog_pathname),
prog_pathname);
if (file_exists(cmake_file))
@ -761,7 +758,7 @@ init_progfile_dir(
* have no "/" in the pathname.
* Just free up prog_pathname.
*/
retstr = g_strdup_printf("No / found in \"%s\"", prog_pathname);
retstr = ws_strdup_printf("No / found in \"%s\"", prog_pathname);
g_free(prog_pathname);
return retstr;
}
@ -863,7 +860,7 @@ get_datafile_dir(void)
* it; we don't need to call started_with_special_privs().)
*/
else if (appbundle_dir != NULL) {
datafile_dir = g_strdup_printf("%s/Contents/Resources/share/wireshark",
datafile_dir = ws_strdup_printf("%s/Contents/Resources/share/wireshark",
appbundle_dir);
}
#endif
@ -1194,7 +1191,7 @@ has_global_profiles(void)
((dir = ws_dir_open(global_dir, 0, NULL)) != NULL))
{
while ((file = ws_dir_read_name(dir)) != NULL) {
filename = g_strdup_printf ("%s%s%s", global_dir, G_DIR_SEPARATOR_S,
filename = ws_strdup_printf ("%s%s%s", global_dir, G_DIR_SEPARATOR_S,
ws_dir_get_name(file));
if (test_for_directory(filename) == EISDIR) {
has_global = TRUE;
@ -1368,7 +1365,7 @@ set_persconffile_dir(const char *p)
char *
get_profiles_dir(void)
{
return g_strdup_printf ("%s%s%s", get_persconffile_dir_no_profile (),
return ws_strdup_printf ("%s%s%s", get_persconffile_dir_no_profile (),
G_DIR_SEPARATOR_S, PROFILES_DIR);
}
@ -1414,7 +1411,7 @@ create_profiles_dir(char **pf_dir_path_return)
char *
get_global_profiles_dir(void)
{
return g_strdup_printf ("%s%s%s", get_datafile_dir(),
return ws_strdup_printf ("%s%s%s", get_datafile_dir(),
G_DIR_SEPARATOR_S, PROFILES_DIR);
}
@ -1426,7 +1423,7 @@ get_persconffile_dir(const gchar *profilename)
if (profilename && strlen(profilename) > 0 &&
strcmp(profilename, DEFAULT_PROFILE) != 0) {
profile_dir = get_profiles_dir();
persconffile_profile_dir = g_strdup_printf ("%s%s%s", profile_dir,
persconffile_profile_dir = ws_strdup_printf ("%s%s%s", profile_dir,
G_DIR_SEPARATOR_S, profilename);
g_free(profile_dir);
} else {
@ -1492,7 +1489,7 @@ delete_directory (const char *directory, char **pf_dir_path_return)
if ((dir = ws_dir_open(directory, 0, NULL)) != NULL) {
while ((file = ws_dir_read_name(dir)) != NULL) {
filename = g_strdup_printf ("%s%s%s", directory, G_DIR_SEPARATOR_S,
filename = ws_strdup_printf ("%s%s%s", directory, G_DIR_SEPARATOR_S,
ws_dir_get_name(file));
if (test_for_directory(filename) != EISDIR) {
ret = ws_remove(filename);
@ -1531,7 +1528,7 @@ reset_default_profile(char **pf_dir_path_return)
file = g_list_first(files);
while (file) {
filename = (gchar *)file->data;
del_file = g_strdup_printf("%s%s%s", profile_dir, G_DIR_SEPARATOR_S, filename);
del_file = ws_strdup_printf("%s%s%s", profile_dir, G_DIR_SEPARATOR_S, filename);
if (file_exists(del_file)) {
ret = ws_remove(del_file);
@ -1716,8 +1713,8 @@ copy_persconffile_profile(const char *toname, const char *fromname, gboolean fro
file = g_list_first(files);
while (file) {
filename = (gchar *)file->data;
from_file = g_strdup_printf ("%s%s%s", from_dir, G_DIR_SEPARATOR_S, filename);
to_file = g_strdup_printf ("%s%s%s", to_dir, G_DIR_SEPARATOR_S, filename);
from_file = ws_strdup_printf ("%s%s%s", from_dir, G_DIR_SEPARATOR_S, filename);
to_file = ws_strdup_printf ("%s%s%s", to_dir, G_DIR_SEPARATOR_S, filename);
if (file_exists(from_file) && !copy_file_binary_mode(from_file, to_file)) {
*pf_filename_return = g_strdup(filename);
@ -1810,7 +1807,7 @@ get_home_dir(void)
* This is cached, so we don't need to worry about
* allocating multiple ones of them.
*/
homestring = g_strdup_printf("%s%s", homedrive, homepath);
homestring = ws_strdup_printf("%s%s", homedrive, homepath);
/*
* Trim off any trailing slash or backslash.
@ -1988,7 +1985,7 @@ file_open_error_message(int err, gboolean for_writing)
break;
default:
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
snprintf(errmsg_errno, sizeof(errmsg_errno),
"The file \"%%s\" could not be %s: %s.",
for_writing ? "created" : "opened",
g_strerror(err));
@ -2021,7 +2018,7 @@ file_write_error_message(int err)
#endif
default:
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
snprintf(errmsg_errno, sizeof(errmsg_errno),
"An error occurred while writing to the file \"%%s\": %s.",
g_strerror(err));
errmsg = errmsg_errno;
@ -2337,7 +2334,7 @@ data_file_url(const gchar *filename)
if(g_path_is_absolute(filename)) {
file_path = g_strdup(filename);
} else {
file_path = g_strdup_printf("%s/%s", get_datafile_dir(), filename);
file_path = ws_strdup_printf("%s/%s", get_datafile_dir(), filename);
}
/* XXX - check, if the file is really existing, otherwise display a simple_dialog about the problem */

View File

@ -11,8 +11,7 @@
#ifndef FILESYSTEM_H
#define FILESYSTEM_H
#include "ws_symbol_export.h"
#include "ws_attributes.h"
#include <wireshark.h>
#ifdef __cplusplus
extern "C" {

View File

@ -56,7 +56,7 @@ rsa_privkey_to_sexp(gnutls_x509_privkey_t priv_key, char **err)
/* these buffers were allocated by gnutls_x509_privkey_export_rsa_raw() */
g_free(rsa_datum[i].data);
if (gret != 0) {
*err = g_strdup_printf("can't convert m rsa param to int (size %d)", rsa_datum[i].size);
*err = ws_strdup_printf("can't convert m rsa param to int (size %d)", rsa_datum[i].size);
return NULL;
}
}
@ -101,7 +101,7 @@ rsa_load_pem_key(FILE *fp, char **err)
*err = NULL;
if (ws_fstat64(ws_fileno(fp), &statbuf) == -1) {
*err = g_strdup_printf("can't ws_fstat64 file: %s", g_strerror(errno));
*err = ws_strdup_printf("can't ws_fstat64 file: %s", g_strerror(errno));
return NULL;
}
if (S_ISDIR(statbuf.st_mode)) {
@ -126,10 +126,10 @@ rsa_load_pem_key(FILE *fp, char **err)
bytes = (guint) fread(key.data, 1, key.size, fp);
if (bytes < key.size) {
if (bytes == 0 && ferror(fp)) {
*err = g_strdup_printf("can't read from file %d bytes, got error %s",
*err = ws_strdup_printf("can't read from file %d bytes, got error %s",
key.size, g_strerror(errno));
} else {
*err = g_strdup_printf("can't read from file %d bytes, got %d",
*err = ws_strdup_printf("can't read from file %d bytes, got %d",
key.size, bytes);
}
g_free(key.data);
@ -141,7 +141,7 @@ rsa_load_pem_key(FILE *fp, char **err)
/* import PEM data*/
if ((ret = gnutls_x509_privkey_import(priv_key, &key, GNUTLS_X509_FMT_PEM)) != GNUTLS_E_SUCCESS) {
*err = g_strdup_printf("can't import pem data: %s", gnutls_strerror(ret));
*err = ws_strdup_printf("can't import pem data: %s", gnutls_strerror(ret));
g_free(key.data);
gnutls_x509_privkey_deinit(priv_key);
return NULL;
@ -211,7 +211,7 @@ rsa_load_pkcs12(FILE *fp, const gchar *cert_passwd, char **err)
ret = gnutls_pkcs12_init(&rsa_p12);
if (ret < 0) {
*err = g_strdup_printf("gnutls_pkcs12_init(&st_p12) - %s", gnutls_strerror(ret));
*err = ws_strdup_printf("gnutls_pkcs12_init(&st_p12) - %s", gnutls_strerror(ret));
g_free(data.data);
return NULL;
}
@ -221,7 +221,7 @@ rsa_load_pkcs12(FILE *fp, const gchar *cert_passwd, char **err)
if (ret < 0) {
ret = gnutls_pkcs12_import(rsa_p12, &data, GNUTLS_X509_FMT_PEM, 0);
if (ret < 0) {
*err = g_strdup_printf("could not load PKCS#12 in DER or PEM format: %s", gnutls_strerror(ret));
*err = ws_strdup_printf("could not load PKCS#12 in DER or PEM format: %s", gnutls_strerror(ret));
}
}
g_free(data.data);
@ -238,14 +238,14 @@ rsa_load_pkcs12(FILE *fp, const gchar *cert_passwd, char **err)
ret = gnutls_pkcs12_bag_init(&bag);
if (ret < 0) {
*err = g_strdup_printf("gnutls_pkcs12_bag_init failed: %s",
*err = ws_strdup_printf("gnutls_pkcs12_bag_init failed: %s",
gnutls_strerror(ret));
goto done;
}
ret = gnutls_pkcs12_get_bag(rsa_p12, i, bag);
if (ret < 0) {
*err = g_strdup_printf("gnutls_pkcs12_get_bag failed: %s",
*err = ws_strdup_printf("gnutls_pkcs12_get_bag failed: %s",
gnutls_strerror(ret));
goto done;
}
@ -254,13 +254,13 @@ rsa_load_pkcs12(FILE *fp, const gchar *cert_passwd, char **err)
ret = gnutls_pkcs12_bag_get_type(bag, j);
if (ret < 0) {
*err = g_strdup_printf("gnutls_pkcs12_bag_get_type failed: %s",
*err = ws_strdup_printf("gnutls_pkcs12_bag_get_type failed: %s",
gnutls_strerror(ret));
goto done;
}
bag_type = (gnutls_pkcs12_bag_type_t)ret;
if (bag_type >= GNUTLS_BAG_UNKNOWN) {
*err = g_strdup_printf("gnutls_pkcs12_bag_get_type returned unknown bag type %u",
*err = ws_strdup_printf("gnutls_pkcs12_bag_get_type returned unknown bag type %u",
ret);
goto done;
}
@ -270,13 +270,13 @@ rsa_load_pkcs12(FILE *fp, const gchar *cert_passwd, char **err)
if (ret == 0) {
ret = gnutls_pkcs12_bag_get_type(bag, j);
if (ret < 0) {
*err = g_strdup_printf("gnutls_pkcs12_bag_get_type failed: %s",
*err = ws_strdup_printf("gnutls_pkcs12_bag_get_type failed: %s",
gnutls_strerror(ret));
goto done;
}
bag_type = (gnutls_pkcs12_bag_type_t)ret;
if (bag_type >= GNUTLS_BAG_UNKNOWN) {
*err = g_strdup_printf("gnutls_pkcs12_bag_get_type returned unknown bag type %u",
*err = ws_strdup_printf("gnutls_pkcs12_bag_get_type returned unknown bag type %u",
ret);
goto done;
}
@ -286,7 +286,7 @@ rsa_load_pkcs12(FILE *fp, const gchar *cert_passwd, char **err)
ret = gnutls_pkcs12_bag_get_data(bag, j, &data);
if (ret < 0) {
*err = g_strdup_printf("gnutls_pkcs12_bag_get_data failed: %s",
*err = ws_strdup_printf("gnutls_pkcs12_bag_get_data failed: %s",
gnutls_strerror(ret));
goto done;
}
@ -300,13 +300,13 @@ rsa_load_pkcs12(FILE *fp, const gchar *cert_passwd, char **err)
ret = gnutls_x509_privkey_init(&rsa_pkey);
if (ret < 0) {
*err = g_strdup_printf("gnutls_x509_privkey_init failed: %s", gnutls_strerror(ret));
*err = ws_strdup_printf("gnutls_x509_privkey_init failed: %s", gnutls_strerror(ret));
goto done;
}
ret = gnutls_x509_privkey_import_pkcs8(rsa_pkey, &data, GNUTLS_X509_FMT_DER, cert_passwd,
(bag_type==GNUTLS_BAG_PKCS8_KEY) ? GNUTLS_PKCS_PLAIN : 0);
if (ret < 0) {
*err = g_strdup_printf("Can not decrypt private key - %s", gnutls_strerror(ret));
*err = ws_strdup_printf("Can not decrypt private key - %s", gnutls_strerror(ret));
gnutls_x509_privkey_deinit(rsa_pkey);
goto done;
}

View File

@ -10,16 +10,13 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <config.h>
#include "config.h"
#include "socket.h"
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <glib.h>
#include <wsutil/socket.h>
#include <wsutil/inet_addr.h>
#include <wsutil/ws_assert.h>
#ifdef _WIN32
#include <wsutil/win32-utils.h>
@ -38,7 +35,7 @@ ws_init_sockets(void)
wVersionRequested = MAKEWORD(2, 2);
err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0) {
errmsg = g_strdup_printf("Couldn't initialize Windows Sockets: %s",
errmsg = ws_strdup_printf("Couldn't initialize Windows Sockets: %s",
win32strerror(err));
}
#endif

View File

@ -12,7 +12,7 @@
#ifndef __SOCKET_H__
#define __SOCKET_H__
#include "ws_symbol_export.h"
#include <wireshark.h>
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <windows.h>

View File

@ -373,10 +373,10 @@ static void test_printf_thousands_grouping(void) {
wmem_strbuf_t *buf = wmem_strbuf_new(NULL, NULL);
wmem_strbuf_append_printf(buf, "%'d", 22);
if (g_strcmp0(wmem_strbuf_get_str(buf), "22") == 0) {
thousands_grouping_fmt = "%'"G_GINT64_MODIFIER"d";
thousands_grouping_fmt = "%'"PRId64;
} else {
/* Don't use */
thousands_grouping_fmt = "%"G_GINT64_MODIFIER"d";
thousands_grouping_fmt = "%"PRId64;
}
wmem_strbuf_destroy(buf);
}

View File

@ -9,8 +9,6 @@
*/
#include "config.h"
#include <glib.h>
#include "tempfile.h"
/**
@ -46,7 +44,7 @@ create_tempfile(gchar **namebuf, const char *pfx, const char *sfx, GError **err)
safe_pfx = g_strdelimit(safe_pfx, delimiters, '-');
}
gchar* filetmpl = g_strdup_printf("%sXXXXXX%s", safe_pfx ? safe_pfx : "", sfx ? sfx : "");
gchar* filetmpl = ws_strdup_printf("%sXXXXXX%s", safe_pfx ? safe_pfx : "", sfx ? sfx : "");
g_free(safe_pfx);
fd = g_file_open_tmp(filetmpl, namebuf, err);

View File

@ -11,7 +11,7 @@
#ifndef __TEMPFILE_H__
#define __TEMPFILE_H__
#include "ws_symbol_export.h"
#include <wireshark.h>
#ifdef __cplusplus
extern "C" {

View File

@ -8,7 +8,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <config.h>
#include "config.h"
#include "unicode-utils.h"
@ -94,7 +94,7 @@ utf_8to16_snprintf(TCHAR *utf16buf, gint utf16buf_len, const gchar* fmt, ...)
gchar* dst;
va_start(ap,fmt);
dst = g_strdup_vprintf(fmt, ap);
dst = ws_strdup_vprintf(fmt, ap);
va_end(ap);
StringCchPrintf(utf16buf, utf16buf_len, _T("%s"), utf_8to16(dst));

View File

@ -11,9 +11,7 @@
#ifndef __UNICODEUTIL_H__
#define __UNICODEUTIL_H__
#include "ws_symbol_export.h"
#include <glib.h>
#include <wireshark.h>
#ifdef _WIN32
#include <windows.h>
@ -49,7 +47,7 @@ const wchar_t * utf_8to16(const char *utf8str);
*
* @param utf16buf The buffer to return the UTF-16 string in.
* @param utf16buf_len The size of the 'utf16buf' parameter
* @param fmt A standard g_printf() format string
* @param fmt A standard printf() format string
*/
WS_DLL_PUBLIC
void utf_8to16_snprintf(TCHAR *utf16buf, gint utf16buf_len, const gchar* fmt,

View File

@ -119,7 +119,7 @@ win32strerror(DWORD error)
(LPTSTR)&utf16_message, ERRBUF_SIZE, NULL);
if (retval == 0) {
/* Failed. */
tempmsg = g_strdup_printf("Couldn't get error message for error (%lu) (because %lu)",
tempmsg = ws_strdup_printf("Couldn't get error message for error (%lu) (because %lu)",
error, GetLastError());
msg = g_intern_string(tempmsg);
g_free(tempmsg);
@ -130,13 +130,13 @@ win32strerror(DWORD error)
LocalFree(utf16_message);
if (utf8_message == NULL) {
/* Conversion failed. */
tempmsg = g_strdup_printf("Couldn't convert error message for error to UTF-8 (%lu) (because %lu)",
tempmsg = ws_strdup_printf("Couldn't convert error message for error to UTF-8 (%lu) (because %lu)",
error, GetLastError());
msg = g_intern_string(tempmsg);
g_free(tempmsg);
return msg;
}
tempmsg = g_strdup_printf("%s (%lu)", utf8_message, error);
tempmsg = ws_strdup_printf("%s (%lu)", utf8_message, error);
g_free(utf8_message);
msg = g_intern_string(tempmsg);
g_free(tempmsg);
@ -185,7 +185,7 @@ win32strexception(DWORD exception)
if (exceptions[i].code == exception)
return exceptions[i].msg;
}
g_snprintf(errbuf, (gulong)sizeof errbuf, "Exception 0x%08x", exception);
snprintf(errbuf, (gulong)sizeof errbuf, "Exception 0x%08x", exception);
return errbuf;
}

View File

@ -31,7 +31,7 @@ print_range(const void *value)
if(!value) {
return;
}
printf("Range: low=%" G_GUINT64_FORMAT " high=%" G_GUINT64_FORMAT " max_edge=%" G_GUINT64_FORMAT "\n", range->low, range->high, range->max_edge);
printf("Range: low=%" PRIu64 " high=%" PRIu64 " max_edge=%" PRIu64 "\n", range->low, range->high, range->max_edge);
}
/**

View File

@ -125,7 +125,7 @@ ws_pipe_create_overlapped_read(HANDLE *read_pipe_handle, HANDLE *write_pipe_hand
SECURITY_ATTRIBUTES *sa, DWORD suggested_buffer_size)
{
HANDLE read_pipe, write_pipe;
guchar *name = g_strdup_printf("\\\\.\\Pipe\\WiresharkWsPipe.%08x.%08x",
guchar *name = ws_strdup_printf("\\\\.\\Pipe\\WiresharkWsPipe.%08x.%08x",
GetCurrentProcessId(),
InterlockedIncrement(&pipe_serial_number));
gunichar2 *wname = g_utf8_to_utf16(name, -1, NULL, NULL, NULL);

View File

@ -11,7 +11,6 @@
*/
#include "wsgcrypt.h"
#include "ws_attributes.h"
gcry_error_t ws_hmac_buffer(int algo, void *digest, const void *buffer, size_t length, const void *key, size_t keylen)
{
@ -96,14 +95,14 @@ size_t rsa_decrypt_inplace(const guint len, guchar* data, gcry_sexp_t pk, gboole
/* create mpi representation of encrypted data */
rc = gcry_mpi_scan(&encr_mpi, GCRYMPI_FMT_USG, data, len, NULL);
if (rc != 0 ) {
*err = g_strdup_printf("can't convert data to mpi (size %d):%s", len, gcry_strerror(rc));
*err = ws_strdup_printf("can't convert data to mpi (size %d):%s", len, gcry_strerror(rc));
return 0;
}
/* put the data into a simple list */
rc = gcry_sexp_build(&s_data, NULL, "(enc-val(rsa(a%m)))", encr_mpi);
if (rc != 0) {
*err = g_strdup_printf("can't build encr_sexp:%s", gcry_strerror(rc));
*err = ws_strdup_printf("can't build encr_sexp:%s", gcry_strerror(rc));
decr_len = 0;
goto out;
}
@ -112,7 +111,7 @@ size_t rsa_decrypt_inplace(const guint len, guchar* data, gcry_sexp_t pk, gboole
rc = gcry_pk_decrypt(&s_plain, s_data, pk);
if (rc != 0)
{
*err = g_strdup_printf("can't decrypt key:%s", gcry_strerror(rc));
*err = ws_strdup_printf("can't decrypt key:%s", gcry_strerror(rc));
decr_len = 0;
goto out;
}
@ -128,14 +127,14 @@ size_t rsa_decrypt_inplace(const guint len, guchar* data, gcry_sexp_t pk, gboole
/* compute size requested for plaintext buffer */
rc = gcry_mpi_print(GCRYMPI_FMT_USG, NULL, 0, &decr_len, text);
if (rc != 0) {
*err = g_strdup_printf("can't compute decr size:%s", gcry_strerror(rc));
*err = ws_strdup_printf("can't compute decr size:%s", gcry_strerror(rc));
decr_len = 0;
goto out;
}
/* sanity check on out buffer */
if (decr_len > len) {
*err = g_strdup_printf("decrypted data is too long ?!? (%" G_GSIZE_MODIFIER "u max %d)", decr_len, len);
*err = ws_strdup_printf("decrypted data is too long ?!? (%zu max %d)", decr_len, len);
decr_len = 0;
goto out;
}
@ -143,7 +142,7 @@ size_t rsa_decrypt_inplace(const guint len, guchar* data, gcry_sexp_t pk, gboole
/* write plain text to newly allocated buffer */
rc = gcry_mpi_print(GCRYMPI_FMT_USG, data, len, &decr_len, text);
if (rc != 0) {
*err = g_strdup_printf("can't print decr data to mpi (size %" G_GSIZE_MODIFIER "u):%s", decr_len, gcry_strerror(rc));
*err = ws_strdup_printf("can't print decr data to mpi (size %zu):%s", decr_len, gcry_strerror(rc));
decr_len = 0;
goto out;
}

View File

@ -15,9 +15,7 @@
#ifndef __WSGCRYPT_H__
#define __WSGCRYPT_H__
#include <ws_diag_control.h>
#include "ws_symbol_export.h"
#include <glib.h>
#include <wireshark.h>
DIAG_OFF(deprecated-declarations)