mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 03:22:48 -05:00
Giant const-correctness patch of doom!
Having found a lot of unfixed constness issues in recent development, I thought perhaps it was time to get proactive, so I compiled the whole codebase with -Wwrite-strings. That turned up a huge load of const problems, which I've fixed in this commit: the Unix build now goes cleanly through with -Wwrite-strings, and the Windows build is as close as I could get it (there are some lingering issues due to occasional Windows API functions like AcquireCredentialsHandle not having the right constness). Notable fallout beyond the purely mechanical changing of types: - the stuff saved by cmdline_save_param() is now explicitly dupstr()ed, and freed in cmdline_run_saved. - I couldn't make both string arguments to cmdline_process_param() const, because it intentionally writes to one of them in the case where it's the argument to -pw (in the vain hope of being at least slightly friendly to 'ps'), so elsewhere I had to temporarily dupstr() something for the sake of passing it to that function - I had to invent a silly parallel version of const_cmp() so I could pass const string literals in to lookup functions. - stripslashes() in pscp.c and psftp.c has the annoying strchr nature
This commit is contained in:
@ -304,7 +304,8 @@ static void console_data_untrusted(HANDLE hout, const char *data, int len)
|
||||
WriteFile(hout, data, len, &dummy, NULL);
|
||||
}
|
||||
|
||||
int console_get_userpass_input(prompts_t *p, unsigned char *in, int inlen)
|
||||
int console_get_userpass_input(prompts_t *p,
|
||||
const unsigned char *in, int inlen)
|
||||
{
|
||||
HANDLE hin, hout;
|
||||
size_t curr_prompt;
|
||||
|
@ -2406,7 +2406,7 @@ void dlg_beep(void *dlg)
|
||||
MessageBeep(0);
|
||||
}
|
||||
|
||||
void dlg_error_msg(void *dlg, char *msg)
|
||||
void dlg_error_msg(void *dlg, const char *msg)
|
||||
{
|
||||
struct dlgparam *dp = (struct dlgparam *)dlg;
|
||||
MessageBox(dp->hwnd, msg,
|
||||
|
@ -1126,7 +1126,7 @@ void set_raw_mouse_mode(void *frontend, int activate)
|
||||
/*
|
||||
* Print a message box and close the connection.
|
||||
*/
|
||||
void connection_fatal(void *frontend, char *fmt, ...)
|
||||
void connection_fatal(void *frontend, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *stuff, morestuff[100];
|
||||
@ -1148,7 +1148,7 @@ void connection_fatal(void *frontend, char *fmt, ...)
|
||||
/*
|
||||
* Report an error at the command-line parsing stage.
|
||||
*/
|
||||
void cmdline_error(char *fmt, ...)
|
||||
void cmdline_error(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *stuff, morestuff[100];
|
||||
@ -2165,7 +2165,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
|
||||
unsigned int sessno = ((lParam - IDM_SAVED_MIN)
|
||||
/ MENU_SAVED_STEP) + 1;
|
||||
if (sessno < (unsigned)sesslist.nsessions) {
|
||||
char *session = sesslist.sessions[sessno];
|
||||
const char *session = sesslist.sessions[sessno];
|
||||
cl = dupprintf("putty @%s", session);
|
||||
inherit_handles = FALSE;
|
||||
freecl = TRUE;
|
||||
@ -5345,7 +5345,7 @@ void optimised_move(void *frontend, int to, int from, int lines)
|
||||
/*
|
||||
* Print a message box and perform a fatal exit.
|
||||
*/
|
||||
void fatalbox(char *fmt, ...)
|
||||
void fatalbox(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *stuff, morestuff[100];
|
||||
@ -5362,7 +5362,7 @@ void fatalbox(char *fmt, ...)
|
||||
/*
|
||||
* Print a modal (Really Bad) message box and perform a fatal exit.
|
||||
*/
|
||||
void modalfatalbox(char *fmt, ...)
|
||||
void modalfatalbox(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *stuff, morestuff[100];
|
||||
@ -5380,7 +5380,7 @@ void modalfatalbox(char *fmt, ...)
|
||||
/*
|
||||
* Print a message box and don't close the connection.
|
||||
*/
|
||||
void nonfatal(char *fmt, ...)
|
||||
void nonfatal(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *stuff, morestuff[100];
|
||||
@ -5787,7 +5787,7 @@ int from_backend_eof(void *frontend)
|
||||
return TRUE; /* do respond to incoming EOF with outgoing */
|
||||
}
|
||||
|
||||
int get_userpass_input(prompts_t *p, unsigned char *in, int inlen)
|
||||
int get_userpass_input(prompts_t *p, const unsigned char *in, int inlen)
|
||||
{
|
||||
int ret;
|
||||
ret = cmdline_get_passwd_input(p, in, inlen);
|
||||
|
@ -355,7 +355,7 @@ static Ssh_gss_stat ssh_sspi_display_status(struct ssh_gss_library *lib,
|
||||
Ssh_gss_ctx ctx, Ssh_gss_buf *buf)
|
||||
{
|
||||
winSsh_gss_ctx *winctx = (winSsh_gss_ctx *) ctx;
|
||||
char *msg;
|
||||
const char *msg;
|
||||
|
||||
if (winctx == NULL) return SSH_GSS_FAILURE;
|
||||
|
||||
|
@ -239,7 +239,7 @@ static FILE *debug_fp = NULL;
|
||||
static HANDLE debug_hdl = INVALID_HANDLE_VALUE;
|
||||
static int debug_got_console = 0;
|
||||
|
||||
void dputs(char *buf)
|
||||
void dputs(const char *buf)
|
||||
{
|
||||
DWORD dw;
|
||||
|
||||
|
@ -50,7 +50,7 @@ struct SockAddrStep_tag {
|
||||
struct Socket_tag {
|
||||
const struct socket_function_table *fn;
|
||||
/* the above variable absolutely *must* be the first in this structure */
|
||||
char *error;
|
||||
const char *error;
|
||||
SOCKET s;
|
||||
Plug plug;
|
||||
bufchain output_data;
|
||||
@ -356,7 +356,7 @@ static int errstring_compare(void *av, void *bv)
|
||||
|
||||
static tree234 *errstrings = NULL;
|
||||
|
||||
char *winsock_error_string(int error)
|
||||
const char *winsock_error_string(int error)
|
||||
{
|
||||
const char prefix[] = "Network error: ";
|
||||
struct errstring *es;
|
||||
@ -1162,8 +1162,8 @@ Socket sk_new(SockAddr addr, int port, int privport, int oobinline,
|
||||
return (Socket) ret;
|
||||
}
|
||||
|
||||
Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only,
|
||||
int orig_address_family)
|
||||
Socket sk_newlistener(const char *srcaddr, int port, Plug plug,
|
||||
int local_host_only, int orig_address_family)
|
||||
{
|
||||
static const struct socket_function_table fn_table = {
|
||||
sk_tcp_plug,
|
||||
|
@ -27,7 +27,7 @@ static char *cmdline_keyfile = NULL;
|
||||
/*
|
||||
* Print a modal (Really Bad) message box and perform a fatal exit.
|
||||
*/
|
||||
void modalfatalbox(char *fmt, ...)
|
||||
void modalfatalbox(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *stuff;
|
||||
@ -44,7 +44,7 @@ void modalfatalbox(char *fmt, ...)
|
||||
/*
|
||||
* Print a non-fatal message box and do not exit.
|
||||
*/
|
||||
void nonfatal(char *fmt, ...)
|
||||
void nonfatal(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *stuff;
|
||||
@ -1372,7 +1372,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
|
||||
case WM_HELP:
|
||||
{
|
||||
int id = ((LPHELPINFO)lParam)->iCtrlId;
|
||||
char *topic = NULL;
|
||||
const char *topic = NULL;
|
||||
switch (id) {
|
||||
case IDC_GENERATING:
|
||||
case IDC_PROGRESS:
|
||||
|
@ -70,7 +70,7 @@ static int initial_menuitems_count;
|
||||
/*
|
||||
* Print a modal (Really Bad) message box and perform a fatal exit.
|
||||
*/
|
||||
void modalfatalbox(char *fmt, ...)
|
||||
void modalfatalbox(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *buf;
|
||||
@ -594,7 +594,7 @@ static int CALLBACK KeyListProc(HWND hwnd, UINT msg,
|
||||
case WM_HELP:
|
||||
{
|
||||
int id = ((LPHELPINFO)lParam)->iCtrlId;
|
||||
char *topic = NULL;
|
||||
const char *topic = NULL;
|
||||
switch (id) {
|
||||
case 100: topic = WINHELP_CTX_pageant_keylist; break;
|
||||
case 101: topic = WINHELP_CTX_pageant_addkey; break;
|
||||
@ -989,7 +989,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
|
||||
/*
|
||||
* Fork and Exec the command in cmdline. [DBW]
|
||||
*/
|
||||
void spawn_cmd(char *cmdline, char * args, int show)
|
||||
void spawn_cmd(const char *cmdline, const char *args, int show)
|
||||
{
|
||||
if (ShellExecute(NULL, _T("open"), cmdline,
|
||||
args, NULL, show) <= (HINSTANCE) 32) {
|
||||
@ -1023,7 +1023,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
||||
{
|
||||
WNDCLASS wndclass;
|
||||
MSG msg;
|
||||
char *command = NULL;
|
||||
const char *command = NULL;
|
||||
int added_keys = 0;
|
||||
int argc, i;
|
||||
char **argv, **argstart;
|
||||
|
@ -21,7 +21,7 @@ struct agent_callback {
|
||||
int len;
|
||||
};
|
||||
|
||||
void fatalbox(char *p, ...)
|
||||
void fatalbox(const char *p, ...)
|
||||
{
|
||||
va_list ap;
|
||||
fprintf(stderr, "FATAL ERROR: ");
|
||||
@ -35,7 +35,7 @@ void fatalbox(char *p, ...)
|
||||
}
|
||||
cleanup_exit(1);
|
||||
}
|
||||
void modalfatalbox(char *p, ...)
|
||||
void modalfatalbox(const char *p, ...)
|
||||
{
|
||||
va_list ap;
|
||||
fprintf(stderr, "FATAL ERROR: ");
|
||||
@ -49,7 +49,7 @@ void modalfatalbox(char *p, ...)
|
||||
}
|
||||
cleanup_exit(1);
|
||||
}
|
||||
void nonfatal(char *p, ...)
|
||||
void nonfatal(const char *p, ...)
|
||||
{
|
||||
va_list ap;
|
||||
fprintf(stderr, "ERROR: ");
|
||||
@ -58,7 +58,7 @@ void nonfatal(char *p, ...)
|
||||
va_end(ap);
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
void connection_fatal(void *frontend, char *p, ...)
|
||||
void connection_fatal(void *frontend, const char *p, ...)
|
||||
{
|
||||
va_list ap;
|
||||
fprintf(stderr, "FATAL ERROR: ");
|
||||
@ -72,7 +72,7 @@ void connection_fatal(void *frontend, char *p, ...)
|
||||
}
|
||||
cleanup_exit(1);
|
||||
}
|
||||
void cmdline_error(char *p, ...)
|
||||
void cmdline_error(const char *p, ...)
|
||||
{
|
||||
va_list ap;
|
||||
fprintf(stderr, "plink: ");
|
||||
@ -145,7 +145,7 @@ int from_backend_eof(void *frontend_handle)
|
||||
return FALSE; /* do not respond to incoming EOF with outgoing */
|
||||
}
|
||||
|
||||
int get_userpass_input(prompts_t *p, unsigned char *in, int inlen)
|
||||
int get_userpass_input(prompts_t *p, const unsigned char *in, int inlen)
|
||||
{
|
||||
int ret;
|
||||
ret = cmdline_get_passwd_input(p, in, inlen);
|
||||
|
@ -16,7 +16,7 @@
|
||||
Socket make_handle_socket(HANDLE send_H, HANDLE recv_H, Plug plug,
|
||||
int overlapped);
|
||||
|
||||
Socket platform_new_connection(SockAddr addr, char *hostname,
|
||||
Socket platform_new_connection(SockAddr addr, const char *hostname,
|
||||
int port, int privport,
|
||||
int oobinline, int nodelay, int keepalive,
|
||||
Plug plug, Conf *conf)
|
||||
|
@ -199,7 +199,7 @@ static const char *serial_configure(Serial serial, HANDLE serport, Conf *conf)
|
||||
* freed by the caller.
|
||||
*/
|
||||
static const char *serial_init(void *frontend_handle, void **backend_handle,
|
||||
Conf *conf, char *host, int port,
|
||||
Conf *conf, const char *host, int port,
|
||||
char **realhost, int nodelay, int keepalive)
|
||||
{
|
||||
Serial serial;
|
||||
@ -302,7 +302,7 @@ static void serial_reconfig(void *handle, Conf *conf)
|
||||
/*
|
||||
* Called to send data down the serial connection.
|
||||
*/
|
||||
static int serial_send(void *handle, char *buf, int len)
|
||||
static int serial_send(void *handle, const char *buf, int len)
|
||||
{
|
||||
Serial serial = (Serial) handle;
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
char *get_ttymode(void *frontend, const char *mode) { return NULL; }
|
||||
|
||||
int get_userpass_input(prompts_t *p, unsigned char *in, int inlen)
|
||||
int get_userpass_input(prompts_t *p, const unsigned char *in, int inlen)
|
||||
{
|
||||
int ret;
|
||||
ret = cmdline_get_passwd_input(p, in, inlen);
|
||||
@ -87,7 +87,7 @@ struct RFile {
|
||||
HANDLE h;
|
||||
};
|
||||
|
||||
RFile *open_existing_file(char *name, uint64 *size,
|
||||
RFile *open_existing_file(const char *name, uint64 *size,
|
||||
unsigned long *mtime, unsigned long *atime,
|
||||
long *perms)
|
||||
{
|
||||
@ -141,7 +141,7 @@ struct WFile {
|
||||
HANDLE h;
|
||||
};
|
||||
|
||||
WFile *open_new_file(char *name, long perms)
|
||||
WFile *open_new_file(const char *name, long perms)
|
||||
{
|
||||
HANDLE h;
|
||||
WFile *ret;
|
||||
@ -157,7 +157,7 @@ WFile *open_new_file(char *name, long perms)
|
||||
return ret;
|
||||
}
|
||||
|
||||
WFile *open_existing_wfile(char *name, uint64 *size)
|
||||
WFile *open_existing_wfile(const char *name, uint64 *size)
|
||||
{
|
||||
HANDLE h;
|
||||
WFile *ret;
|
||||
@ -239,7 +239,7 @@ uint64 get_file_posn(WFile *f)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int file_type(char *name)
|
||||
int file_type(const char *name)
|
||||
{
|
||||
DWORD attr;
|
||||
attr = GetFileAttributes(name);
|
||||
@ -257,7 +257,7 @@ struct DirHandle {
|
||||
char *name;
|
||||
};
|
||||
|
||||
DirHandle *open_directory(char *name)
|
||||
DirHandle *open_directory(const char *name)
|
||||
{
|
||||
HANDLE h;
|
||||
WIN32_FIND_DATA fdat;
|
||||
@ -316,7 +316,7 @@ void close_directory(DirHandle *dir)
|
||||
sfree(dir);
|
||||
}
|
||||
|
||||
int test_wildcard(char *name, int cmdline)
|
||||
int test_wildcard(const char *name, int cmdline)
|
||||
{
|
||||
HANDLE fh;
|
||||
WIN32_FIND_DATA fdat;
|
||||
@ -364,7 +364,7 @@ static char *stripslashes(char *str, int local)
|
||||
return str;
|
||||
}
|
||||
|
||||
WildcardMatcher *begin_wildcard_matching(char *name)
|
||||
WildcardMatcher *begin_wildcard_matching(const char *name)
|
||||
{
|
||||
HANDLE h;
|
||||
WIN32_FIND_DATA fdat;
|
||||
@ -424,7 +424,7 @@ void finish_wildcard_matching(WildcardMatcher *dir)
|
||||
sfree(dir);
|
||||
}
|
||||
|
||||
int vet_filename(char *name)
|
||||
int vet_filename(const char *name)
|
||||
{
|
||||
if (strchr(name, '/') || strchr(name, '\\') || strchr(name, ':'))
|
||||
return FALSE;
|
||||
@ -435,12 +435,12 @@ int vet_filename(char *name)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int create_directory(char *name)
|
||||
int create_directory(const char *name)
|
||||
{
|
||||
return CreateDirectory(name, NULL) != 0;
|
||||
}
|
||||
|
||||
char *dir_file_cat(char *dir, char *file)
|
||||
char *dir_file_cat(const char *dir, const char *file)
|
||||
{
|
||||
return dupcat(dir, "\\", file, NULL);
|
||||
}
|
||||
@ -691,7 +691,7 @@ static DWORD WINAPI command_read_thread(void *param)
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *ssh_sftp_get_cmdline(char *prompt, int no_fds_ok)
|
||||
char *ssh_sftp_get_cmdline(const char *prompt, int no_fds_ok)
|
||||
{
|
||||
int ret;
|
||||
struct command_read_ctx actx, *ctx = &actx;
|
||||
|
@ -1161,7 +1161,7 @@ void get_unitab(int codepage, wchar_t * unitab, int ftype)
|
||||
}
|
||||
|
||||
int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen,
|
||||
char *mbstr, int mblen, char *defchr, int *defused,
|
||||
char *mbstr, int mblen, const char *defchr, int *defused,
|
||||
struct unicode_data *ucsdata)
|
||||
{
|
||||
char *p;
|
||||
|
@ -94,7 +94,7 @@ void filereq_free(filereq *state)
|
||||
/* Callback function to launch context help. */
|
||||
static VOID CALLBACK message_box_help_callback(LPHELPINFO lpHelpInfo)
|
||||
{
|
||||
char *context = NULL;
|
||||
const char *context = NULL;
|
||||
#define CHECK_CTX(name) \
|
||||
do { \
|
||||
if (lpHelpInfo->dwContextId == WINHELP_CTXID_ ## name) \
|
||||
|
Reference in New Issue
Block a user