1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12:48 -05:00

Giant const-correctness patch of doom!

Having found a lot of unfixed constness issues in recent development,
I thought perhaps it was time to get proactive, so I compiled the
whole codebase with -Wwrite-strings. That turned up a huge load of
const problems, which I've fixed in this commit: the Unix build now
goes cleanly through with -Wwrite-strings, and the Windows build is as
close as I could get it (there are some lingering issues due to
occasional Windows API functions like AcquireCredentialsHandle not
having the right constness).

Notable fallout beyond the purely mechanical changing of types:
 - the stuff saved by cmdline_save_param() is now explicitly
   dupstr()ed, and freed in cmdline_run_saved.
 - I couldn't make both string arguments to cmdline_process_param()
   const, because it intentionally writes to one of them in the case
   where it's the argument to -pw (in the vain hope of being at least
   slightly friendly to 'ps'), so elsewhere I had to temporarily
   dupstr() something for the sake of passing it to that function
 - I had to invent a silly parallel version of const_cmp() so I could
   pass const string literals in to lookup functions.
 - stripslashes() in pscp.c and psftp.c has the annoying strchr nature
This commit is contained in:
Simon Tatham
2015-05-15 11:15:42 +01:00
parent fb4fbe1158
commit 89da2ddf56
65 changed files with 559 additions and 450 deletions

View File

@ -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 */