Skip to content

Commit

Permalink
Replace g_strdup_printf() with ws_strdup_printf()
Browse files Browse the repository at this point in the history
Use macros from inttypes.h.
  • Loading branch information
randstr committed Dec 19, 2021
1 parent f984def commit 0ccd69e
Show file tree
Hide file tree
Showing 186 changed files with 967 additions and 970 deletions.
4 changes: 2 additions & 2 deletions capture/airpcap_loader.c
Expand Up @@ -115,7 +115,7 @@ static guint num_legacy_channels = 14;
static gchar *
cant_get_airpcap_if_list_error_message(const char *err_str)
{
return g_strdup_printf("Can't get list of Wireless interfaces: %s", err_str);
return ws_strdup_printf("Can't get list of Wireless interfaces: %s", err_str);
}

/*
Expand Down Expand Up @@ -931,7 +931,7 @@ airpcap_get_if_string_number(airpcap_if_info_t* if_info)
}
else
{
number = g_strdup_printf("%.2u",n);
number = ws_strdup_printf("%.2u",n);
}

return number;
Expand Down
2 changes: 1 addition & 1 deletion capture/capture-pcap-util-unix.c
Expand Up @@ -51,7 +51,7 @@ get_interface_list(int *err, char **err_str)
gchar *
cant_get_if_list_error_message(const char *err_str)
{
return g_strdup_printf("Can't get list of interfaces: %s", err_str);
return ws_strdup_printf("Can't get list of interfaces: %s", err_str);
}

if_capabilities_t *
Expand Down
14 changes: 7 additions & 7 deletions capture/capture-pcap-util.c
Expand Up @@ -231,7 +231,7 @@ add_unix_interface_ifinfo(if_info_t *if_info, const char *name,
* Look for /sys/class/net/{device}/wireless. If it exists,
* it's a wireless interface.
*/
wireless_path = g_strdup_printf("/sys/class/net/%s/wireless", name);
wireless_path = ws_strdup_printf("/sys/class/net/%s/wireless", name);
if (wireless_path != NULL) {
if (ws_stat64(wireless_path, &statb) == 0)
if_info->type = IF_WIRELESS;
Expand Down Expand Up @@ -915,7 +915,7 @@ create_data_link_info(int dlt)
if (text != NULL)
data_link_info->name = g_strdup(text);
else
data_link_info->name = g_strdup_printf("DLT %d", dlt);
data_link_info->name = ws_strdup_printf("DLT %d", dlt);
text = pcap_datalink_val_to_description(dlt);
data_link_info->description = g_strdup(text);
return data_link_info;
Expand Down Expand Up @@ -947,7 +947,7 @@ get_data_link_types(pcap_t *pch, interface_options *interface_opts,
*/
if (nlt == PCAP_ERROR) {
*status = CAP_DEVICE_OPEN_ERR_GENERIC;
*status_str = g_strdup_printf("pcap_list_datalinks() failed: %s",
*status_str = ws_strdup_printf("pcap_list_datalinks() failed: %s",
pcap_geterr(pch));
} else {
if (nlt == PCAP_ERROR_PERM_DENIED)
Expand All @@ -958,7 +958,7 @@ get_data_link_types(pcap_t *pch, interface_options *interface_opts,
}
#else /* HAVE_PCAP_CREATE */
*status = CAP_DEVICE_OPEN_ERR_GENERIC;
*status_str = g_strdup_printf("pcap_list_datalinks() failed: %s",
*status_str = ws_strdup_printf("pcap_list_datalinks() failed: %s",
pcap_geterr(pch));
#endif /* HAVE_PCAP_CREATE */
return NULL;
Expand Down Expand Up @@ -1197,7 +1197,7 @@ get_if_capabilities_pcap_create(interface_options *interface_opts,
/* Error. */
if (status == PCAP_ERROR) {
*open_status = CAP_DEVICE_OPEN_ERR_GENERIC;
*open_status_str = g_strdup_printf("pcap_can_set_rfmon() failed: %s",
*open_status_str = ws_strdup_printf("pcap_can_set_rfmon() failed: %s",
pcap_geterr(pch));
} else {
if (status == PCAP_ERROR_PERM_DENIED)
Expand All @@ -1218,7 +1218,7 @@ get_if_capabilities_pcap_create(interface_options *interface_opts,
pcap_set_rfmon(pch, 1);
} else {
*open_status = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
*open_status_str = g_strdup_printf("pcap_can_set_rfmon() returned %d",
*open_status_str = ws_strdup_printf("pcap_can_set_rfmon() returned %d",
status);
pcap_close(pch);
g_free(caps);
Expand All @@ -1230,7 +1230,7 @@ get_if_capabilities_pcap_create(interface_options *interface_opts,
/* Error. */
if (status == PCAP_ERROR) {
*open_status = CAP_DEVICE_OPEN_ERR_GENERIC;
*open_status_str = g_strdup_printf("pcap_activate() failed: %s",
*open_status_str = ws_strdup_printf("pcap_activate() failed: %s",
pcap_geterr(pch));
} else {
if (status == PCAP_ERROR_PERM_DENIED)
Expand Down
6 changes: 3 additions & 3 deletions capture/capture-wpcap.c
Expand Up @@ -270,7 +270,7 @@ convert_errbuf_to_utf8(char *errbuf)
static char *
cant_load_winpcap_err(const char *app_name)
{
return g_strdup_printf(
return ws_strdup_printf(
"Unable to load Npcap or WinPcap (wpcap.dll); %s will not be able to\n"
"capture packets.\n"
"\n"
Expand Down Expand Up @@ -771,12 +771,12 @@ cant_get_if_list_error_message(const char *err_str)
*/
if (strstr(err_str, "Not enough storage is available to process this command") != NULL ||
strstr(err_str, "The operation completed successfully") != NULL) {
return g_strdup_printf("Can't get list of interfaces: %s\n"
return ws_strdup_printf("Can't get list of interfaces: %s\n"
"This might be a problem with WinPcap 3.0. You should try updating to\n"
"Npcap. See https://nmap.org/npcap/ for more information.",
err_str);
}
return g_strdup_printf("Can't get list of interfaces: %s", err_str);
return ws_strdup_printf("Can't get list of interfaces: %s", err_str);
}

if_capabilities_t *
Expand Down
2 changes: 1 addition & 1 deletion capture/capture_ifinfo.c
Expand Up @@ -266,7 +266,7 @@ capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode,
default:
ws_info("Capture Interface Capabilities returned bad information.");
if (err_primary_msg) {
*err_primary_msg = g_strdup_printf("Dumpcap returned \"%s\" for monitor-mode capability",
*err_primary_msg = ws_strdup_printf("Dumpcap returned \"%s\" for monitor-mode capability",
raw_list[0]);
}
g_free(caps);
Expand Down
64 changes: 32 additions & 32 deletions capture/capture_sync.c
Expand Up @@ -187,9 +187,9 @@ init_pipe_args(int *argc) {

/* take Wireshark's absolute program path and replace "Wireshark" with "dumpcap" */
#ifdef _WIN32
exename = g_strdup_printf("%s\\dumpcap.exe", progfile_dir);
exename = ws_strdup_printf("%s\\dumpcap.exe", progfile_dir);
#else
exename = g_strdup_printf("%s/dumpcap", progfile_dir);
exename = ws_strdup_printf("%s/dumpcap", progfile_dir);
#endif

/* Make that the first argument in the argument list (argv[0]). */
Expand Down Expand Up @@ -349,7 +349,7 @@ sync_pipe_start(capture_options *capture_opts, GPtrArray *capture_comments,
if (interface_opts->extcap_fifo != NULL)
{
#ifdef _WIN32
char *pipe = g_strdup_printf("%s%" PRIuPTR, EXTCAP_PIPE_PREFIX, interface_opts->extcap_pipe_h);
char *pipe = ws_strdup_printf("%s%" PRIuPTR, EXTCAP_PIPE_PREFIX, interface_opts->extcap_pipe_h);
argv = sync_pipe_add_arg(argv, &argc, pipe);
g_free(pipe);
#else
Expand Down Expand Up @@ -501,7 +501,7 @@ sync_pipe_start(capture_options *capture_opts, GPtrArray *capture_comments,
}

/* Create the signal pipe */
signal_pipe_name = g_strdup_printf(SIGNAL_PIPE_FORMAT, control_id);
signal_pipe_name = ws_strdup_printf(SIGNAL_PIPE_FORMAT, control_id);
signal_pipe = CreateNamedPipe(utf_8to16(signal_pipe_name),
PIPE_ACCESS_OUTBOUND, PIPE_TYPE_BYTE, 1, 65535, 65535, 0, NULL);
g_free(signal_pipe_name);
Expand Down Expand Up @@ -715,7 +715,7 @@ sync_pipe_open_command(char* const argv[], int *data_read_fd,
/* (increase this value if you have trouble while fast capture file switches) */
if (! CreatePipe(&sync_pipe[PIPE_READ], &sync_pipe[PIPE_WRITE], &sa, 5120)) {
/* Couldn't create the message pipe between parent and child. */
*msg = g_strdup_printf("Couldn't create sync pipe: %s",
*msg = ws_strdup_printf("Couldn't create sync pipe: %s",
win32strerror(GetLastError()));
return -1;
}
Expand All @@ -729,7 +729,7 @@ sync_pipe_open_command(char* const argv[], int *data_read_fd,
*/
*message_read_fd = _open_osfhandle( (intptr_t) sync_pipe[PIPE_READ], _O_BINARY);
if (*message_read_fd == -1) {
*msg = g_strdup_printf("Couldn't get C file handle for message read pipe: %s", g_strerror(errno));
*msg = ws_strdup_printf("Couldn't get C file handle for message read pipe: %s", g_strerror(errno));
CloseHandle(sync_pipe[PIPE_READ]);
CloseHandle(sync_pipe[PIPE_WRITE]);
return -1;
Expand All @@ -739,7 +739,7 @@ sync_pipe_open_command(char* const argv[], int *data_read_fd,
/* (increase this value if you have trouble while fast capture file switches) */
if (! CreatePipe(&data_pipe[PIPE_READ], &data_pipe[PIPE_WRITE], &sa, 5120)) {
/* Couldn't create the message pipe between parent and child. */
*msg = g_strdup_printf("Couldn't create data pipe: %s",
*msg = ws_strdup_printf("Couldn't create data pipe: %s",
win32strerror(GetLastError()));
ws_close(*message_read_fd); /* Should close sync_pipe[PIPE_READ] */
CloseHandle(sync_pipe[PIPE_WRITE]);
Expand All @@ -755,7 +755,7 @@ sync_pipe_open_command(char* const argv[], int *data_read_fd,
*/
*data_read_fd = _open_osfhandle( (intptr_t) data_pipe[PIPE_READ], _O_BINARY);
if (*data_read_fd == -1) {
*msg = g_strdup_printf("Couldn't get C file handle for data read pipe: %s", g_strerror(errno));
*msg = ws_strdup_printf("Couldn't get C file handle for data read pipe: %s", g_strerror(errno));
CloseHandle(data_pipe[PIPE_READ]);
CloseHandle(data_pipe[PIPE_WRITE]);
ws_close(*message_read_fd); /* Should close sync_pipe[PIPE_READ] */
Expand Down Expand Up @@ -792,7 +792,7 @@ sync_pipe_open_command(char* const argv[], int *data_read_fd,
/* call dumpcap */
if(!win32_create_process(argv[0], args->str, NULL, NULL, TRUE,
CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) {
*msg = g_strdup_printf("Couldn't run %s in child process: %s",
*msg = ws_strdup_printf("Couldn't run %s in child process: %s",
args->str, win32strerror(GetLastError()));
ws_close(*data_read_fd); /* Should close data_pipe[PIPE_READ] */
CloseHandle(data_pipe[PIPE_WRITE]);
Expand All @@ -809,14 +809,14 @@ sync_pipe_open_command(char* const argv[], int *data_read_fd,
/* Create a pipe for the child process to send us messages */
if (pipe(sync_pipe) < 0) {
/* Couldn't create the message pipe between parent and child. */
*msg = g_strdup_printf("Couldn't create sync pipe: %s", g_strerror(errno));
*msg = ws_strdup_printf("Couldn't create sync pipe: %s", g_strerror(errno));
return -1;
}

/* Create a pipe for the child process to send us data */
if (pipe(data_pipe) < 0) {
/* Couldn't create the data pipe between parent and child. */
*msg = g_strdup_printf("Couldn't create data pipe: %s", g_strerror(errno));
*msg = ws_strdup_printf("Couldn't create data pipe: %s", g_strerror(errno));
ws_close(sync_pipe[PIPE_READ]);
ws_close(sync_pipe[PIPE_WRITE]);
return -1;
Expand Down Expand Up @@ -872,7 +872,7 @@ sync_pipe_open_command(char* const argv[], int *data_read_fd,

if (*fork_child == WS_INVALID_PID) {
/* We couldn't even create the child process. */
*msg = g_strdup_printf("Couldn't create child process: %s", g_strerror(errno));
*msg = ws_strdup_printf("Couldn't create child process: %s", g_strerror(errno));
ws_close(*data_read_fd);
ws_close(*message_read_fd);
return -1;
Expand Down Expand Up @@ -982,7 +982,7 @@ sync_pipe_run_command_actual(char* const argv[], gchar **data, gchar **primary_m
/* We got an error from the sync pipe. If ret is -1, report
both the sync pipe I/O error and the wait error. */
if (ret == -1) {
combined_msg = g_strdup_printf("%s\n\n%s", *primary_msg, wait_msg);
combined_msg = ws_strdup_printf("%s\n\n%s", *primary_msg, wait_msg);
g_free(*primary_msg);
g_free(wait_msg);
*primary_msg = combined_msg;
Expand Down Expand Up @@ -1085,7 +1085,7 @@ sync_pipe_run_command_actual(char* const argv[], gchar **data, gchar **primary_m
/*
* Child process returned an unknown status.
*/
*primary_msg = g_strdup_printf("dumpcap process gave an unexpected message type: 0x%02x",
*primary_msg = ws_strdup_printf("dumpcap process gave an unexpected message type: 0x%02x",
indicator);
*secondary_msg = NULL;
ret = -1;
Expand Down Expand Up @@ -1153,11 +1153,11 @@ sync_interface_set_80211_chan(const gchar *iface, const char *freq, const gchar
argv = sync_pipe_add_arg(argv, &argc, iface);

if (center_freq2)
opt = g_strdup_printf("%s,%s,%s,%s", freq, type, center_freq1, center_freq2);
opt = ws_strdup_printf("%s,%s,%s,%s", freq, type, center_freq1, center_freq2);
else if (center_freq1)
opt = g_strdup_printf("%s,%s,%s", freq, type, center_freq1);
opt = ws_strdup_printf("%s,%s,%s", freq, type, center_freq1);
else if (type)
opt = g_strdup_printf("%s,%s", freq, type);
opt = ws_strdup_printf("%s,%s", freq, type);
else
opt = g_strdup(freq);

Expand Down Expand Up @@ -1366,7 +1366,7 @@ sync_interface_stats_open(int *data_read_fd, ws_process_id *fork_child, gchar **
/* We got an error from the sync pipe. If ret is -1, report
both the sync pipe I/O error and the wait error. */
if (ret == -1) {
combined_msg = g_strdup_printf("%s\n\n%s", *msg, wait_msg);
combined_msg = ws_strdup_printf("%s\n\n%s", *msg, wait_msg);
g_free(*msg);
g_free(wait_msg);
*msg = combined_msg;
Expand Down Expand Up @@ -1433,7 +1433,7 @@ sync_interface_stats_open(int *data_read_fd, ws_process_id *fork_child, gchar **
/*
* Child process returned an unknown status.
*/
*msg = g_strdup_printf("dumpcap process gave an unexpected message type: 0x%02x",
*msg = ws_strdup_printf("dumpcap process gave an unexpected message type: 0x%02x",
indicator);
ret = -1;
}
Expand Down Expand Up @@ -1477,7 +1477,7 @@ pipe_read_bytes(int pipe_fd, char *bytes, int required, char **msg)
/* error */
error = errno;
ws_debug("read from pipe %d: error(%u): %s", pipe_fd, error, g_strerror(error));
*msg = g_strdup_printf("Error reading from sync pipe: %s",
*msg = ws_strdup_printf("Error reading from sync pipe: %s",
g_strerror(error));
return newly;
}
Expand Down Expand Up @@ -1564,7 +1564,7 @@ pipe_read_block(int pipe_fd, char *indicator, int len, char *msg,
/*
* Short read, but not an immediate EOF.
*/
*err_msg = g_strdup_printf("Premature EOF reading from sync pipe: got only %ld bytes",
*err_msg = ws_strdup_printf("Premature EOF reading from sync pipe: got only %ld bytes",
(long)newly);
}
return -1;
Expand All @@ -1591,7 +1591,7 @@ pipe_read_block(int pipe_fd, char *indicator, int len, char *msg,
if (newly < 0) { /* error */
ws_debug("read from pipe %d: error(%u): %s", pipe_fd, errno, g_strerror(errno));
}
*err_msg = g_strdup_printf("Unknown message from dumpcap reading header, try to show it as a string: %s",
*err_msg = ws_strdup_printf("Unknown message from dumpcap reading header, try to show it as a string: %s",
msg);
return -1;
}
Expand All @@ -1601,7 +1601,7 @@ pipe_read_block(int pipe_fd, char *indicator, int len, char *msg,
newly = pipe_read_bytes(pipe_fd, msg, required, err_msg);
if(newly != required) {
if (newly != -1) {
*err_msg = g_strdup_printf("Unknown message from dumpcap reading data, try to show it as a string: %s",
*err_msg = ws_strdup_printf("Unknown message from dumpcap reading data, try to show it as a string: %s",
msg);
}
return -1;
Expand Down Expand Up @@ -1660,7 +1660,7 @@ sync_pipe_input_cb(gint source, gpointer user_data)
/* We got an error from the sync pipe. If ret is -1, report
both the sync pipe I/O error and the wait error. */
if (ret == -1) {
combined_msg = g_strdup_printf("%s\n\n%s", primary_msg, wait_msg);
combined_msg = ws_strdup_printf("%s\n\n%s", primary_msg, wait_msg);
g_free(primary_msg);
g_free(wait_msg);
primary_msg = combined_msg;
Expand Down Expand Up @@ -1789,7 +1789,7 @@ sync_pipe_wait_for_child(ws_process_id fork_child, gchar **msgp)
*msgp = NULL; /* assume no error */
#ifdef _WIN32
if (_cwait(&fork_child_status, (intptr_t) fork_child, _WAIT_CHILD) == -1) {
*msgp = g_strdup_printf("Error from cwait(): %s", g_strerror(errno));
*msgp = ws_strdup_printf("Error from cwait(): %s", g_strerror(errno));
ret = -1;
} else {
/*
Expand All @@ -1799,7 +1799,7 @@ sync_pipe_wait_for_child(ws_process_id fork_child, gchar **msgp)
ret = fork_child_status;
if ((fork_child_status & 0xC0000000) == ERROR_SEVERITY_ERROR) {
/* Probably an exception code */
*msgp = g_strdup_printf("Child dumpcap process died: %s",
*msgp = ws_strdup_printf("Child dumpcap process died: %s",
win32strexception(fork_child_status));
ret = -1;
}
Expand All @@ -1816,19 +1816,19 @@ sync_pipe_wait_for_child(ws_process_id fork_child, gchar **msgp)
ret = WEXITSTATUS(fork_child_status);
} else if (WIFSTOPPED(fork_child_status)) {
/* It stopped, rather than exiting. "Should not happen." */
*msgp = g_strdup_printf("Child dumpcap process stopped: %s",
*msgp = ws_strdup_printf("Child dumpcap process stopped: %s",
sync_pipe_signame(WSTOPSIG(fork_child_status)));
ret = -1;
} else if (WIFSIGNALED(fork_child_status)) {
/* It died with a signal. */
*msgp = g_strdup_printf("Child dumpcap process died: %s%s",
*msgp = ws_strdup_printf("Child dumpcap process died: %s%s",
sync_pipe_signame(WTERMSIG(fork_child_status)),
WCOREDUMP(fork_child_status) ? " - core dumped" : "");
ret = -1;
} else {
/* What? It had to either have exited, or stopped, or died with
a signal; what happened here? */
*msgp = g_strdup_printf("Bad status from waitpid(): %#o",
*msgp = ws_strdup_printf("Bad status from waitpid(): %#o",
fork_child_status);
ret = -1;
}
Expand Down Expand Up @@ -1863,7 +1863,7 @@ sync_pipe_wait_for_child(ws_process_id fork_child, gchar **msgp)
ret = fetch_dumpcap_pid ? 0 : -1;
} else {
/* Unknown error. */
*msgp = g_strdup_printf("Error from waitpid(): %s", g_strerror(errno));
*msgp = ws_strdup_printf("Error from waitpid(): %s", g_strerror(errno));
ret = -1;
}
}
Expand Down Expand Up @@ -1982,11 +1982,11 @@ static void create_dummy_signal_pipe() {
if (dummy_signal_pipe != NULL) return;

if (!dummy_control_id) {
dummy_control_id = g_strdup_printf("%d.dummy", GetCurrentProcessId());
dummy_control_id = ws_strdup_printf("%d.dummy", GetCurrentProcessId());
}

/* Create the signal pipe */
dummy_signal_pipe_name = g_strdup_printf(SIGNAL_PIPE_FORMAT, dummy_control_id);
dummy_signal_pipe_name = ws_strdup_printf(SIGNAL_PIPE_FORMAT, dummy_control_id);
dummy_signal_pipe = CreateNamedPipe(utf_8to16(dummy_signal_pipe_name),
PIPE_ACCESS_OUTBOUND, PIPE_TYPE_BYTE, 1, 65535, 65535, 0, NULL);
g_free(dummy_signal_pipe_name);
Expand Down

0 comments on commit 0ccd69e

Please sign in to comment.