From 89da2ddf564a93414ee9ab2df3f053608094e417 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 15 May 2015 11:15:42 +0100 Subject: [PATCH] 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 --- cmdgen.c | 4 +- cmdline.c | 27 ++++++---- conf.c | 42 ++++++++++++++-- config.c | 20 ++++---- dialog.c | 69 +++++++++++++------------- dialog.h | 60 +++++++++++------------ import.c | 21 ++++---- ldisc.c | 4 +- ldiscucs.c | 4 +- logging.c | 2 +- macosx/osxctrls.m | 2 +- macosx/osxdlg.m | 2 +- macosx/osxmain.m | 10 ++-- macosx/osxwin.m | 2 +- misc.c | 4 +- network.h | 13 ++--- proxy.c | 8 +-- proxy.h | 2 +- pscp.c | 119 +++++++++++++++++++++++++-------------------- psftp.c | 34 +++++++------ psftp.h | 26 +++++----- putty.h | 55 ++++++++++++--------- raw.c | 6 +-- rlogin.c | 4 +- settings.c | 28 ++++++----- sftp.c | 33 +++++++------ sftp.h | 20 ++++---- ssh.c | 118 ++++++++++++++++++++++++-------------------- ssh.h | 13 ++--- sshbn.c | 2 +- sshpubk.c | 4 +- telnet.c | 10 ++-- terminal.c | 9 ++-- unix/gtkask.c | 2 +- unix/gtkdlg.c | 19 ++++---- unix/gtkfont.c | 2 +- unix/gtkwin.c | 14 +++--- unix/unix.h | 11 +++-- unix/uxcons.c | 3 +- unix/uxmisc.c | 2 +- unix/uxnet.c | 3 +- unix/uxpgnt.c | 10 ++-- unix/uxplink.c | 12 ++--- unix/uxproxy.c | 2 +- unix/uxpterm.c | 2 +- unix/uxpty.c | 6 +-- unix/uxputty.c | 13 +++-- unix/uxser.c | 6 +-- unix/uxsftp.c | 24 ++++----- unix/uxucs.c | 2 +- windows/wincons.c | 3 +- windows/winctrls.c | 2 +- windows/window.c | 14 +++--- windows/wingss.c | 2 +- windows/winmisc.c | 2 +- windows/winnet.c | 8 +-- windows/winpgen.c | 6 +-- windows/winpgnt.c | 8 +-- windows/winplink.c | 12 ++--- windows/winproxy.c | 2 +- windows/winser.c | 4 +- windows/winsftp.c | 24 ++++----- windows/winucs.c | 2 +- windows/winutils.c | 2 +- x11fwd.c | 8 +-- 65 files changed, 559 insertions(+), 450 deletions(-) diff --git a/cmdgen.c b/cmdgen.c index eefcfda7..4811280b 100644 --- a/cmdgen.c +++ b/cmdgen.c @@ -91,7 +91,7 @@ static void no_progress(void *param, int action, int phase, int iprogress) { } -void modalfatalbox(char *p, ...) +void modalfatalbox(const char *p, ...) { va_list ap; fprintf(stderr, "FATAL ERROR: "); @@ -102,7 +102,7 @@ void modalfatalbox(char *p, ...) cleanup_exit(1); } -void nonfatal(char *p, ...) +void nonfatal(const char *p, ...) { va_list ap; fprintf(stderr, "ERROR: "); diff --git a/cmdline.c b/cmdline.c index 327a585a..ee1d31e7 100644 --- a/cmdline.c +++ b/cmdline.c @@ -44,15 +44,15 @@ struct cmdline_saved_param_set { */ static struct cmdline_saved_param_set saves[NPRIORITIES]; -static void cmdline_save_param(char *p, char *value, int pri) +static void cmdline_save_param(const char *p, const char *value, int pri) { if (saves[pri].nsaved >= saves[pri].savesize) { saves[pri].savesize = saves[pri].nsaved + 32; saves[pri].params = sresize(saves[pri].params, saves[pri].savesize, struct cmdline_saved_param); } - saves[pri].params[saves[pri].nsaved].p = p; - saves[pri].params[saves[pri].nsaved].value = value; + saves[pri].params[saves[pri].nsaved].p = dupstr(p); + saves[pri].params[saves[pri].nsaved].value = dupstr(value); saves[pri].nsaved++; } @@ -85,8 +85,8 @@ void cmdline_cleanup(void) * return means that we aren't capable of processing the prompt and * someone else should do it. */ -int cmdline_get_passwd_input(prompts_t *p, unsigned char *in, int inlen) { - +int cmdline_get_passwd_input(prompts_t *p, const unsigned char *in, int inlen) +{ static int tried_once = 0; /* @@ -125,7 +125,7 @@ int cmdline_get_passwd_input(prompts_t *p, unsigned char *in, int inlen) { */ int cmdline_tooltype = 0; -static int cmdline_check_unavailable(int flag, char *p) +static int cmdline_check_unavailable(int flag, const char *p) { if (cmdline_tooltype & flag) { cmdline_error("option \"%s\" not available in this tool", p); @@ -159,7 +159,8 @@ static int cmdline_check_unavailable(int flag, char *p) if (need_save < 0) return x; \ } while (0) -int cmdline_process_param(char *p, char *value, int need_save, Conf *conf) +int cmdline_process_param(const char *p, char *value, + int need_save, Conf *conf) { int ret = 0; @@ -328,7 +329,8 @@ int cmdline_process_param(char *p, char *value, int need_save, Conf *conf) sfree(host); } if (!strcmp(p, "-m")) { - char *filename, *command; + const char *filename; + char *command; int cmdlen, cmdsize; FILE *fp; int c, d; @@ -578,8 +580,13 @@ int cmdline_process_param(char *p, char *value, int need_save, Conf *conf) void cmdline_run_saved(Conf *conf) { int pri, i; - for (pri = 0; pri < NPRIORITIES; pri++) - for (i = 0; i < saves[pri].nsaved; i++) + for (pri = 0; pri < NPRIORITIES; pri++) { + for (i = 0; i < saves[pri].nsaved; i++) { cmdline_process_param(saves[pri].params[i].p, saves[pri].params[i].value, 0, conf); + sfree(saves[pri].params[i].p); + sfree(saves[pri].params[i].value); + } + saves[pri].nsaved = 0; + } } diff --git a/conf.c b/conf.c index e80f5853..92341758 100644 --- a/conf.c +++ b/conf.c @@ -39,6 +39,16 @@ struct key { } secondary; }; +/* Variant form of struct key which doesn't contain dynamic data, used + * for lookups. */ +struct constkey { + int primary; + union { + int i; + const char *s; + } secondary; +}; + struct value { union { int intval; @@ -88,6 +98,29 @@ static int conf_cmp(void *av, void *bv) } } +static int conf_cmp_constkey(void *av, void *bv) +{ + struct key *a = (struct key *)av; + struct constkey *b = (struct constkey *)bv; + + if (a->primary < b->primary) + return -1; + else if (a->primary > b->primary) + return +1; + switch (subkeytypes[a->primary]) { + case TYPE_INT: + if (a->secondary.i < b->secondary.i) + return -1; + else if (a->secondary.i > b->secondary.i) + return +1; + return 0; + case TYPE_STR: + return strcmp(a->secondary.s, b->secondary.s); + default: + return 0; + } +} + /* * Free any dynamic data items pointed to by a 'struct key'. We * don't free the structure itself, since it's probably part of a @@ -286,7 +319,7 @@ char *conf_get_str_str(Conf *conf, int primary, const char *secondary) char *conf_get_str_strs(Conf *conf, int primary, char *subkeyin, char **subkeyout) { - struct key key; + struct constkey key; struct conf_entry *entry; assert(subkeytypes[primary] == TYPE_STR); @@ -297,7 +330,7 @@ char *conf_get_str_strs(Conf *conf, int primary, entry = findrel234(conf->tree, &key, NULL, REL234_GT); } else { key.secondary.s = ""; - entry = findrel234(conf->tree, &key, NULL, REL234_GE); + entry = findrel234(conf->tree, &key, conf_cmp_constkey, REL234_GE); } if (!entry || entry->key.primary != primary) return NULL; @@ -307,7 +340,7 @@ char *conf_get_str_strs(Conf *conf, int primary, char *conf_get_str_nthstrkey(Conf *conf, int primary, int n) { - struct key key; + struct constkey key; struct conf_entry *entry; int index; @@ -315,7 +348,8 @@ char *conf_get_str_nthstrkey(Conf *conf, int primary, int n) assert(valuetypes[primary] == TYPE_STR); key.primary = primary; key.secondary.s = ""; - entry = findrelpos234(conf->tree, &key, NULL, REL234_GE, &index); + entry = findrelpos234(conf->tree, &key, conf_cmp_constkey, + REL234_GE, &index); if (!entry || entry->key.primary != primary) return NULL; entry = index234(conf->tree, index + n); diff --git a/config.c b/config.c index a134e326..ded51095 100644 --- a/config.c +++ b/config.c @@ -356,7 +356,7 @@ static void cipherlist_handler(union control *ctrl, void *dlg, if (event == EVENT_REFRESH) { int i; - static const struct { char *s; int c; } ciphers[] = { + static const struct { const char *s; int c; } ciphers[] = { { "3DES", CIPHER_3DES }, { "Blowfish", CIPHER_BLOWFISH }, { "DES", CIPHER_DES }, @@ -372,7 +372,7 @@ static void cipherlist_handler(union control *ctrl, void *dlg, for (i = 0; i < CIPHER_MAX; i++) { int c = conf_get_int_int(conf, CONF_ssh_cipherlist, i); int j; - char *cstr = NULL; + const char *cstr = NULL; for (j = 0; j < (sizeof ciphers) / (sizeof ciphers[0]); j++) { if (ciphers[j].c == c) { cstr = ciphers[j].s; @@ -428,7 +428,7 @@ static void kexlist_handler(union control *ctrl, void *dlg, if (event == EVENT_REFRESH) { int i; - static const struct { char *s; int k; } kexes[] = { + static const struct { const char *s; int k; } kexes[] = { { "Diffie-Hellman group 1", KEX_DHGROUP1 }, { "Diffie-Hellman group 14", KEX_DHGROUP14 }, { "Diffie-Hellman group exchange", KEX_DHGEX }, @@ -444,7 +444,7 @@ static void kexlist_handler(union control *ctrl, void *dlg, for (i = 0; i < KEX_MAX; i++) { int k = conf_get_int_int(conf, CONF_ssh_kexlist, i); int j; - char *kstr = NULL; + const char *kstr = NULL; for (j = 0; j < (sizeof kexes) / (sizeof kexes[0]); j++) { if (kexes[j].k == k) { kstr = kexes[j].s; @@ -472,7 +472,7 @@ static void printerbox_handler(union control *ctrl, void *dlg, if (event == EVENT_REFRESH) { int nprinters, i; printer_enum *pe; - char *printer; + const char *printer; dlg_update_start(ctrl, dlg); /* @@ -1119,7 +1119,8 @@ static void portfwd_handler(union control *ctrl, void *dlg, } } else if (event == EVENT_ACTION) { if (ctrl == pfd->addbutton) { - char *family, *type, *src, *key, *val; + const char *family, *type; + char *src, *key, *val; int whichbutton; #ifndef NO_IPV6 @@ -1178,7 +1179,8 @@ static void portfwd_handler(union control *ctrl, void *dlg, if (i < 0) { dlg_beep(dlg); } else { - char *key, *val, *p; + char *key, *p; + const char *val; key = conf_get_str_nthstrkey(conf, CONF_portfwd, i); if (key) { @@ -1450,7 +1452,7 @@ void setup_config_box(struct controlbox *b, int midsession, * logging can sensibly be available. */ { - char *sshlogname, *sshrawlogname; + const char *sshlogname, *sshrawlogname; if ((midsession && protocol == PROT_SSH) || (!midsession && backend_from_proto(PROT_SSH))) { sshlogname = "SSH packets"; @@ -1927,7 +1929,7 @@ void setup_config_box(struct controlbox *b, int midsession, #endif { - char *label = backend_from_proto(PROT_SSH) ? + const char *label = backend_from_proto(PROT_SSH) ? "Logical name of remote host (e.g. for SSH key lookup):" : "Logical name of remote host:"; s = ctrl_getset(b, "Connection", "identity", diff --git a/dialog.c b/dialog.c index cc198775..31a9627b 100644 --- a/dialog.c +++ b/dialog.c @@ -13,7 +13,7 @@ #include "putty.h" #include "dialog.h" -int ctrl_path_elements(char *path) +int ctrl_path_elements(const char *path) { int i = 1; while (*path) { @@ -25,7 +25,7 @@ int ctrl_path_elements(char *path) /* Return the number of matching path elements at the starts of p1 and p2, * or INT_MAX if the paths are identical. */ -int ctrl_path_compare(char *p1, char *p2) +int ctrl_path_compare(const char *p1, const char *p2) { int i = 0; while (*p1 || *p2) { @@ -86,7 +86,7 @@ void ctrl_free_set(struct controlset *s) * path. If that path doesn't exist, return the index where it * should be inserted. */ -static int ctrl_find_set(struct controlbox *b, char *path, int start) +static int ctrl_find_set(struct controlbox *b, const char *path, int start) { int i, last, thisone; @@ -112,7 +112,7 @@ static int ctrl_find_set(struct controlbox *b, char *path, int start) * path, or -1 if no such controlset exists. If -1 is passed as * input, finds the first. */ -int ctrl_find_path(struct controlbox *b, char *path, int index) +int ctrl_find_path(struct controlbox *b, const char *path, int index) { if (index < 0) index = ctrl_find_set(b, path, 1); @@ -127,7 +127,7 @@ int ctrl_find_path(struct controlbox *b, char *path, int index) /* Set up a panel title. */ struct controlset *ctrl_settitle(struct controlbox *b, - char *path, char *title) + const char *path, const char *title) { struct controlset *s = snew(struct controlset); @@ -151,8 +151,8 @@ struct controlset *ctrl_settitle(struct controlbox *b, } /* Retrieve a pointer to a controlset, creating it if absent. */ -struct controlset *ctrl_getset(struct controlbox *b, - char *path, char *name, char *boxtitle) +struct controlset *ctrl_getset(struct controlbox *b, const char *path, + const char *name, const char *boxtitle) { struct controlset *s; int index = ctrl_find_set(b, path, 1); @@ -257,8 +257,8 @@ union control *ctrl_columns(struct controlset *s, int ncolumns, ...) return c; } -union control *ctrl_editbox(struct controlset *s, char *label, char shortcut, - int percentage, +union control *ctrl_editbox(struct controlset *s, const char *label, + char shortcut, int percentage, intorptr helpctx, handler_fn handler, intorptr context, intorptr context2) { @@ -272,8 +272,8 @@ union control *ctrl_editbox(struct controlset *s, char *label, char shortcut, return c; } -union control *ctrl_combobox(struct controlset *s, char *label, char shortcut, - int percentage, +union control *ctrl_combobox(struct controlset *s, const char *label, + char shortcut, int percentage, intorptr helpctx, handler_fn handler, intorptr context, intorptr context2) { @@ -293,7 +293,7 @@ union control *ctrl_combobox(struct controlset *s, char *label, char shortcut, * title is expected to be followed by a shortcut _iff_ `shortcut' * is NO_SHORTCUT. */ -union control *ctrl_radiobuttons(struct controlset *s, char *label, +union control *ctrl_radiobuttons(struct controlset *s, const char *label, char shortcut, int ncolumns, intorptr helpctx, handler_fn handler, intorptr context, ...) { @@ -339,9 +339,9 @@ union control *ctrl_radiobuttons(struct controlset *s, char *label, return c; } -union control *ctrl_pushbutton(struct controlset *s,char *label,char shortcut, - intorptr helpctx, handler_fn handler, - intorptr context) +union control *ctrl_pushbutton(struct controlset *s, const char *label, + char shortcut, intorptr helpctx, + handler_fn handler, intorptr context) { union control *c = ctrl_new(s, CTRL_BUTTON, helpctx, handler, context); c->button.label = label ? dupstr(label) : NULL; @@ -351,9 +351,9 @@ union control *ctrl_pushbutton(struct controlset *s,char *label,char shortcut, return c; } -union control *ctrl_listbox(struct controlset *s,char *label,char shortcut, - intorptr helpctx, handler_fn handler, - intorptr context) +union control *ctrl_listbox(struct controlset *s, const char *label, + char shortcut, intorptr helpctx, + handler_fn handler, intorptr context) { union control *c = ctrl_new(s, CTRL_LISTBOX, helpctx, handler, context); c->listbox.label = label ? dupstr(label) : NULL; @@ -368,8 +368,8 @@ union control *ctrl_listbox(struct controlset *s,char *label,char shortcut, return c; } -union control *ctrl_droplist(struct controlset *s, char *label, char shortcut, - int percentage, intorptr helpctx, +union control *ctrl_droplist(struct controlset *s, const char *label, + char shortcut, int percentage, intorptr helpctx, handler_fn handler, intorptr context) { union control *c = ctrl_new(s, CTRL_LISTBOX, helpctx, handler, context); @@ -385,9 +385,9 @@ union control *ctrl_droplist(struct controlset *s, char *label, char shortcut, return c; } -union control *ctrl_draglist(struct controlset *s,char *label,char shortcut, - intorptr helpctx, handler_fn handler, - intorptr context) +union control *ctrl_draglist(struct controlset *s, const char *label, + char shortcut, intorptr helpctx, + handler_fn handler, intorptr context) { union control *c = ctrl_new(s, CTRL_LISTBOX, helpctx, handler, context); c->listbox.label = label ? dupstr(label) : NULL; @@ -402,10 +402,10 @@ union control *ctrl_draglist(struct controlset *s,char *label,char shortcut, return c; } -union control *ctrl_filesel(struct controlset *s,char *label,char shortcut, - char const *filter, int write, char *title, - intorptr helpctx, handler_fn handler, - intorptr context) +union control *ctrl_filesel(struct controlset *s, const char *label, + char shortcut, const char *filter, int write, + const char *title, intorptr helpctx, + handler_fn handler, intorptr context) { union control *c = ctrl_new(s, CTRL_FILESELECT, helpctx, handler, context); c->fileselect.label = label ? dupstr(label) : NULL; @@ -416,9 +416,9 @@ union control *ctrl_filesel(struct controlset *s,char *label,char shortcut, return c; } -union control *ctrl_fontsel(struct controlset *s,char *label,char shortcut, - intorptr helpctx, handler_fn handler, - intorptr context) +union control *ctrl_fontsel(struct controlset *s, const char *label, + char shortcut, intorptr helpctx, + handler_fn handler, intorptr context) { union control *c = ctrl_new(s, CTRL_FONTSELECT, helpctx, handler, context); c->fontselect.label = label ? dupstr(label) : NULL; @@ -433,16 +433,17 @@ union control *ctrl_tabdelay(struct controlset *s, union control *ctrl) return c; } -union control *ctrl_text(struct controlset *s, char *text, intorptr helpctx) +union control *ctrl_text(struct controlset *s, const char *text, + intorptr helpctx) { union control *c = ctrl_new(s, CTRL_TEXT, helpctx, NULL, P(NULL)); c->text.label = dupstr(text); return c; } -union control *ctrl_checkbox(struct controlset *s, char *label, char shortcut, - intorptr helpctx, handler_fn handler, - intorptr context) +union control *ctrl_checkbox(struct controlset *s, const char *label, + char shortcut, intorptr helpctx, + handler_fn handler, intorptr context) { union control *c = ctrl_new(s, CTRL_CHECKBOX, helpctx, handler, context); c->checkbox.label = label ? dupstr(label) : NULL; diff --git a/dialog.h b/dialog.h index 67751670..9ac355c6 100644 --- a/dialog.h +++ b/dialog.h @@ -458,10 +458,10 @@ void ctrl_free_box(struct controlbox *); /* Set up a panel title. */ struct controlset *ctrl_settitle(struct controlbox *, - char *path, char *title); + const char *path, const char *title); /* Retrieve a pointer to a controlset, creating it if absent. */ -struct controlset *ctrl_getset(struct controlbox *, - char *path, char *name, char *boxtitle); +struct controlset *ctrl_getset(struct controlbox *, const char *path, + const char *name, const char *boxtitle); void ctrl_free_set(struct controlset *); void ctrl_free(union control *); @@ -493,12 +493,12 @@ void *ctrl_alloc_with_free(struct controlbox *b, size_t size, /* `ncolumns' is followed by that many percentages, as integers. */ union control *ctrl_columns(struct controlset *, int ncolumns, ...); -union control *ctrl_editbox(struct controlset *, char *label, char shortcut, - int percentage, intorptr helpctx, +union control *ctrl_editbox(struct controlset *, const char *label, + char shortcut, int percentage, intorptr helpctx, handler_fn handler, intorptr context, intorptr context2); -union control *ctrl_combobox(struct controlset *, char *label, char shortcut, - int percentage, intorptr helpctx, +union control *ctrl_combobox(struct controlset *, const char *label, + char shortcut, int percentage, intorptr helpctx, handler_fn handler, intorptr context, intorptr context2); /* @@ -507,32 +507,32 @@ union control *ctrl_combobox(struct controlset *, char *label, char shortcut, * title is expected to be followed by a shortcut _iff_ `shortcut' * is NO_SHORTCUT. */ -union control *ctrl_radiobuttons(struct controlset *, char *label, - char shortcut, int ncolumns, - intorptr helpctx, +union control *ctrl_radiobuttons(struct controlset *, const char *label, + char shortcut, int ncolumns, intorptr helpctx, handler_fn handler, intorptr context, ...); -union control *ctrl_pushbutton(struct controlset *,char *label,char shortcut, - intorptr helpctx, +union control *ctrl_pushbutton(struct controlset *, const char *label, + char shortcut, intorptr helpctx, handler_fn handler, intorptr context); -union control *ctrl_listbox(struct controlset *,char *label,char shortcut, - intorptr helpctx, +union control *ctrl_listbox(struct controlset *, const char *label, + char shortcut, intorptr helpctx, handler_fn handler, intorptr context); -union control *ctrl_droplist(struct controlset *, char *label, char shortcut, - int percentage, intorptr helpctx, +union control *ctrl_droplist(struct controlset *, const char *label, + char shortcut, int percentage, intorptr helpctx, handler_fn handler, intorptr context); -union control *ctrl_draglist(struct controlset *,char *label,char shortcut, - intorptr helpctx, +union control *ctrl_draglist(struct controlset *, const char *label, + char shortcut, intorptr helpctx, handler_fn handler, intorptr context); -union control *ctrl_filesel(struct controlset *,char *label,char shortcut, - char const *filter, int write, char *title, - intorptr helpctx, +union control *ctrl_filesel(struct controlset *, const char *label, + char shortcut, const char *filter, int write, + const char *title, intorptr helpctx, handler_fn handler, intorptr context); -union control *ctrl_fontsel(struct controlset *,char *label,char shortcut, - intorptr helpctx, +union control *ctrl_fontsel(struct controlset *, const char *label, + char shortcut, intorptr helpctx, handler_fn handler, intorptr context); -union control *ctrl_text(struct controlset *, char *text, intorptr helpctx); -union control *ctrl_checkbox(struct controlset *, char *label, char shortcut, - intorptr helpctx, +union control *ctrl_text(struct controlset *, const char *text, + intorptr helpctx); +union control *ctrl_checkbox(struct controlset *, const char *label, + char shortcut, intorptr helpctx, handler_fn handler, intorptr context); union control *ctrl_tabdelay(struct controlset *, union control *); @@ -597,7 +597,7 @@ union control *dlg_last_focused(union control *ctrl, void *dlg); * error; dlg_error() puts up a message-box or equivalent. */ void dlg_beep(void *dlg); -void dlg_error_msg(void *dlg, char *msg); +void dlg_error_msg(void *dlg, const char *msg); /* * This function signals to the front end that the dialog's * processing is completed, and passes an integer value (typically @@ -647,8 +647,8 @@ void dlg_refresh(union control *ctrl, void *dlg); * ... process this controlset ... * } */ -int ctrl_find_path(struct controlbox *b, char *path, int index); -int ctrl_path_elements(char *path); +int ctrl_find_path(struct controlbox *b, const char *path, int index); +int ctrl_path_elements(const char *path); /* Return the number of matching path elements at the starts of p1 and p2, * or INT_MAX if the paths are identical. */ -int ctrl_path_compare(char *p1, char *p2); +int ctrl_path_compare(const char *p1, const char *p2); diff --git a/import.c b/import.c index ed57add0..1e91f82a 100644 --- a/import.c +++ b/import.c @@ -362,7 +362,8 @@ static struct openssh_pem_key *load_openssh_pem_key(const Filename *filename, struct openssh_pem_key *ret; FILE *fp = NULL; char *line = NULL; - char *errmsg, *p; + const char *errmsg; + char *p; int headers_done; char base64_bit[4]; int base64_chars = 0; @@ -570,7 +571,7 @@ struct ssh2_userkey *openssh_pem_read(const Filename *filename, int ret, id, len, flags; int i, num_integers; struct ssh2_userkey *retval = NULL; - char *errmsg; + const char *errmsg; unsigned char *blob; int blobsize = 0, blobptr, privptr; char *modptr = NULL; @@ -910,7 +911,7 @@ int openssh_pem_write(const Filename *filename, struct ssh2_userkey *key, int outlen; struct mpint_pos numbers[9]; int nnumbers, pos, len, seqlen, i; - char *header, *footer; + const char *header, *footer; char zero[1]; unsigned char iv[8]; int ret = 0; @@ -1283,7 +1284,8 @@ static struct openssh_new_key *load_openssh_new_key(const Filename *filename, struct openssh_new_key *ret; FILE *fp = NULL; char *line = NULL; - char *errmsg, *p; + const char *errmsg; + char *p; char base64_bit[4]; int base64_chars = 0; const void *filedata; @@ -1526,7 +1528,7 @@ struct ssh2_userkey *openssh_new_read(const Filename *filename, struct ssh2_userkey *retkey; int i; struct ssh2_userkey *retval = NULL; - char *errmsg; + const char *errmsg; unsigned char *blob; int blobsize = 0; unsigned checkint0, checkint1; @@ -1981,7 +1983,8 @@ static struct sshcom_key *load_sshcom_key(const Filename *filename, FILE *fp; char *line = NULL; int hdrstart, len; - char *errmsg, *p; + const char *errmsg; + char *p; int headers_done; char base64_bit[4]; int base64_chars = 0; @@ -2226,7 +2229,7 @@ struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase, const char **errmsg_p) { struct sshcom_key *key = load_sshcom_key(filename, errmsg_p); - char *errmsg; + const char *errmsg; int pos, len; const char prefix_rsa[] = "if-modn{sign{rsa"; const char prefix_dsa[] = "dl-modp{sign{dsa"; @@ -2470,7 +2473,7 @@ int sshcom_write(const Filename *filename, struct ssh2_userkey *key, int outlen; struct mpint_pos numbers[6]; int nnumbers, initial_zero, pos, lenpos, i; - char *type; + const char *type; char *ciphertext; int cipherlen; int ret = 0; @@ -2566,7 +2569,7 @@ int sshcom_write(const Filename *filename, struct ssh2_userkey *key, pos += 4; /* length field, fill in later */ pos += put_string(outblob+pos, type, strlen(type)); { - char *ciphertype = passphrase ? "3des-cbc" : "none"; + const char *ciphertype = passphrase ? "3des-cbc" : "none"; pos += put_string(outblob+pos, ciphertype, strlen(ciphertype)); } lenpos = pos; /* remember this position */ diff --git a/ldisc.c b/ldisc.c index 0e864874..320a9360 100644 --- a/ldisc.c +++ b/ldisc.c @@ -22,7 +22,7 @@ (ldisc->back->ldisc(ldisc->backhandle, LD_EDIT) || \ term_ldisc(ldisc->term, LD_EDIT)))) -static void c_write(Ldisc ldisc, char *buf, int len) +static void c_write(Ldisc ldisc, const char *buf, int len) { from_backend(ldisc->frontend, 0, buf, len); } @@ -134,7 +134,7 @@ void ldisc_echoedit_update(void *handle) frontend_echoedit_update(ldisc->frontend, ECHOING, EDITING); } -void ldisc_send(void *handle, char *buf, int len, int interactive) +void ldisc_send(void *handle, const char *buf, int len, int interactive) { Ldisc ldisc = (Ldisc) handle; int keyflag = 0; diff --git a/ldiscucs.c b/ldiscucs.c index fe0da8a6..1634bc43 100644 --- a/ldiscucs.c +++ b/ldiscucs.c @@ -13,7 +13,7 @@ #include "ldisc.h" void lpage_send(void *handle, - int codepage, char *buf, int len, int interactive) + int codepage, const char *buf, int len, int interactive) { Ldisc ldisc = (Ldisc)handle; wchar_t *widebuffer = 0; @@ -34,7 +34,7 @@ void lpage_send(void *handle, sfree(widebuffer); } -void luni_send(void *handle, wchar_t * widebuf, int len, int interactive) +void luni_send(void *handle, const wchar_t *widebuf, int len, int interactive) { Ldisc ldisc = (Ldisc)handle; int ratio = (in_utf(ldisc->term))?3:1; diff --git a/logging.c b/logging.c index 26634f77..899fa27b 100644 --- a/logging.c +++ b/logging.c @@ -233,7 +233,7 @@ void log_eventlog(void *handle, const char *event) * Set of blanking areas must be in increasing order. */ void log_packet(void *handle, int direction, int type, - char *texttype, const void *data, int len, + const char *texttype, const void *data, int len, int n_blanks, const struct logblank_t *blanks, const unsigned long *seq, unsigned downstream_id, const char *additional_log_text) diff --git a/macosx/osxctrls.m b/macosx/osxctrls.m index b4270f9d..27c2c52b 100644 --- a/macosx/osxctrls.m +++ b/macosx/osxctrls.m @@ -1736,7 +1736,7 @@ void dlg_beep(void *dv) NSBeep(); } -void dlg_error_msg(void *dv, char *msg) +void dlg_error_msg(void *dv, const char *msg) { /* FIXME */ } diff --git a/macosx/osxdlg.m b/macosx/osxdlg.m index 09407819..84a761fe 100644 --- a/macosx/osxdlg.m +++ b/macosx/osxdlg.m @@ -490,7 +490,7 @@ static void connection_fatal_callback(void *ctx, int result) [win endSession:FALSE]; } -void connection_fatal(void *frontend, char *p, ...) +void connection_fatal(void *frontend, const char *p, ...) { SessionWindow *win = (SessionWindow *)frontend; va_list ap; diff --git a/macosx/osxmain.m b/macosx/osxmain.m index 2eba150c..2ac772a8 100644 --- a/macosx/osxmain.m +++ b/macosx/osxmain.m @@ -58,7 +58,7 @@ char *x_get_default(const char *key) return NULL; /* this is a stub */ } -static void commonfatalbox(char *p, va_list ap) +static void commonfatalbox(const char *p, va_list ap) { char errorbuf[2048]; NSAlert *alert; @@ -85,7 +85,7 @@ static void commonfatalbox(char *p, va_list ap) exit(1); } -void nonfatal(void *frontend, char *p, ...) +void nonfatal(void *frontend, const char *p, ...) { char *errorbuf; NSAlert *alert; @@ -103,7 +103,7 @@ void nonfatal(void *frontend, char *p, ...) sfree(errorbuf); } -void fatalbox(char *p, ...) +void fatalbox(const char *p, ...) { va_list ap; va_start(ap, p); @@ -111,7 +111,7 @@ void fatalbox(char *p, ...) va_end(ap); } -void modalfatalbox(char *p, ...) +void modalfatalbox(const char *p, ...) { va_list ap; va_start(ap, p); @@ -119,7 +119,7 @@ void modalfatalbox(char *p, ...) va_end(ap); } -void cmdline_error(char *p, ...) +void cmdline_error(const char *p, ...) { va_list ap; fprintf(stderr, "%s: ", appname); diff --git a/macosx/osxwin.m b/macosx/osxwin.m index 3bf85cd8..06291369 100644 --- a/macosx/osxwin.m +++ b/macosx/osxwin.m @@ -888,7 +888,7 @@ int from_backend_untrusted(void *frontend, const char *data, int len) return [win fromBackendUntrusted:data len:len]; } -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) { SessionWindow *win = (SessionWindow *)p->frontend; Terminal *term = [win term]; diff --git a/misc.c b/misc.c index c6587ab1..37c0207e 100644 --- a/misc.c +++ b/misc.c @@ -175,7 +175,7 @@ int main(void) return fails != 0 ? 1 : 0; } /* Stubs to stop the rest of this module causing compile failures. */ -void modalfatalbox(char *fmt, ...) {} +void modalfatalbox(const char *fmt, ...) {} int conf_get_int(Conf *conf, int primary) { return 0; } char *conf_get_str(Conf *conf, int primary) { return NULL; } #endif /* TEST_HOST_STRFOO */ @@ -830,7 +830,7 @@ void safefree(void *ptr) */ #ifdef DEBUG -extern void dputs(char *); /* defined in per-platform *misc.c */ +extern void dputs(const char *); /* defined in per-platform *misc.c */ void debug_printf(const char *fmt, ...) { diff --git a/network.h b/network.h index 675d24c7..ec67ba94 100644 --- a/network.h +++ b/network.h @@ -92,20 +92,20 @@ struct plug_function_table { /* proxy indirection layer */ /* NB, control of 'addr' is passed via new_connection, which takes * responsibility for freeing it */ -Socket new_connection(SockAddr addr, char *hostname, +Socket new_connection(SockAddr addr, const char *hostname, int port, int privport, int oobinline, int nodelay, int keepalive, Plug plug, Conf *conf); -Socket new_listener(char *srcaddr, int port, Plug plug, int local_host_only, - Conf *conf, int addressfamily); -SockAddr name_lookup(char *host, int port, char **canonicalname, +Socket new_listener(const char *srcaddr, int port, Plug plug, + int local_host_only, Conf *conf, int addressfamily); +SockAddr name_lookup(const char *host, int port, char **canonicalname, Conf *conf, int addressfamily); int proxy_for_destination (SockAddr addr, const char *hostname, int port, Conf *conf); /* platform-dependent callback from new_connection() */ /* (same caveat about addr as new_connection()) */ -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); @@ -137,7 +137,8 @@ SockAddr sk_addr_dup(SockAddr addr); Socket sk_new(SockAddr addr, int port, int privport, int oobinline, int nodelay, int keepalive, Plug p); -Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only, int address_family); +Socket sk_newlistener(const char *srcaddr, int port, Plug plug, + int local_host_only, int address_family); #define sk_plug(s,p) (((*s)->plug) (s, p)) #define sk_close(s) (((*s)->close) (s)) diff --git a/proxy.c b/proxy.c index e2201c64..423ed8da 100644 --- a/proxy.c +++ b/proxy.c @@ -362,7 +362,7 @@ int proxy_for_destination (SockAddr addr, const char *hostname, return 1; } -SockAddr name_lookup(char *host, int port, char **canonicalname, +SockAddr name_lookup(const char *host, int port, char **canonicalname, Conf *conf, int addressfamily) { if (conf_get_int(conf, CONF_proxy_type) != PROXY_NONE && @@ -375,7 +375,7 @@ SockAddr name_lookup(char *host, int port, char **canonicalname, return sk_namelookup(host, canonicalname, addressfamily); } -Socket new_connection(SockAddr addr, char *hostname, +Socket new_connection(SockAddr addr, const char *hostname, int port, int privport, int oobinline, int nodelay, int keepalive, Plug plug, Conf *conf) @@ -488,8 +488,8 @@ Socket new_connection(SockAddr addr, char *hostname, return sk_new(addr, port, privport, oobinline, nodelay, keepalive, plug); } -Socket new_listener(char *srcaddr, int port, Plug plug, int local_host_only, - Conf *conf, int addressfamily) +Socket new_listener(const char *srcaddr, int port, Plug plug, + int local_host_only, Conf *conf, int addressfamily) { /* TODO: SOCKS (and potentially others) support inbound * TODO: connections via the proxy. support them. diff --git a/proxy.h b/proxy.h index 12b47e16..2e2324c0 100644 --- a/proxy.h +++ b/proxy.h @@ -19,7 +19,7 @@ struct Socket_proxy_tag { const struct socket_function_table *fn; /* the above variable absolutely *must* be the first in this structure */ - char * error; + const char *error; Socket sub_socket; Plug plug; diff --git a/pscp.c b/pscp.c index 50ab90b5..1d4967e7 100644 --- a/pscp.c +++ b/pscp.c @@ -48,9 +48,9 @@ static void *backhandle; static Conf *conf; int sent_eof = FALSE; -static void source(char *src); -static void rsource(char *src); -static void sink(char *targ, char *src); +static void source(const char *src); +static void rsource(const char *src); +static void sink(const char *targ, const char *src); const char *const appname = "PSCP"; @@ -62,12 +62,12 @@ const char *const appname = "PSCP"; void ldisc_echoedit_update(void *handle) { } -static void tell_char(FILE * stream, char c) +static void tell_char(FILE *stream, char c) { fputc(c, stream); } -static void tell_str(FILE * stream, char *str) +static void tell_str(FILE *stream, const char *str) { unsigned int i; @@ -75,7 +75,7 @@ static void tell_str(FILE * stream, char *str) tell_char(stream, str[i]); } -static void tell_user(FILE * stream, char *fmt, ...) +static void tell_user(FILE *stream, const char *fmt, ...) { char *str, *str2; va_list ap; @@ -91,7 +91,7 @@ static void tell_user(FILE * stream, char *fmt, ...) /* * Print an error message and perform a fatal exit. */ -void fatalbox(char *fmt, ...) +void fatalbox(const char *fmt, ...) { char *str, *str2; va_list ap; @@ -106,7 +106,7 @@ void fatalbox(char *fmt, ...) cleanup_exit(1); } -void modalfatalbox(char *fmt, ...) +void modalfatalbox(const char *fmt, ...) { char *str, *str2; va_list ap; @@ -121,7 +121,7 @@ void modalfatalbox(char *fmt, ...) cleanup_exit(1); } -void nonfatal(char *fmt, ...) +void nonfatal(const char *fmt, ...) { char *str, *str2; va_list ap; @@ -134,7 +134,7 @@ void nonfatal(char *fmt, ...) sfree(str2); errs++; } -void connection_fatal(void *frontend, char *fmt, ...) +void connection_fatal(void *frontend, const char *fmt, ...) { char *str, *str2; va_list ap; @@ -302,7 +302,7 @@ static void ssh_scp_init(void) /* * Print an error message and exit after closing the SSH link. */ -static void bump(char *fmt, ...) +static void bump(const char *fmt, ...) { char *str, *str2; va_list ap; @@ -533,7 +533,7 @@ static void do_cmd(char *host, char *user, char *cmd) /* * Update statistic information about current file. */ -static void print_stats(char *name, uint64 size, uint64 done, +static void print_stats(const char *name, uint64 size, uint64 done, time_t start, time_t now) { float ratebs; @@ -608,8 +608,13 @@ static char *colon(char *str) /* * Return a pointer to the portion of str that comes after the last * slash (or backslash or colon, if `local' is TRUE). + * + * This function has the annoying strstr() property of taking a const + * char * and returning a char *. You should treat it as if it was a + * pair of overloaded functions, one mapping mutable->mutable and the + * other const->const :-( */ -static char *stripslashes(char *str, int local) +static char *stripslashes(const char *str, int local) { char *p; @@ -626,7 +631,7 @@ static char *stripslashes(char *str, int local) if (p) str = p+1; } - return str; + return (char *)str; } /* @@ -692,7 +697,7 @@ static int sftp_ls_compare(const void *av, const void *bv) const struct fxp_name *b = (const struct fxp_name *) bv; return strcmp(a->filename, b->filename); } -void scp_sftp_listdir(char *dirname) +void scp_sftp_listdir(const char *dirname) { struct fxp_handle *dirh; struct fxp_names *names; @@ -791,7 +796,7 @@ static struct fxp_handle *scp_sftp_filehandle; static struct fxp_xfer *scp_sftp_xfer; static uint64 scp_sftp_fileoffset; -int scp_source_setup(char *target, int shouldbedir) +int scp_source_setup(const char *target, int shouldbedir) { if (using_sftp) { /* @@ -857,7 +862,7 @@ int scp_send_filetimes(unsigned long mtime, unsigned long atime) } } -int scp_send_filename(char *name, uint64 size, int permissions) +int scp_send_filename(const char *name, uint64 size, int permissions) { if (using_sftp) { char *fullname; @@ -1012,7 +1017,7 @@ void scp_restore_remotepath(char *data) scp_sftp_remotepath = data; } -int scp_send_dirname(char *name, int modes) +int scp_send_dirname(const char *name, int modes) { if (using_sftp) { char *fullname; @@ -1087,7 +1092,7 @@ int scp_send_enddir(void) * right at the start, whereas scp_sink_init is called to * initialise every level of recursion in the protocol. */ -int scp_sink_setup(char *source, int preserve, int recursive) +int scp_sink_setup(const char *source, int preserve, int recursive) { if (using_sftp) { char *newsource; @@ -1657,12 +1662,12 @@ static void run_err(const char *fmt, ...) /* * Execute the source part of the SCP protocol. */ -static void source(char *src) +static void source(const char *src) { uint64 size; unsigned long mtime, atime; long permissions; - char *last; + const char *last; RFile *f; int attr; uint64 i; @@ -1682,7 +1687,7 @@ static void source(char *src) /* * Avoid . and .. directories. */ - char *p; + const char *p; p = strrchr(src, '/'); if (!p) p = strrchr(src, '\\'); @@ -1770,9 +1775,9 @@ static void source(char *src) /* * Recursively send the contents of a directory. */ -static void rsource(char *src) +static void rsource(const char *src) { - char *last; + const char *last; char *save_target; DirHandle *dir; @@ -1814,7 +1819,7 @@ static void rsource(char *src) /* * Execute the sink part of the SCP protocol. */ -static void sink(char *targ, char *src) +static void sink(const char *targ, const char *src) { char *destfname; int targisdir = 0; @@ -2020,23 +2025,26 @@ static void sink(char *targ, char *src) */ static void toremote(int argc, char *argv[]) { - char *src, *targ, *host, *user; + char *src, *wtarg, *host, *user; + const char *targ; char *cmd; int i, wc_type; uploading = 1; - targ = argv[argc - 1]; + wtarg = argv[argc - 1]; /* Separate host from filename */ - host = targ; - targ = colon(targ); - if (targ == NULL) - bump("targ == NULL in toremote()"); - *targ++ = '\0'; - if (*targ == '\0') - targ = "."; + host = wtarg; + wtarg = colon(wtarg); + if (wtarg == NULL) + bump("wtarg == NULL in toremote()"); + *wtarg++ = '\0'; /* Substitute "." for empty target */ + if (*wtarg == '\0') + targ = "."; + else + targ = wtarg; /* Separate host and username */ user = host; @@ -2112,7 +2120,8 @@ static void toremote(int argc, char *argv[]) */ static void tolocal(int argc, char *argv[]) { - char *src, *targ, *host, *user; + char *wsrc, *host, *user; + const char *src, *targ; char *cmd; uploading = 0; @@ -2120,18 +2129,20 @@ static void tolocal(int argc, char *argv[]) if (argc != 2) bump("More than one remote source not supported"); - src = argv[0]; + wsrc = argv[0]; targ = argv[1]; /* Separate host from filename */ - host = src; - src = colon(src); - if (src == NULL) + host = wsrc; + wsrc = colon(wsrc); + if (wsrc == NULL) bump("Local to local copy not supported"); - *src++ = '\0'; - if (*src == '\0') - src = "."; + *wsrc++ = '\0'; /* Substitute "." for empty filename */ + if (*wsrc == '\0') + src = "."; + else + src = wsrc; /* Separate username and hostname */ user = host; @@ -2164,21 +2175,25 @@ static void tolocal(int argc, char *argv[]) */ static void get_dir_list(int argc, char *argv[]) { - char *src, *host, *user; - char *cmd, *p, *q; + char *wsrc, *host, *user; + const char *src; + char *cmd, *p; + const char *q; char c; - src = argv[0]; + wsrc = argv[0]; /* Separate host from filename */ - host = src; - src = colon(src); - if (src == NULL) + host = wsrc; + wsrc = colon(wsrc); + if (wsrc == NULL) bump("Local file listing not supported"); - *src++ = '\0'; - if (*src == '\0') - src = "."; + *wsrc++ = '\0'; /* Substitute "." for empty filename */ + if (*wsrc == '\0') + src = "."; + else + src = wsrc; /* Separate username and hostname */ user = host; @@ -2273,7 +2288,7 @@ void version(void) cleanup_exit(1); } -void cmdline_error(char *p, ...) +void cmdline_error(const char *p, ...) { va_list ap; fprintf(stderr, "pscp: "); diff --git a/psftp.c b/psftp.c index a8baad6d..e0e027a1 100644 --- a/psftp.c +++ b/psftp.c @@ -68,7 +68,7 @@ struct sftp_packet *sftp_wait_for_reply(struct sftp_request *req) * canonification fails, at least fall back to returning a _valid_ * pathname (though it may be ugly, eg /home/simon/../foobar). */ -char *canonify(char *name) +char *canonify(const char *name) { char *fullname, *canonname; struct sftp_packet *pktin; @@ -77,7 +77,7 @@ char *canonify(char *name) if (name[0] == '/') { fullname = dupstr(name); } else { - char *slash; + const char *slash; if (pwd[strlen(pwd) - 1] == '/') slash = ""; else @@ -172,8 +172,13 @@ char *canonify(char *name) /* * Return a pointer to the portion of str that comes after the last * slash (or backslash or colon, if `local' is TRUE). + * + * This function has the annoying strstr() property of taking a const + * char * and returning a char *. You should treat it as if it was a + * pair of overloaded functions, one mapping mutable->mutable and the + * other const->const :-( */ -static char *stripslashes(char *str, int local) +static char *stripslashes(const char *str, int local) { char *p; @@ -190,7 +195,7 @@ static char *stripslashes(char *str, int local) if (p) str = p+1; } - return str; + return (char *)str; } /* @@ -1011,7 +1016,8 @@ int sftp_cmd_ls(struct sftp_command *cmd) struct fxp_names *names; struct fxp_name **ournames; int nnames, namesize; - char *dir, *cdir, *unwcdir, *wildcard; + const char *dir; + char *cdir, *unwcdir, *wildcard; struct sftp_packet *pktin; struct sftp_request *req; int i; @@ -1901,7 +1907,7 @@ static int sftp_cmd_pling(struct sftp_command *cmd) static int sftp_cmd_help(struct sftp_command *cmd); static struct sftp_cmd_lookup { - char *name; + const char *name; /* * For help purposes, there are two kinds of command: * @@ -1915,8 +1921,8 @@ static struct sftp_cmd_lookup { * contains the help that should double up for this command. */ int listed; /* do we list this in primary help? */ - char *shorthelp; - char *longhelp; + const char *shorthelp; + const char *longhelp; int (*obey) (struct sftp_command *); } sftp_lookup[] = { /* @@ -2139,7 +2145,7 @@ static struct sftp_cmd_lookup { } }; -const struct sftp_cmd_lookup *lookup_command(char *name) +const struct sftp_cmd_lookup *lookup_command(const char *name) { int i, j, k, cmp; @@ -2450,7 +2456,7 @@ static int verbose = 0; /* * Print an error message and perform a fatal exit. */ -void fatalbox(char *fmt, ...) +void fatalbox(const char *fmt, ...) { char *str, *str2; va_list ap; @@ -2464,7 +2470,7 @@ void fatalbox(char *fmt, ...) cleanup_exit(1); } -void modalfatalbox(char *fmt, ...) +void modalfatalbox(const char *fmt, ...) { char *str, *str2; va_list ap; @@ -2478,7 +2484,7 @@ void modalfatalbox(char *fmt, ...) cleanup_exit(1); } -void nonfatal(char *fmt, ...) +void nonfatal(const char *fmt, ...) { char *str, *str2; va_list ap; @@ -2490,7 +2496,7 @@ void nonfatal(char *fmt, ...) fputs(str2, stderr); sfree(str2); } -void connection_fatal(void *frontend, char *fmt, ...) +void connection_fatal(void *frontend, const char *fmt, ...) { char *str, *str2; va_list ap; @@ -2866,7 +2872,7 @@ static int psftp_connect(char *userhost, char *user, int portnumber) return 0; } -void cmdline_error(char *p, ...) +void cmdline_error(const char *p, ...) { va_list ap; fprintf(stderr, "psftp: "); diff --git a/psftp.h b/psftp.h index e6ad00f6..b3022d56 100644 --- a/psftp.h +++ b/psftp.h @@ -45,7 +45,7 @@ int ssh_sftp_loop_iteration(void); * FALSE, a back end is not (intentionally) active at all (e.g. * psftp before an `open' command). */ -char *ssh_sftp_get_cmdline(char *prompt, int backend_required); +char *ssh_sftp_get_cmdline(const char *prompt, int backend_required); /* * The main program in psftp.c. Called from main() in the platform- @@ -59,13 +59,13 @@ int psftp_main(int argc, char *argv[]); * probably only ever be supported on Windows, so these functions * can safely be stubs on all other platforms. */ -void gui_update_stats(char *name, unsigned long size, +void gui_update_stats(const char *name, unsigned long size, int percentage, unsigned long elapsed, unsigned long done, unsigned long eta, unsigned long ratebs); void gui_send_errcount(int list, int errs); void gui_send_char(int is_stderr, int c); -void gui_enable(char *arg); +void gui_enable(const char *arg); /* * It's likely that a given platform's implementation of file @@ -87,15 +87,15 @@ typedef struct RFile RFile; typedef struct WFile WFile; /* Output params size, perms, mtime and atime can all be NULL if * desired. perms will be -1 if the OS does not support POSIX permissions. */ -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); -WFile *open_existing_wfile(char *name, uint64 *size); +WFile *open_existing_wfile(const char *name, uint64 *size); /* Returns <0 on error, 0 on eof, or number of bytes read, as usual */ int read_from_file(RFile *f, void *buffer, int length); /* Closes and frees the RFile */ void close_rfile(RFile *f); -WFile *open_new_file(char *name, long perms); +WFile *open_new_file(const char *name, long perms); /* Returns <0 on error, 0 on eof, or number of bytes written, as usual */ int write_to_file(WFile *f, void *buffer, int length); void set_file_times(WFile *f, unsigned long mtime, unsigned long atime); @@ -117,13 +117,13 @@ uint64 get_file_posn(WFile *f); enum { FILE_TYPE_NONEXISTENT, FILE_TYPE_FILE, FILE_TYPE_DIRECTORY, FILE_TYPE_WEIRD }; -int file_type(char *name); +int file_type(const char *name); /* * Read all the file names out of a directory. */ typedef struct DirHandle DirHandle; -DirHandle *open_directory(char *name); +DirHandle *open_directory(const char *name); /* The string returned from this will need freeing if not NULL */ char *read_filename(DirHandle *dir); void close_directory(DirHandle *dir); @@ -145,13 +145,13 @@ void close_directory(DirHandle *dir); enum { WCTYPE_NONEXISTENT, WCTYPE_FILENAME, WCTYPE_WILDCARD }; -int test_wildcard(char *name, int cmdline); +int test_wildcard(const char *name, int cmdline); /* * Actually return matching file names for a local wildcard. */ typedef struct WildcardMatcher WildcardMatcher; -WildcardMatcher *begin_wildcard_matching(char *name); +WildcardMatcher *begin_wildcard_matching(const char *name); /* The string returned from this will need freeing if not NULL */ char *wildcard_get_filename(WildcardMatcher *dir); void finish_wildcard_matching(WildcardMatcher *dir); @@ -164,17 +164,17 @@ void finish_wildcard_matching(WildcardMatcher *dir); * * Returns TRUE if the filename is kosher, FALSE if dangerous. */ -int vet_filename(char *name); +int vet_filename(const char *name); /* * Create a directory. Returns 0 on error, !=0 on success. */ -int create_directory(char *name); +int create_directory(const char *name); /* * Concatenate a directory name and a file name. The way this is * done will depend on the OS. */ -char *dir_file_cat(char *dir, char *file); +char *dir_file_cat(const char *dir, const char *file); #endif /* PUTTY_PSFTP_H */ diff --git a/putty.h b/putty.h index 60a0b9fc..22ec67b7 100644 --- a/putty.h +++ b/putty.h @@ -139,7 +139,7 @@ typedef struct terminal_tag Terminal; struct sesslist { int nsessions; - char **sessions; + const char **sessions; char *buffer; /* so memory can be freed later */ }; @@ -359,7 +359,7 @@ struct keyvalwhere { * Two fields which define a string and enum value to be * equivalent to each other. */ - char *s; + const char *s; int v; /* @@ -416,13 +416,13 @@ enum { struct backend_tag { const char *(*init) (void *frontend_handle, void **backend_handle, - Conf *conf, char *host, int port, char **realhost, - int nodelay, int keepalive); + Conf *conf, const char *host, int port, + char **realhost, int nodelay, int keepalive); void (*free) (void *handle); /* back->reconfig() passes in a replacement configuration. */ void (*reconfig) (void *handle, Conf *conf); /* back->send() returns the current amount of buffered data. */ - int (*send) (void *handle, char *buf, int len); + int (*send) (void *handle, const char *buf, int len); /* back->sendbuffer() does the same thing but without attempting a send */ int (*sendbuffer) (void *handle); void (*size) (void *handle, int width, int height); @@ -442,7 +442,7 @@ struct backend_tag { */ void (*unthrottle) (void *handle, int); int (*cfg_info) (void *handle); - char *name; + const char *name; int protocol; int default_port; }; @@ -589,10 +589,10 @@ void write_clip(void *frontend, wchar_t *, int *, int, int); void get_clip(void *frontend, wchar_t **, int *); void optimised_move(void *frontend, int, int, int); void set_raw_mouse_mode(void *frontend, int); -void connection_fatal(void *frontend, char *, ...); -void nonfatal(char *, ...); -void fatalbox(char *, ...); -void modalfatalbox(char *, ...); +void connection_fatal(void *frontend, const char *, ...); +void nonfatal(const char *, ...); +void fatalbox(const char *, ...); +void modalfatalbox(const char *, ...); #ifdef macintosh #pragma noreturn(fatalbox) #pragma noreturn(modalfatalbox) @@ -624,7 +624,7 @@ char *get_ttymode(void *frontend, const char *mode); * 0 = `user cancelled' (FIXME distinguish "give up entirely" and "next auth"?) * <0 = `please call back later with more in/inlen' */ -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); #define OPTIMISE_IS_SCROLL 1 void set_iconic(void *frontend, int iconic); @@ -940,12 +940,12 @@ void random_destroy_seed(void); Backend *backend_from_name(const char *name); Backend *backend_from_proto(int proto); char *get_remote_username(Conf *conf); /* dynamically allocated */ -char *save_settings(char *section, Conf *conf); +char *save_settings(const char *section, Conf *conf); void save_open_settings(void *sesskey, Conf *conf); -void load_settings(char *section, Conf *conf); +void load_settings(const char *section, Conf *conf); void load_open_settings(void *sesskey, Conf *conf); void get_sesslist(struct sesslist *, int allocate); -void do_defaults(char *, Conf *); +void do_defaults(const char *, Conf *); void registry_cleanup(void); /* @@ -1003,7 +1003,7 @@ void term_provide_logctx(Terminal *term, void *logctx); void term_set_focus(Terminal *term, int has_focus); char *term_get_ttymode(Terminal *term, const char *mode); int term_get_userpass_input(Terminal *term, prompts_t *p, - unsigned char *in, int inlen); + const unsigned char *in, int inlen); int format_arrow_key(char *buf, Terminal *term, int xkey, int ctrl); @@ -1026,7 +1026,7 @@ struct logblank_t { int type; }; void log_packet(void *logctx, int direction, int type, - char *texttype, const void *data, int len, + const char *texttype, const void *data, int len, int n_blanks, const struct logblank_t *blanks, const unsigned long *sequence, unsigned downstream_id, const char *additional_log_text); @@ -1067,14 +1067,15 @@ extern Backend ssh_backend; void *ldisc_create(Conf *, Terminal *, Backend *, void *, void *); void ldisc_configure(void *, Conf *); void ldisc_free(void *); -void ldisc_send(void *handle, char *buf, int len, int interactive); +void ldisc_send(void *handle, const char *buf, int len, int interactive); void ldisc_echoedit_update(void *handle); /* * Exports from ldiscucs.c. */ -void lpage_send(void *, int codepage, char *buf, int len, int interactive); -void luni_send(void *, wchar_t * widebuf, int len, int interactive); +void lpage_send(void *, int codepage, const char *buf, int len, + int interactive); +void luni_send(void *, const wchar_t * widebuf, int len, int interactive); /* * Exports from sshrand.c. @@ -1128,7 +1129,7 @@ int is_dbcs_leadbyte(int codepage, char byte); int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen, wchar_t *wcstr, int wclen); 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); wchar_t xlat_uskbd2cyrllic(int ch); int check_compose(int first, int second); @@ -1217,7 +1218,8 @@ int askappend(void *frontend, Filename *filename, * that aren't equivalents to things in windlg.c et al. */ extern int console_batch_mode; -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); void console_provide_logctx(void *logctx); int is_interactive(void); @@ -1237,16 +1239,21 @@ void printer_finish_job(printer_job *); * Exports from cmdline.c (and also cmdline_error(), which is * defined differently in various places and required _by_ * cmdline.c). + * + * Note that cmdline_process_param takes a const option string, but a + * writable argument string. That's not a mistake - that's so it can + * zero out password arguments in the hope of not having them show up + * avoidably in Unix 'ps'. */ -int cmdline_process_param(char *, char *, int, Conf *); +int cmdline_process_param(const char *, char *, int, Conf *); void cmdline_run_saved(Conf *); void cmdline_cleanup(void); -int cmdline_get_passwd_input(prompts_t *p, unsigned char *in, int inlen); +int cmdline_get_passwd_input(prompts_t *p, const unsigned char *in, int inlen); #define TOOLTYPE_FILETRANSFER 1 #define TOOLTYPE_NONNETWORK 2 extern int cmdline_tooltype; -void cmdline_error(char *, ...); +void cmdline_error(const char *, ...); /* * Exports from config.c. diff --git a/raw.c b/raw.c index 97355e8a..b083d09d 100644 --- a/raw.c +++ b/raw.c @@ -125,8 +125,8 @@ static void raw_sent(Plug plug, int bufsize) */ static const char *raw_init(void *frontend_handle, void **backend_handle, Conf *conf, - char *host, int port, char **realhost, int nodelay, - int keepalive) + const char *host, int port, char **realhost, + int nodelay, int keepalive) { static const struct plug_function_table fn_table = { raw_log, @@ -214,7 +214,7 @@ static void raw_reconfig(void *handle, Conf *conf) /* * Called to send data down the raw connection. */ -static int raw_send(void *handle, char *buf, int len) +static int raw_send(void *handle, const char *buf, int len) { Raw raw = (Raw) handle; diff --git a/rlogin.c b/rlogin.c index 3c86eee8..10cda463 100644 --- a/rlogin.c +++ b/rlogin.c @@ -161,7 +161,7 @@ static void rlogin_startup(Rlogin rlogin, const char *ruser) */ static const char *rlogin_init(void *frontend_handle, void **backend_handle, Conf *conf, - char *host, int port, char **realhost, + const char *host, int port, char **realhost, int nodelay, int keepalive) { static const struct plug_function_table fn_table = { @@ -279,7 +279,7 @@ static void rlogin_reconfig(void *handle, Conf *conf) /* * Called to send data down the rlogin connection. */ -static int rlogin_send(void *handle, char *buf, int len) +static int rlogin_send(void *handle, const char *buf, int len) { Rlogin rlogin = (Rlogin) handle; diff --git a/settings.c b/settings.c index b3f7a4db..6b770eee 100644 --- a/settings.c +++ b/settings.c @@ -124,13 +124,14 @@ static void gppfile(void *handle, const char *name, Conf *conf, int primary) filename_free(result); } -static int gppi_raw(void *handle, char *name, int def) +static int gppi_raw(void *handle, const char *name, int def) { def = platform_default_i(name, def); return read_setting_i(handle, name, def); } -static void gppi(void *handle, char *name, int def, Conf *conf, int primary) +static void gppi(void *handle, const char *name, int def, + Conf *conf, int primary) { conf_set_int(conf, primary, gppi_raw(handle, name, def)); } @@ -142,7 +143,7 @@ static void gppi(void *handle, char *name, int def, Conf *conf, int primary) * If there's no "=VALUE" (e.g. just NAME,NAME,NAME) then those keys * are mapped to the empty string. */ -static int gppmap(void *handle, char *name, Conf *conf, int primary) +static int gppmap(void *handle, const char *name, Conf *conf, int primary) { char *buf, *p, *q, *key, *val; @@ -212,7 +213,8 @@ static int gppmap(void *handle, char *name, Conf *conf, int primary) static void wmap(void *handle, char const *outkey, Conf *conf, int primary, int include_values) { - char *buf, *p, *q, *key, *realkey, *val; + char *buf, *p, *key, *realkey; + const char *val, *q; int len; len = 1; /* allow for NUL */ @@ -298,7 +300,7 @@ static const char *val2key(const struct keyvalwhere *mapping, * to the end and duplicates are weeded. * XXX: assumes vals in 'mapping' are small +ve integers */ -static void gprefs(void *sesskey, char *name, char *def, +static void gprefs(void *sesskey, const char *name, const char *def, const struct keyvalwhere *mapping, int nvals, Conf *conf, int primary) { @@ -384,7 +386,7 @@ static void gprefs(void *sesskey, char *name, char *def, /* * Write out a preference list. */ -static void wprefs(void *sesskey, char *name, +static void wprefs(void *sesskey, const char *name, const struct keyvalwhere *mapping, int nvals, Conf *conf, int primary) { @@ -418,7 +420,7 @@ static void wprefs(void *sesskey, char *name, sfree(buf); } -char *save_settings(char *section, Conf *conf) +char *save_settings(const char *section, Conf *conf) { void *sesskey; char *errmsg; @@ -434,7 +436,7 @@ char *save_settings(char *section, Conf *conf) void save_open_settings(void *sesskey, Conf *conf) { int i; - char *p; + const char *p; write_setting_i(sesskey, "Present", 1); write_setting_s(sesskey, "HostName", conf_get_str(conf, CONF_host)); @@ -655,7 +657,7 @@ void save_open_settings(void *sesskey, Conf *conf) wmap(sesskey, "SSHManualHostKeys", conf, CONF_ssh_manual_hostkeys, FALSE); } -void load_settings(char *section, Conf *conf) +void load_settings(const char *section, Conf *conf) { void *sesskey; @@ -769,7 +771,7 @@ void load_open_settings(void *sesskey, Conf *conf) * disable gex under the "bugs" panel after one report of * a server which offered it then choked, but we never got * a server version string or any other reports. */ - char *default_kexes; + const char *default_kexes; i = 2 - gppi_raw(sesskey, "BugDHGEx2", 0); if (i == FORCE_ON) default_kexes = "ecdh,dh-group14-sha1,dh-group1-sha1,rsa," @@ -1006,7 +1008,7 @@ void load_open_settings(void *sesskey, Conf *conf) gppmap(sesskey, "SSHManualHostKeys", conf, CONF_ssh_manual_hostkeys); } -void do_defaults(char *session, Conf *conf) +void do_defaults(const char *session, Conf *conf) { load_settings(session, conf); } @@ -1076,7 +1078,7 @@ void get_sesslist(struct sesslist *list, int allocate) p++; } - list->sessions = snewn(list->nsessions + 1, char *); + list->sessions = snewn(list->nsessions + 1, const char *); list->sessions[0] = "Default Settings"; p = list->buffer; i = 1; @@ -1088,7 +1090,7 @@ void get_sesslist(struct sesslist *list, int allocate) p++; } - qsort(list->sessions, i, sizeof(char *), sessioncmp); + qsort(list->sessions, i, sizeof(const char *), sessioncmp); } else { sfree(list->buffer); sfree(list->sessions); diff --git a/sftp.c b/sftp.c index bf75779d..b4421f77 100644 --- a/sftp.c +++ b/sftp.c @@ -23,7 +23,7 @@ struct sftp_packet { static const char *fxp_error_message; static int fxp_errtype; -static void fxp_internal_error(char *msg); +static void fxp_internal_error(const char *msg); /* ---------------------------------------------------------------------- * SFTP packet construction functions. @@ -35,7 +35,8 @@ static void sftp_pkt_ensure(struct sftp_packet *pkt, int length) pkt->data = sresize(pkt->data, pkt->maxlen, char); } } -static void sftp_pkt_adddata(struct sftp_packet *pkt, void *data, int len) +static void sftp_pkt_adddata(struct sftp_packet *pkt, + const void *data, int len) { pkt->length += len; sftp_pkt_ensure(pkt, pkt->length); @@ -82,18 +83,18 @@ static void sftp_pkt_addstring_start(struct sftp_packet *pkt) sftp_pkt_adduint32(pkt, 0); pkt->savedpos = pkt->length; } -static void sftp_pkt_addstring_str(struct sftp_packet *pkt, char *data) +static void sftp_pkt_addstring_str(struct sftp_packet *pkt, const char *data) { sftp_pkt_adddata(pkt, data, strlen(data)); PUT_32BIT(pkt->data + pkt->savedpos - 4, pkt->length - pkt->savedpos); } static void sftp_pkt_addstring_data(struct sftp_packet *pkt, - char *data, int len) + const char *data, int len) { sftp_pkt_adddata(pkt, data, len); PUT_32BIT(pkt->data + pkt->savedpos - 4, pkt->length - pkt->savedpos); } -static void sftp_pkt_addstring(struct sftp_packet *pkt, char *data) +static void sftp_pkt_addstring(struct sftp_packet *pkt, const char *data) { sftp_pkt_addstring_start(pkt); sftp_pkt_addstring_str(pkt, data); @@ -438,7 +439,7 @@ static int fxp_got_status(struct sftp_packet *pktin) return -1; } -static void fxp_internal_error(char *msg) +static void fxp_internal_error(const char *msg) { fxp_error_message = msg; fxp_errtype = -1; @@ -501,7 +502,7 @@ int fxp_init(void) /* * Canonify a pathname. */ -struct sftp_request *fxp_realpath_send(char *path) +struct sftp_request *fxp_realpath_send(const char *path) { struct sftp_request *req = sftp_alloc_request(); struct sftp_packet *pktout; @@ -547,7 +548,7 @@ char *fxp_realpath_recv(struct sftp_packet *pktin, struct sftp_request *req) /* * Open a file. */ -struct sftp_request *fxp_open_send(char *path, int type, +struct sftp_request *fxp_open_send(const char *path, int type, struct fxp_attrs *attrs) { struct sftp_request *req = sftp_alloc_request(); @@ -596,7 +597,7 @@ struct fxp_handle *fxp_open_recv(struct sftp_packet *pktin, /* * Open a directory. */ -struct sftp_request *fxp_opendir_send(char *path) +struct sftp_request *fxp_opendir_send(const char *path) { struct sftp_request *req = sftp_alloc_request(); struct sftp_packet *pktout; @@ -662,7 +663,7 @@ void fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req) sftp_pkt_free(pktin); } -struct sftp_request *fxp_mkdir_send(char *path) +struct sftp_request *fxp_mkdir_send(const char *path) { struct sftp_request *req = sftp_alloc_request(); struct sftp_packet *pktout; @@ -688,7 +689,7 @@ int fxp_mkdir_recv(struct sftp_packet *pktin, struct sftp_request *req) return 1; } -struct sftp_request *fxp_rmdir_send(char *path) +struct sftp_request *fxp_rmdir_send(const char *path) { struct sftp_request *req = sftp_alloc_request(); struct sftp_packet *pktout; @@ -713,7 +714,7 @@ int fxp_rmdir_recv(struct sftp_packet *pktin, struct sftp_request *req) return 1; } -struct sftp_request *fxp_remove_send(char *fname) +struct sftp_request *fxp_remove_send(const char *fname) { struct sftp_request *req = sftp_alloc_request(); struct sftp_packet *pktout; @@ -738,7 +739,8 @@ int fxp_remove_recv(struct sftp_packet *pktin, struct sftp_request *req) return 1; } -struct sftp_request *fxp_rename_send(char *srcfname, char *dstfname) +struct sftp_request *fxp_rename_send(const char *srcfname, + const char *dstfname) { struct sftp_request *req = sftp_alloc_request(); struct sftp_packet *pktout; @@ -768,7 +770,7 @@ int fxp_rename_recv(struct sftp_packet *pktin, struct sftp_request *req) * Retrieve the attributes of a file. We have fxp_stat which works * on filenames, and fxp_fstat which works on open file handles. */ -struct sftp_request *fxp_stat_send(char *fname) +struct sftp_request *fxp_stat_send(const char *fname) { struct sftp_request *req = sftp_alloc_request(); struct sftp_packet *pktout; @@ -836,7 +838,8 @@ int fxp_fstat_recv(struct sftp_packet *pktin, struct sftp_request *req, /* * Set the attributes of a file. */ -struct sftp_request *fxp_setstat_send(char *fname, struct fxp_attrs attrs) +struct sftp_request *fxp_setstat_send(const char *fname, + struct fxp_attrs attrs) { struct sftp_request *req = sftp_alloc_request(); struct sftp_packet *pktout; diff --git a/sftp.h b/sftp.h index c3167a57..c61340c1 100644 --- a/sftp.h +++ b/sftp.h @@ -125,14 +125,14 @@ int fxp_init(void); * Canonify a pathname. Concatenate the two given path elements * with a separating slash, unless the second is NULL. */ -struct sftp_request *fxp_realpath_send(char *path); +struct sftp_request *fxp_realpath_send(const char *path); char *fxp_realpath_recv(struct sftp_packet *pktin, struct sftp_request *req); /* * Open a file. 'attrs' contains attributes to be applied to the file * if it's being created. */ -struct sftp_request *fxp_open_send(char *path, int type, +struct sftp_request *fxp_open_send(const char *path, int type, struct fxp_attrs *attrs); struct fxp_handle *fxp_open_recv(struct sftp_packet *pktin, struct sftp_request *req); @@ -140,7 +140,7 @@ struct fxp_handle *fxp_open_recv(struct sftp_packet *pktin, /* * Open a directory. */ -struct sftp_request *fxp_opendir_send(char *path); +struct sftp_request *fxp_opendir_send(const char *path); struct fxp_handle *fxp_opendir_recv(struct sftp_packet *pktin, struct sftp_request *req); @@ -153,31 +153,32 @@ void fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req); /* * Make a directory. */ -struct sftp_request *fxp_mkdir_send(char *path); +struct sftp_request *fxp_mkdir_send(const char *path); int fxp_mkdir_recv(struct sftp_packet *pktin, struct sftp_request *req); /* * Remove a directory. */ -struct sftp_request *fxp_rmdir_send(char *path); +struct sftp_request *fxp_rmdir_send(const char *path); int fxp_rmdir_recv(struct sftp_packet *pktin, struct sftp_request *req); /* * Remove a file. */ -struct sftp_request *fxp_remove_send(char *fname); +struct sftp_request *fxp_remove_send(const char *fname); int fxp_remove_recv(struct sftp_packet *pktin, struct sftp_request *req); /* * Rename a file. */ -struct sftp_request *fxp_rename_send(char *srcfname, char *dstfname); +struct sftp_request *fxp_rename_send(const char *srcfname, + const char *dstfname); int fxp_rename_recv(struct sftp_packet *pktin, struct sftp_request *req); /* * Return file attributes. */ -struct sftp_request *fxp_stat_send(char *fname); +struct sftp_request *fxp_stat_send(const char *fname); int fxp_stat_recv(struct sftp_packet *pktin, struct sftp_request *req, struct fxp_attrs *attrs); struct sftp_request *fxp_fstat_send(struct fxp_handle *handle); @@ -187,7 +188,8 @@ int fxp_fstat_recv(struct sftp_packet *pktin, struct sftp_request *req, /* * Set file attributes. */ -struct sftp_request *fxp_setstat_send(char *fname, struct fxp_attrs attrs); +struct sftp_request *fxp_setstat_send(const char *fname, + struct fxp_attrs attrs); int fxp_setstat_recv(struct sftp_packet *pktin, struct sftp_request *req); struct sftp_request *fxp_fsetstat_send(struct fxp_handle *handle, struct fxp_attrs attrs); diff --git a/ssh.c b/ssh.c index fd3cdd64..616b87d3 100644 --- a/ssh.c +++ b/ssh.c @@ -189,7 +189,7 @@ static unsigned int ssh_tty_parse_boolean(char *s) #define translate(x) if (type == x) return #x #define translatek(x,ctx) if (type == x && (pkt_kctx == ctx)) return #x #define translatea(x,ctx) if (type == x && (pkt_actx == ctx)) return #x -static char *ssh1_pkt_type(int type) +static const char *ssh1_pkt_type(int type) { translate(SSH1_MSG_DISCONNECT); translate(SSH1_SMSG_PUBLIC_KEY); @@ -234,7 +234,8 @@ static char *ssh1_pkt_type(int type) translate(SSH1_CMSG_AUTH_CCARD_RESPONSE); return "unknown"; } -static char *ssh2_pkt_type(Pkt_KCtx pkt_kctx, Pkt_ACtx pkt_actx, int type) +static const char *ssh2_pkt_type(Pkt_KCtx pkt_kctx, Pkt_ACtx pkt_actx, + int type) { translatea(SSH2_MSG_USERAUTH_GSSAPI_RESPONSE,SSH2_PKTCTX_GSSAPI); translatea(SSH2_MSG_USERAUTH_GSSAPI_TOKEN,SSH2_PKTCTX_GSSAPI); @@ -357,9 +358,9 @@ static void ssh2_pkt_addmp(struct Packet *, Bignum b); static int ssh2_pkt_construct(Ssh, struct Packet *); static void ssh2_pkt_send(Ssh, struct Packet *); static void ssh2_pkt_send_noqueue(Ssh, struct Packet *); -static int do_ssh1_login(Ssh ssh, unsigned char *in, int inlen, +static int do_ssh1_login(Ssh ssh, const unsigned char *in, int inlen, struct Packet *pktin); -static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, +static void do_ssh2_authconn(Ssh ssh, const unsigned char *in, int inlen, struct Packet *pktin); static void ssh2_channel_check_close(struct ssh_channel *c); static void ssh_channel_destroy(struct ssh_channel *c); @@ -686,11 +687,11 @@ struct Packet { const char *additional_log_text; }; -static void ssh1_protocol(Ssh ssh, void *vin, int inlen, +static void ssh1_protocol(Ssh ssh, const void *vin, int inlen, struct Packet *pktin); -static void ssh2_protocol(Ssh ssh, void *vin, int inlen, +static void ssh2_protocol(Ssh ssh, const void *vin, int inlen, struct Packet *pktin); -static void ssh2_bare_connection_protocol(Ssh ssh, void *vin, int inlen, +static void ssh2_bare_connection_protocol(Ssh ssh, const void *vin, int inlen, struct Packet *pktin); static void ssh1_protocol_setup(Ssh ssh); static void ssh2_protocol_setup(Ssh ssh); @@ -698,7 +699,8 @@ static void ssh2_bare_connection_protocol_setup(Ssh ssh); static void ssh_size(void *handle, int width, int height); static void ssh_special(void *handle, Telnet_Special); static int ssh2_try_send(struct ssh_channel *c); -static void ssh2_add_channel_data(struct ssh_channel *c, char *buf, int len); +static void ssh2_add_channel_data(struct ssh_channel *c, + const char *buf, int len); static void ssh_throttle_all(Ssh ssh, int enable, int bufsize); static void ssh2_set_window(struct ssh_channel *c, int newwin); static int ssh_sendbuffer(void *handle); @@ -707,7 +709,7 @@ static unsigned long ssh_pkt_getuint32(struct Packet *pkt); static int ssh2_pkt_getbool(struct Packet *pkt); static void ssh_pkt_getstring(struct Packet *pkt, char **p, int *length); static void ssh2_timer(void *ctx, unsigned long now); -static void do_ssh2_transport(Ssh ssh, void *vin, int inlen, +static void do_ssh2_transport(Ssh ssh, const void *vin, int inlen, struct Packet *pktin); static void ssh2_msg_unexpected(Ssh ssh, struct Packet *pktin); @@ -864,9 +866,10 @@ struct ssh_tag { /* SSH-1 and SSH-2 use this for different things, but both use it */ int protocol_initial_phase_done; - void (*protocol) (Ssh ssh, void *vin, int inlen, + void (*protocol) (Ssh ssh, const void *vin, int inlen, struct Packet *pkt); - struct Packet *(*s_rdpkt) (Ssh ssh, unsigned char **data, int *datalen); + struct Packet *(*s_rdpkt) (Ssh ssh, const unsigned char **data, + int *datalen); int (*do_ssh_init)(Ssh ssh, unsigned char c); /* @@ -936,7 +939,7 @@ struct ssh_tag { unsigned long max_data_size; int kex_in_progress; unsigned long next_rekey, last_rekey; - char *deferred_rekey_reason; /* points to STATIC string; don't free */ + const char *deferred_rekey_reason; /* * Fully qualified host name, which we need if doing GSSAPI. @@ -1294,7 +1297,8 @@ static void ssh1_log_outgoing_packet(Ssh ssh, struct Packet *pkt) * Update the *data and *datalen variables. * Return a Packet structure when a packet is completed. */ -static struct Packet *ssh1_rdpkt(Ssh ssh, unsigned char **data, int *datalen) +static struct Packet *ssh1_rdpkt(Ssh ssh, const unsigned char **data, + int *datalen) { struct rdpkt1_state_tag *st = &ssh->rdpkt1_state; @@ -1549,7 +1553,8 @@ static void ssh2_log_outgoing_packet(Ssh ssh, struct Packet *pkt) pkt->length += (pkt->body - pkt->data); } -static struct Packet *ssh2_rdpkt(Ssh ssh, unsigned char **data, int *datalen) +static struct Packet *ssh2_rdpkt(Ssh ssh, const unsigned char **data, + int *datalen) { struct rdpkt2_state_tag *st = &ssh->rdpkt2_state; @@ -1837,7 +1842,8 @@ static struct Packet *ssh2_rdpkt(Ssh ssh, unsigned char **data, int *datalen) crFinish(st->pktin); } -static struct Packet *ssh2_bare_connection_rdpkt(Ssh ssh, unsigned char **data, +static struct Packet *ssh2_bare_connection_rdpkt(Ssh ssh, + const unsigned char **data, int *datalen) { struct rdpkt2_bare_state_tag *st = &ssh->rdpkt2_bare_state; @@ -2050,7 +2056,7 @@ static void defer_packet(Ssh ssh, int pkttype, ...) s_wrpkt_defer(ssh, pkt); } -static int ssh_versioncmp(char *a, char *b) +static int ssh_versioncmp(const char *a, const char *b) { char *ae, *be; unsigned long av, bv; @@ -3243,7 +3249,7 @@ static int do_ssh_connection_init(Ssh ssh, unsigned char c) } static void ssh_process_incoming_data(Ssh ssh, - unsigned char **data, int *datalen) + const unsigned char **data, int *datalen) { struct Packet *pktin; @@ -3255,7 +3261,7 @@ static void ssh_process_incoming_data(Ssh ssh, } static void ssh_queue_incoming_data(Ssh ssh, - unsigned char **data, int *datalen) + const unsigned char **data, int *datalen) { bufchain_add(&ssh->queued_incoming_data, *data, *datalen); *data += *datalen; @@ -3265,7 +3271,7 @@ static void ssh_queue_incoming_data(Ssh ssh, static void ssh_process_queued_incoming_data(Ssh ssh) { void *vdata; - unsigned char *data; + const unsigned char *data; int len, origlen; while (!ssh->frozen && bufchain_size(&ssh->queued_incoming_data)) { @@ -3288,7 +3294,7 @@ static void ssh_set_frozen(Ssh ssh, int frozen) ssh->frozen = frozen; } -static void ssh_gotdata(Ssh ssh, unsigned char *data, int datalen) +static void ssh_gotdata(Ssh ssh, const unsigned char *data, int datalen) { /* Log raw data, if we're in that mode. */ if (ssh->logctx) @@ -3533,7 +3539,7 @@ static void ssh_sent(Plug plug, int bufsize) * Also places the canonical host name into `realhost'. It must be * freed by the caller. */ -static const char *connect_to_host(Ssh ssh, char *host, int port, +static const char *connect_to_host(Ssh ssh, const char *host, int port, char **realhost, int nodelay, int keepalive) { static const struct plug_function_table fn_table = { @@ -3740,7 +3746,7 @@ static void ssh_agentf_callback(void *cv, void *reply, int replylen) { struct ssh_channel *c = (struct ssh_channel *)cv; Ssh ssh = c->ssh; - void *sentreply = reply; + const void *sentreply = reply; c->u.a.outstanding_requests--; if (!sentreply) { @@ -3773,7 +3779,8 @@ static void ssh_agentf_callback(void *cv, void *reply, int replylen) * non-NULL, otherwise just close the connection. `client_reason' == NULL * => log `wire_reason'. */ -static void ssh_disconnect(Ssh ssh, char *client_reason, char *wire_reason, +static void ssh_disconnect(Ssh ssh, const char *client_reason, + const char *wire_reason, int code, int clean_exit) { char *error; @@ -3857,7 +3864,7 @@ int verify_ssh_manual_host_key(Ssh ssh, const char *fingerprint, /* * Handle the key exchange and user authentication phases. */ -static int do_ssh1_login(Ssh ssh, unsigned char *in, int inlen, +static int do_ssh1_login(Ssh ssh, const unsigned char *in, int inlen, struct Packet *pktin) { int i, j, ret; @@ -4038,7 +4045,7 @@ static int do_ssh1_login(Ssh ssh, unsigned char *in, int inlen, { int cipher_chosen = 0, warn = 0; - char *cipher_string = NULL; + const char *cipher_string = NULL; int i; for (i = 0; !cipher_chosen && i < CIPHER_MAX; i++) { int next_cipher = conf_get_int_int(ssh->conf, @@ -5773,7 +5780,7 @@ int ssh_agent_forwarding_permitted(Ssh ssh) return conf_get_int(ssh->conf, CONF_agentfwd) && agent_exists(); } -static void do_ssh1_connection(Ssh ssh, unsigned char *in, int inlen, +static void do_ssh1_connection(Ssh ssh, const unsigned char *in, int inlen, struct Packet *pktin) { crBegin(ssh->do_ssh1_connection_crstate); @@ -6028,10 +6035,10 @@ static void ssh1_protocol_setup(Ssh ssh) ssh->packet_dispatch[SSH1_MSG_DEBUG] = ssh1_msg_debug; } -static void ssh1_protocol(Ssh ssh, void *vin, int inlen, +static void ssh1_protocol(Ssh ssh, const void *vin, int inlen, struct Packet *pktin) { - unsigned char *in=(unsigned char*)vin; + const unsigned char *in = (const unsigned char *)vin; if (ssh->state == SSH_STATE_CLOSED) return; @@ -6149,10 +6156,10 @@ static void ssh2_mkkey(Ssh ssh, Bignum K, unsigned char *H, char chr, /* * Handle the SSH-2 transport layer. */ -static void do_ssh2_transport(Ssh ssh, void *vin, int inlen, +static void do_ssh2_transport(Ssh ssh, const void *vin, int inlen, struct Packet *pktin) { - unsigned char *in = (unsigned char *)vin; + const unsigned char *in = (const unsigned char *)vin; struct do_ssh2_transport_state { int crLine; int nbits, pbits, warn_kex, warn_cscipher, warn_sccipher; @@ -6405,7 +6412,8 @@ static void do_ssh2_transport(Ssh ssh, void *vin, int inlen, * to. */ { - char *str, *preferred; + char *str; + const char *preferred; int i, j, len; if (pktin->type != SSH2_MSG_KEXINIT) { @@ -7354,7 +7362,7 @@ static void do_ssh2_transport(Ssh ssh, void *vin, int inlen, /* * Add data to an SSH-2 channel output buffer. */ -static void ssh2_add_channel_data(struct ssh_channel *c, char *buf, +static void ssh2_add_channel_data(struct ssh_channel *c, const char *buf, int len) { bufchain_add(&c->v.v2.outbuffer, buf, len); @@ -7461,7 +7469,8 @@ static void ssh2_channel_init(struct ssh_channel *c) /* * Construct the common parts of a CHANNEL_OPEN. */ -static struct Packet *ssh2_chanopen_init(struct ssh_channel *c, char *type) +static struct Packet *ssh2_chanopen_init(struct ssh_channel *c, + const char *type) { struct Packet *pktout; @@ -7508,7 +7517,8 @@ static void ssh2_queue_chanreq_handler(struct ssh_channel *c, * the server initiated channel closure before we saw the response) * and the handler should free any storage it's holding. */ -static struct Packet *ssh2_chanreq_init(struct ssh_channel *c, char *type, +static struct Packet *ssh2_chanreq_init(struct ssh_channel *c, + const char *type, cchandler_fn_t handler, void *ctx) { struct Packet *pktout; @@ -8218,7 +8228,7 @@ static void ssh2_msg_channel_request(Ssh ssh, struct Packet *pktin) !memcmp(type, "exit-signal", 11)) { int is_plausible = TRUE, is_int = FALSE; - char *fmt_sig = "", *fmt_msg = ""; + char *fmt_sig = NULL, *fmt_msg = NULL; char *msg; int msglen = 0, core = FALSE; /* ICK: older versions of OpenSSH (e.g. 3.4p1) @@ -8341,10 +8351,11 @@ static void ssh2_msg_channel_request(Ssh ssh, struct Packet *pktin) /* ignore lang tag */ } /* else don't attempt to parse */ logeventf(ssh, "Server exited on signal%s%s%s", - fmt_sig, core ? " (core dumped)" : "", - fmt_msg); - if (*fmt_sig) sfree(fmt_sig); - if (*fmt_msg) sfree(fmt_msg); + fmt_sig ? fmt_sig : "", + core ? " (core dumped)" : "", + fmt_msg ? fmt_msg : ""); + sfree(fmt_sig); + sfree(fmt_msg); reply = SSH2_MSG_CHANNEL_SUCCESS; } @@ -8416,7 +8427,7 @@ static void ssh2_msg_channel_open(Ssh ssh, struct Packet *pktin) char *peeraddr; int peeraddrlen; int peerport; - char *error = NULL; + const char *error = NULL; struct ssh_channel *c; unsigned remid, winsize, pktsize; unsigned our_winsize_override = 0; @@ -8829,7 +8840,7 @@ static void ssh2_response_authconn(struct ssh_channel *c, struct Packet *pktin, do_ssh2_authconn(c->ssh, NULL, 0, pktin); } -static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, +static void do_ssh2_authconn(Ssh ssh, const unsigned char *in, int inlen, struct Packet *pktin) { struct do_ssh2_authconn_state { @@ -10116,7 +10127,7 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int prompt_len; /* not live over crReturn */ { - char *msg; + const char *msg; if (changereq_first_time) msg = "Server requested password change"; else @@ -10740,10 +10751,10 @@ static void ssh2_timer(void *ctx, unsigned long now) } } -static void ssh2_protocol(Ssh ssh, void *vin, int inlen, +static void ssh2_protocol(Ssh ssh, const void *vin, int inlen, struct Packet *pktin) { - unsigned char *in = (unsigned char *)vin; + const unsigned char *in = (const unsigned char *)vin; if (ssh->state == SSH_STATE_CLOSED) return; @@ -10763,10 +10774,10 @@ static void ssh2_protocol(Ssh ssh, void *vin, int inlen, do_ssh2_authconn(ssh, in, inlen, pktin); } -static void ssh2_bare_connection_protocol(Ssh ssh, void *vin, int inlen, +static void ssh2_bare_connection_protocol(Ssh ssh, const void *vin, int inlen, struct Packet *pktin) { - unsigned char *in = (unsigned char *)vin; + const unsigned char *in = (const unsigned char *)vin; if (ssh->state == SSH_STATE_CLOSED) return; @@ -10787,7 +10798,8 @@ static void ssh_cache_conf_values(Ssh ssh) * Returns an error message, or NULL on success. */ static const char *ssh_init(void *frontend_handle, void **backend_handle, - Conf *conf, char *host, int port, char **realhost, + Conf *conf, + const char *host, int port, char **realhost, int nodelay, int keepalive) { const char *p; @@ -11039,7 +11051,8 @@ static void ssh_free(void *handle) static void ssh_reconfig(void *handle, Conf *conf) { Ssh ssh = (Ssh) handle; - char *rekeying = NULL, rekey_mandatory = FALSE; + const char *rekeying = NULL; + int rekey_mandatory = FALSE; unsigned long old_max_data_size; int i, rekey_time; @@ -11104,14 +11117,14 @@ static void ssh_reconfig(void *handle, Conf *conf) /* * Called to send data down the SSH connection. */ -static int ssh_send(void *handle, char *buf, int len) +static int ssh_send(void *handle, const char *buf, int len) { Ssh ssh = (Ssh) handle; if (ssh == NULL || ssh->s == NULL || ssh->protocol == NULL) return 0; - ssh->protocol(ssh, (unsigned char *)buf, len, 0); + ssh->protocol(ssh, (const unsigned char *)buf, len, 0); return ssh_sendbuffer(ssh); } @@ -11319,7 +11332,7 @@ static void ssh_special(void *handle, Telnet_Special code) } } else { /* Is is a POSIX signal? */ - char *signame = NULL; + const char *signame = NULL; if (code == TS_SIGABRT) signame = "ABRT"; if (code == TS_SIGALRM) signame = "ALRM"; if (code == TS_SIGFPE) signame = "FPE"; @@ -11436,7 +11449,8 @@ static void ssh_unthrottle(void *handle, int bufsize) ssh_process_queued_incoming_data(ssh); } -void ssh_send_port_open(void *channel, char *hostname, int port, char *org) +void ssh_send_port_open(void *channel, const char *hostname, int port, + const char *org) { struct ssh_channel *c = (struct ssh_channel *)channel; Ssh ssh = c->ssh; diff --git a/ssh.h b/ssh.h index 4fc4edea..0b6b4f8e 100644 --- a/ssh.h +++ b/ssh.h @@ -304,7 +304,7 @@ struct ssh2_cipher { void (*setkey) (void *, unsigned char *key);/* for SSH-2 */ void (*encrypt) (void *, unsigned char *blk, int len); void (*decrypt) (void *, unsigned char *blk, int len); - char *name; + const char *name; int blksize; int keylen; unsigned int flags; @@ -343,7 +343,7 @@ struct ssh_hash { }; struct ssh_kex { - char *name, *groupname; + const char *name, *groupname; enum { KEXTYPE_DH, KEXTYPE_RSA, KEXTYPE_ECDH } main_type; const struct ssh_hash *hash; const void *extra; /* private to the kex methods */ @@ -388,10 +388,10 @@ struct ssh_signkey { }; struct ssh_compress { - char *name; + const char *name; /* For zlib@openssh.com: if non-NULL, this name will be considered once * userauth has completed successfully. */ - char *delayed_name; + const char *delayed_name; void *(*compress_init) (void); void (*compress_cleanup) (void *); int (*compress) (void *, unsigned char *block, int len, @@ -478,7 +478,8 @@ struct PortForwarding; /* Allocate and register a new channel for port forwarding */ void *new_sock_channel(void *handle, struct PortForwarding *pf); -void ssh_send_port_open(void *channel, char *hostname, int port, char *org); +void ssh_send_port_open(void *channel, const char *hostname, int port, + const char *org); /* Exports from portfwd.c */ extern char *pfd_connect(struct PortForwarding **pf, char *hostname, int port, @@ -729,7 +730,7 @@ void ssh2_write_pubkey(FILE *fp, const char *comment, char *ssh2_fingerprint_blob(const void *blob, int bloblen); char *ssh2_fingerprint(const struct ssh_signkey *alg, void *data); int key_type(const Filename *filename); -char *key_type_to_str(int type); +const char *key_type_to_str(int type); int import_possible(int type); int import_target_type(int type); diff --git a/sshbn.c b/sshbn.c index 0d64620d..a35bf314 100644 --- a/sshbn.c +++ b/sshbn.c @@ -1970,7 +1970,7 @@ char *bignum_decimal(Bignum x) * testdata/bignum.py . */ -void modalfatalbox(char *p, ...) +void modalfatalbox(const char *p, ...) { va_list ap; fprintf(stderr, "FATAL ERROR: "); diff --git a/sshpubk.c b/sshpubk.c index 30f9e4b3..0323335e 100644 --- a/sshpubk.c +++ b/sshpubk.c @@ -1308,7 +1308,7 @@ int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key, int passlen; int cipherblk; int i; - char *cipherstr; + const char *cipherstr; unsigned char priv_mac[20]; /* @@ -1688,7 +1688,7 @@ int key_type(const Filename *filename) * Convert the type word to a string, for `wrong type' error * messages. */ -char *key_type_to_str(int type) +const char *key_type_to_str(int type) { switch (type) { case SSH_KEYTYPE_UNOPENABLE: return "unable to open file"; break; diff --git a/telnet.c b/telnet.c index 8717a972..ca166525 100644 --- a/telnet.c +++ b/telnet.c @@ -113,7 +113,7 @@ enum { TELOPTS(telnet_enum) dummy=0 }; ( (x) != IAC && \ (telnet->opt_states[o_we_bin.index] == ACTIVE || (x) != CR)) -static char *telopt(int opt) +static const char *telopt(int opt) { #define telnet_str(x,y) case TELOPT_##x: return #x; switch (opt) { @@ -212,14 +212,14 @@ typedef struct telnet_tag { #define SB_DELTA 1024 -static void c_write(Telnet telnet, char *buf, int len) +static void c_write(Telnet telnet, const char *buf, int len) { int backlog; backlog = from_backend(telnet->frontend, 0, buf, len); sk_set_frozen(telnet->s, backlog > TELNET_MAX_BACKLOG); } -static void log_option(Telnet telnet, char *sender, int cmd, int option) +static void log_option(Telnet telnet, const char *sender, int cmd, int option) { char *buf; /* @@ -715,7 +715,7 @@ static void telnet_sent(Plug plug, int bufsize) * freed by the caller. */ static const char *telnet_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) { static const struct plug_function_table fn_table = { @@ -855,7 +855,7 @@ static void telnet_reconfig(void *handle, Conf *conf) /* * Called to send data down the Telnet connection. */ -static int telnet_send(void *handle, char *buf, int len) +static int telnet_send(void *handle, const char *buf, int len) { Telnet telnet = (Telnet) handle; unsigned char *p, *end; diff --git a/terminal.c b/terminal.c index d4808e7f..dc727238 100644 --- a/terminal.c +++ b/terminal.c @@ -65,7 +65,7 @@ #define has_compat(x) ( ((CL_##x)&term->compatibility_level) != 0 ) -char *EMPTY_WINDOW_TITLE = ""; +const char *EMPTY_WINDOW_TITLE = ""; const char sco2ansicolour[] = { 0, 4, 2, 6, 1, 5, 3, 7 }; @@ -3940,7 +3940,8 @@ static void term_out(Terminal *term) switch (term->esc_args[0]) { int x, y, len; - char buf[80], *p; + char buf[80]; + const char *p; case 1: set_iconic(term->frontend, FALSE); break; @@ -6319,7 +6320,7 @@ void term_set_focus(Terminal *term, int has_focus) */ char *term_get_ttymode(Terminal *term, const char *mode) { - char *val = NULL; + const char *val = NULL; if (strcmp(mode, "ERASE") == 0) { val = term->bksp_is_delete ? "^?" : "^H"; } @@ -6339,7 +6340,7 @@ struct term_userpass_state { * input. */ int term_get_userpass_input(Terminal *term, prompts_t *p, - unsigned char *in, int inlen) + const unsigned char *in, int inlen) { struct term_userpass_state *s = (struct term_userpass_state *)p->data; if (!s) { diff --git a/unix/gtkask.c b/unix/gtkask.c index 7d0f13cf..0f62e9b8 100644 --- a/unix/gtkask.c +++ b/unix/gtkask.c @@ -342,7 +342,7 @@ char *gtk_askpass_main(const char *display, const char *wintitle, } #ifdef TEST_ASKPASS -void modalfatalbox(char *p, ...) +void modalfatalbox(const char *p, ...) { va_list ap; fprintf(stderr, "FATAL ERROR: "); diff --git a/unix/gtkdlg.c b/unix/gtkdlg.c index 8007b75c..6c532024 100644 --- a/unix/gtkdlg.c +++ b/unix/gtkdlg.c @@ -1055,7 +1055,7 @@ static void set_transient_window_pos(GtkWidget *parent, GtkWidget *child) gtk_widget_set_uposition(GTK_WIDGET(child), dx, dy); } -void dlg_error_msg(void *dlg, char *msg) +void dlg_error_msg(void *dlg, const char *msg) { struct dlgparam *dp = (struct dlgparam *)dlg; GtkWidget *window, *hbox, *text, *ok; @@ -1998,7 +1998,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs, { GtkWidget *ww; GtkRequisition req; - char *browsebtn = + const char *browsebtn = (ctrl->generic.type == CTRL_FILESELECT ? "Browse..." : "Change..."); @@ -3138,7 +3138,8 @@ static void messagebox_handler(union control *ctrl, void *dlg, if (event == EVENT_ACTION) dlg_end(dlg, ctrl->generic.context.i); } -int messagebox(GtkWidget *parentwin, char *title, char *msg, int minwid, ...) +int messagebox(GtkWidget *parentwin, const char *title, const char *msg, + int minwid, ...) { GtkWidget *window, *w0, *w1; struct controlbox *ctrlbox; @@ -3235,7 +3236,7 @@ int messagebox(GtkWidget *parentwin, char *title, char *msg, int minwid, ...) return dp.retval; } -int string_width(char *text) +int string_width(const char *text) { GtkWidget *label = gtk_label_new(text); GtkRequisition req; @@ -3355,21 +3356,21 @@ void old_keyfile_warning(void) */ } -void fatal_message_box(void *window, char *msg) +void fatal_message_box(void *window, const char *msg) { messagebox(window, "PuTTY Fatal Error", msg, string_width("REASONABLY LONG LINE OF TEXT FOR BASIC SANITY"), "OK", 'o', 1, 1, NULL); } -void nonfatal_message_box(void *window, char *msg) +void nonfatal_message_box(void *window, const char *msg) { messagebox(window, "PuTTY Error", msg, string_width("REASONABLY LONG LINE OF TEXT FOR BASIC SANITY"), "OK", 'o', 1, 1, NULL); } -void fatalbox(char *p, ...) +void fatalbox(const char *p, ...) { va_list ap; char *msg; @@ -3381,7 +3382,7 @@ void fatalbox(char *p, ...) cleanup_exit(1); } -void nonfatal(char *p, ...) +void nonfatal(const char *p, ...) { va_list ap; char *msg; @@ -3404,7 +3405,7 @@ static void licence_clicked(GtkButton *button, gpointer data) { char *title; - char *licence = + const char *licence = "Copyright 1997-2015 Simon Tatham.\n\n" "Portions copyright Robert de Bath, Joris van Rantwijk, Delian " diff --git a/unix/gtkfont.c b/unix/gtkfont.c index d241db0e..d776dfa5 100644 --- a/unix/gtkfont.c +++ b/unix/gtkfont.c @@ -175,7 +175,7 @@ static char *x11_guess_derived_font_name(XFontStruct *xfs, int bold, int wide) if (XGetFontProperty(xfs, fontprop, &ret)) { char *name = XGetAtomName(disp, (Atom)ret); if (name && name[0] == '-') { - char *strings[13]; + const char *strings[13]; char *dupname, *extrafree = NULL, *ret; char *p, *q; int nstr; diff --git a/unix/gtkwin.c b/unix/gtkwin.c index f3a17d58..e8345881 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -133,7 +133,7 @@ struct draw_ctx { static int send_raw_mouse; -static char *app_name = "pterm"; +static const char *app_name = "pterm"; static void start_backend(struct gui_data *inst); static void exit_callback(void *vinst); @@ -143,7 +143,7 @@ char *x_get_default(const char *key) return XGetDefault(GDK_DISPLAY(), app_name, key); } -void connection_fatal(void *frontend, char *p, ...) +void connection_fatal(void *frontend, const char *p, ...) { struct gui_data *inst = (struct gui_data *)frontend; @@ -221,7 +221,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) { struct gui_data *inst = (struct gui_data *)p->frontend; int ret; @@ -885,7 +885,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) * NetHack keypad mode. */ if (nethack_mode) { - char *keys = NULL; + const char *keys = NULL; switch (event->keyval) { case GDK_KP_1: case GDK_KP_End: keys = "bB\002"; break; case GDK_KP_2: case GDK_KP_Down: keys = "jJ\012"; break; @@ -2603,7 +2603,7 @@ GdkCursor *make_mouse_ptr(struct gui_data *inst, int cursor_val) return ret; } -void modalfatalbox(char *p, ...) +void modalfatalbox(const char *p, ...) { va_list ap; fprintf(stderr, "FATAL ERROR: "); @@ -2614,7 +2614,7 @@ void modalfatalbox(char *p, ...) exit(1); } -void cmdline_error(char *p, ...) +void cmdline_error(const char *p, ...) { va_list ap; fprintf(stderr, "%s: ", appname); @@ -2695,7 +2695,7 @@ int do_cmdline(int argc, char **argv, int do_everything, int *allow_launch, #define SECOND_PASS_ONLY { if (!do_everything) continue; } while (--argc > 0) { - char *p = *++argv; + const char *p = *++argv; int ret; /* diff --git a/unix/unix.h b/unix/unix.h index 79a9fb3c..aba8a2bd 100644 --- a/unix/unix.h +++ b/unix/unix.h @@ -84,21 +84,22 @@ void *get_window(void *frontend); /* void * to avoid depending on gtk.h */ /* Things pterm.c needs from gtkdlg.c */ int do_config_box(const char *title, Conf *conf, int midsession, int protcfginfo); -void fatal_message_box(void *window, char *msg); -void nonfatal_message_box(void *window, char *msg); +void fatal_message_box(void *window, const char *msg); +void nonfatal_message_box(void *window, const char *msg); void about_box(void *window); void *eventlogstuff_new(void); void showeventlog(void *estuff, void *parentwin); void logevent_dlg(void *estuff, const char *string); int reallyclose(void *frontend); #ifdef MAY_REFER_TO_GTK_IN_HEADERS -int messagebox(GtkWidget *parentwin, char *title, char *msg, int minwid, ...); -int string_width(char *text); +int messagebox(GtkWidget *parentwin, const char *title, + const char *msg, int minwid, ...); +int string_width(const char *text); #endif /* Things pterm.c needs from {ptermm,uxputty}.c */ char *make_default_wintitle(char *hostname); -int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch); +int process_nonoption_arg(const char *arg, Conf *conf, int *allow_launch); /* pterm.c needs this special function in xkeysym.c */ int keysym_to_unicode(int keysym); diff --git a/unix/uxcons.c b/unix/uxcons.c index ea6297c4..eabb7769 100644 --- a/unix/uxcons.c +++ b/unix/uxcons.c @@ -364,7 +364,8 @@ static void console_prompt_text(FILE *outfp, const char *data, int len) fflush(outfp); } -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) { size_t curr_prompt; FILE *outfp = NULL; diff --git a/unix/uxmisc.c b/unix/uxmisc.c index 95133a03..e2c2de32 100644 --- a/unix/uxmisc.c +++ b/unix/uxmisc.c @@ -98,7 +98,7 @@ Filename *filename_deserialise(void *vdata, int maxsize, int *used) #ifdef DEBUG static FILE *debug_fp = NULL; -void dputs(char *buf) +void dputs(const char *buf) { if (!debug_fp) { debug_fp = fopen("debug.log", "w"); diff --git a/unix/uxnet.c b/unix/uxnet.c index 235d6fd9..e409315a 100644 --- a/unix/uxnet.c +++ b/unix/uxnet.c @@ -776,7 +776,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) { int s; #ifndef NO_IPV6 diff --git a/unix/uxpgnt.c b/unix/uxpgnt.c index bf737772..95646b3e 100644 --- a/unix/uxpgnt.c +++ b/unix/uxpgnt.c @@ -23,7 +23,7 @@ SockAddr unix_sock_addr(const char *path); Socket new_unix_listener(SockAddr listenaddr, Plug plug); -void fatalbox(char *p, ...) +void fatalbox(const char *p, ...) { va_list ap; fprintf(stderr, "FATAL ERROR: "); @@ -33,7 +33,7 @@ void fatalbox(char *p, ...) fputc('\n', stderr); exit(1); } -void modalfatalbox(char *p, ...) +void modalfatalbox(const char *p, ...) { va_list ap; fprintf(stderr, "FATAL ERROR: "); @@ -43,7 +43,7 @@ void modalfatalbox(char *p, ...) fputc('\n', stderr); exit(1); } -void nonfatal(char *p, ...) +void nonfatal(const char *p, ...) { va_list ap; fprintf(stderr, "ERROR: "); @@ -52,7 +52,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: "); @@ -62,7 +62,7 @@ void connection_fatal(void *frontend, char *p, ...) fputc('\n', stderr); exit(1); } -void cmdline_error(char *p, ...) +void cmdline_error(const char *p, ...) { va_list ap; fprintf(stderr, "pageant: "); diff --git a/unix/uxplink.c b/unix/uxplink.c index 3e32925c..64c3cabc 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -29,7 +29,7 @@ void *logctx; static struct termios orig_termios; -void fatalbox(char *p, ...) +void fatalbox(const char *p, ...) { struct termios cf; va_list ap; @@ -46,7 +46,7 @@ void fatalbox(char *p, ...) } cleanup_exit(1); } -void modalfatalbox(char *p, ...) +void modalfatalbox(const char *p, ...) { struct termios cf; va_list ap; @@ -63,7 +63,7 @@ void modalfatalbox(char *p, ...) } cleanup_exit(1); } -void nonfatal(char *p, ...) +void nonfatal(const char *p, ...) { struct termios cf; va_list ap; @@ -75,7 +75,7 @@ void nonfatal(char *p, ...) fputc('\n', stderr); postmsg(&cf); } -void connection_fatal(void *frontend, char *p, ...) +void connection_fatal(void *frontend, const char *p, ...) { struct termios cf; va_list ap; @@ -92,7 +92,7 @@ void connection_fatal(void *frontend, char *p, ...) } cleanup_exit(1); } -void cmdline_error(char *p, ...) +void cmdline_error(const char *p, ...) { struct termios cf; va_list ap; @@ -446,7 +446,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); diff --git a/unix/uxproxy.c b/unix/uxproxy.c index dfbcc86a..f230604a 100644 --- a/unix/uxproxy.c +++ b/unix/uxproxy.c @@ -230,7 +230,7 @@ static int localproxy_select_result(int fd, int event) return 1; } -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) diff --git a/unix/uxpterm.c b/unix/uxpterm.c index 1f4f20c2..3211d45a 100644 --- a/unix/uxpterm.c +++ b/unix/uxpterm.c @@ -33,7 +33,7 @@ void cleanup_exit(int code) exit(code); } -int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch) +int process_nonoption_arg(const char *arg, Conf *conf, int *allow_launch) { return 0; /* pterm doesn't have any. */ } diff --git a/unix/uxpty.c b/unix/uxpty.c index 54ba082c..84f36ef8 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -706,8 +706,8 @@ static void pty_uxsel_setup(Pty pty) * freed by the caller. */ static const char *pty_init(void *frontend, void **backend_handle, Conf *conf, - char *host, int port, char **realhost, int nodelay, - int keepalive) + const char *host, int port, char **realhost, + int nodelay, int keepalive) { int slavefd; pid_t pid, pgrp; @@ -1008,7 +1008,7 @@ static void pty_try_write(Pty pty) /* * Called to send data down the pty. */ -static int pty_send(void *handle, char *buf, int len) +static int pty_send(void *handle, const char *buf, int len) { Pty pty = (Pty)handle; diff --git a/unix/uxputty.c b/unix/uxputty.c index c7b0fcb2..f0b4bfbd 100644 --- a/unix/uxputty.c +++ b/unix/uxputty.c @@ -50,9 +50,11 @@ static int got_host = 0; const int use_event_log = 1, new_session = 1, saved_sessions = 1; -int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch) +int process_nonoption_arg(const char *arg, Conf *conf, int *allow_launch) { - char *p, *q = arg; + char *argdup, *p, *q; + argdup = dupstr(arg); + q = argdup; if (got_host) { /* @@ -61,7 +63,7 @@ int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch) * argument, so that it will be deferred until it's a good * moment to run it. */ - int ret = cmdline_process_param("-P", arg, 1, conf); + int ret = cmdline_process_param("-P", argdup, 1, conf); assert(ret == 2); } else if (!strncmp(q, "telnet:", 7)) { /* @@ -90,7 +92,7 @@ int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch) /* * Otherwise, treat this argument as a host name. */ - p = arg; + p = argdup; while (*p && !isspace((unsigned char)*p)) p++; if (*p) @@ -100,6 +102,9 @@ int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch) } if (got_host) *allow_launch = TRUE; + + sfree(argdup); + return 1; } diff --git a/unix/uxser.c b/unix/uxser.c index e45f3ae1..691e527e 100644 --- a/unix/uxser.c +++ b/unix/uxser.c @@ -289,8 +289,8 @@ static const char *serial_configure(Serial serial, Conf *conf) */ static const char *serial_init(void *frontend_handle, void **backend_handle, Conf *conf, - char *host, int port, char **realhost, int nodelay, - int keepalive) + const char *host, int port, char **realhost, + int nodelay, int keepalive) { Serial serial; const char *err; @@ -462,7 +462,7 @@ static void serial_try_write(Serial serial) /* * 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; diff --git a/unix/uxsftp.c b/unix/uxsftp.c index 391da021..21d7f40f 100644 --- a/unix/uxsftp.c +++ b/unix/uxsftp.c @@ -68,7 +68,7 @@ Filename *platform_default_filename(const char *name) 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); @@ -120,7 +120,7 @@ struct RFile { int fd; }; -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) { @@ -174,7 +174,7 @@ struct WFile { char *name; }; -WFile *open_new_file(char *name, long perms) +WFile *open_new_file(const char *name, long perms) { int fd; WFile *ret; @@ -192,7 +192,7 @@ WFile *open_new_file(char *name, long perms) } -WFile *open_existing_wfile(char *name, uint64 *size) +WFile *open_existing_wfile(const char *name, uint64 *size) { int fd; WFile *ret; @@ -298,7 +298,7 @@ uint64 get_file_posn(WFile *f) return ret; } -int file_type(char *name) +int file_type(const char *name) { struct stat statbuf; @@ -321,7 +321,7 @@ struct DirHandle { DIR *dir; }; -DirHandle *open_directory(char *name) +DirHandle *open_directory(const char *name) { DIR *dir; DirHandle *ret; @@ -356,7 +356,7 @@ void close_directory(DirHandle *dir) sfree(dir); } -int test_wildcard(char *name, int cmdline) +int test_wildcard(const char *name, int cmdline) { struct stat statbuf; @@ -390,7 +390,7 @@ struct WildcardMatcher { glob_t globbed; int i; }; -WildcardMatcher *begin_wildcard_matching(char *name) { +WildcardMatcher *begin_wildcard_matching(const char *name) { WildcardMatcher *ret = snew(WildcardMatcher); if (glob(name, 0, NULL, &ret->globbed) < 0) { @@ -413,7 +413,7 @@ void finish_wildcard_matching(WildcardMatcher *dir) { sfree(dir); } -int vet_filename(char *name) +int vet_filename(const char *name) { if (strchr(name, '/')) return FALSE; @@ -424,12 +424,12 @@ int vet_filename(char *name) return TRUE; } -int create_directory(char *name) +int create_directory(const char *name) { return mkdir(name, 0777) == 0; } -char *dir_file_cat(char *dir, char *file) +char *dir_file_cat(const char *dir, const char *file) { return dupcat(dir, "/", file, NULL); } @@ -559,7 +559,7 @@ int ssh_sftp_loop_iteration(void) /* * Read a PSFTP command line from stdin. */ -char *ssh_sftp_get_cmdline(char *prompt, int no_fds_ok) +char *ssh_sftp_get_cmdline(const char *prompt, int no_fds_ok) { char *buf; int buflen, bufsize, ret; diff --git a/unix/uxucs.c b/unix/uxucs.c index 5d3d5af0..86cc33d4 100644 --- a/unix/uxucs.c +++ b/unix/uxucs.c @@ -57,7 +57,7 @@ int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen, } 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) { /* FIXME: we should remove the defused param completely... */ diff --git a/windows/wincons.c b/windows/wincons.c index a470e744..b0ca5f2e 100644 --- a/windows/wincons.c +++ b/windows/wincons.c @@ -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; diff --git a/windows/winctrls.c b/windows/winctrls.c index 9bee9274..ea1cc182 100644 --- a/windows/winctrls.c +++ b/windows/winctrls.c @@ -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, diff --git a/windows/window.c b/windows/window.c index 76c0b928..b021b05f 100644 --- a/windows/window.c +++ b/windows/window.c @@ -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); diff --git a/windows/wingss.c b/windows/wingss.c index d08064d4..0187a5a7 100644 --- a/windows/wingss.c +++ b/windows/wingss.c @@ -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; diff --git a/windows/winmisc.c b/windows/winmisc.c index 5bf52141..d21e1170 100644 --- a/windows/winmisc.c +++ b/windows/winmisc.c @@ -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; diff --git a/windows/winnet.c b/windows/winnet.c index 039701cf..5e05cfc2 100644 --- a/windows/winnet.c +++ b/windows/winnet.c @@ -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, diff --git a/windows/winpgen.c b/windows/winpgen.c index 753cf141..e67a55af 100644 --- a/windows/winpgen.c +++ b/windows/winpgen.c @@ -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: diff --git a/windows/winpgnt.c b/windows/winpgnt.c index 70f8309e..73de99dd 100644 --- a/windows/winpgnt.c +++ b/windows/winpgnt.c @@ -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; diff --git a/windows/winplink.c b/windows/winplink.c index f154ebc9..43f53bb0 100644 --- a/windows/winplink.c +++ b/windows/winplink.c @@ -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); diff --git a/windows/winproxy.c b/windows/winproxy.c index aa14b91a..94954600 100644 --- a/windows/winproxy.c +++ b/windows/winproxy.c @@ -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) diff --git a/windows/winser.c b/windows/winser.c index 086d3e5c..3f1326db 100644 --- a/windows/winser.c +++ b/windows/winser.c @@ -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; diff --git a/windows/winsftp.c b/windows/winsftp.c index d061b514..fa052eeb 100644 --- a/windows/winsftp.c +++ b/windows/winsftp.c @@ -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; diff --git a/windows/winucs.c b/windows/winucs.c index 14728a81..c1888f9e 100644 --- a/windows/winucs.c +++ b/windows/winucs.c @@ -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; diff --git a/windows/winutils.c b/windows/winutils.c index f68405bc..c81e7fe0 100644 --- a/windows/winutils.c +++ b/windows/winutils.c @@ -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) \ diff --git a/x11fwd.c b/x11fwd.c index 4a6d8270..e42edf75 100644 --- a/x11fwd.c +++ b/x11fwd.c @@ -357,10 +357,10 @@ void x11_free_display(struct X11Display *disp) #define XDM_MAXSKEW 20*60 /* 20 minute clock skew should be OK */ -static char *x11_verify(unsigned long peer_ip, int peer_port, - tree234 *authtree, char *proto, - unsigned char *data, int dlen, - struct X11FakeAuth **auth_ret) +static const char *x11_verify(unsigned long peer_ip, int peer_port, + tree234 *authtree, char *proto, + unsigned char *data, int dlen, + struct X11FakeAuth **auth_ret) { struct X11FakeAuth match_dummy; /* for passing to find234 */ struct X11FakeAuth *auth; -- 2.45.2