mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 01:48:00 +00:00
New utility functions to make ptrlens.
One to make one from a NUL-terminated string, and another to make one from a strbuf. I've switched over all the obvious cases where I should have been using these functions.
This commit is contained in:
parent
b9bfc81531
commit
56096ba558
2
cmdgen.c
2
cmdgen.c
@ -816,7 +816,7 @@ int main(int argc, char **argv)
|
|||||||
const ssh_keyalg *alg = find_pubkey_alg(ssh2alg);
|
const ssh_keyalg *alg = find_pubkey_alg(ssh2alg);
|
||||||
if (alg)
|
if (alg)
|
||||||
bits = ssh_key_public_bits(
|
bits = ssh_key_public_bits(
|
||||||
alg, make_ptrlen(ssh2blob->s, ssh2blob->len));
|
alg, ptrlen_from_strbuf(ssh2blob));
|
||||||
else
|
else
|
||||||
bits = -1;
|
bits = -1;
|
||||||
} else {
|
} else {
|
||||||
|
10
misc.c
10
misc.c
@ -1243,6 +1243,16 @@ ptrlen make_ptrlen(const void *ptr, size_t len)
|
|||||||
return pl;
|
return pl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ptrlen ptrlen_from_asciz(const char *str)
|
||||||
|
{
|
||||||
|
return make_ptrlen(str, strlen(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
ptrlen ptrlen_from_strbuf(strbuf *sb)
|
||||||
|
{
|
||||||
|
return make_ptrlen(sb->u, sb->len);
|
||||||
|
}
|
||||||
|
|
||||||
int ptrlen_eq_string(ptrlen pl, const char *str)
|
int ptrlen_eq_string(ptrlen pl, const char *str)
|
||||||
{
|
{
|
||||||
size_t len = strlen(str);
|
size_t len = strlen(str);
|
||||||
|
2
misc.h
2
misc.h
@ -97,6 +97,8 @@ struct tm ltime(void);
|
|||||||
int nullstrcmp(const char *a, const char *b);
|
int nullstrcmp(const char *a, const char *b);
|
||||||
|
|
||||||
ptrlen make_ptrlen(const void *ptr, size_t len);
|
ptrlen make_ptrlen(const void *ptr, size_t len);
|
||||||
|
ptrlen ptrlen_from_asciz(const char *str);
|
||||||
|
ptrlen ptrlen_from_strbuf(strbuf *sb);
|
||||||
int ptrlen_eq_string(ptrlen pl, const char *str);
|
int ptrlen_eq_string(ptrlen pl, const char *str);
|
||||||
char *mkstr(ptrlen pl);
|
char *mkstr(ptrlen pl);
|
||||||
int string_length_for_printf(size_t);
|
int string_length_for_printf(size_t);
|
||||||
|
@ -867,8 +867,8 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
|
|||||||
BinarySink_UPCAST(sigblob));
|
BinarySink_UPCAST(sigblob));
|
||||||
strbuf_free(sigdata);
|
strbuf_free(sigdata);
|
||||||
ssh2_userauth_add_sigblob(
|
ssh2_userauth_add_sigblob(
|
||||||
s, s->pktout, make_ptrlen(pkblob->s, pkblob->len),
|
s, s->pktout, ptrlen_from_strbuf(pkblob),
|
||||||
make_ptrlen(sigblob->s, sigblob->len));
|
ptrlen_from_strbuf(sigblob));
|
||||||
strbuf_free(pkblob);
|
strbuf_free(pkblob);
|
||||||
strbuf_free(sigblob);
|
strbuf_free(sigblob);
|
||||||
|
|
||||||
|
@ -584,7 +584,7 @@ const ssh_keyalg *find_pubkey_alg_len(ptrlen name)
|
|||||||
|
|
||||||
const ssh_keyalg *find_pubkey_alg(const char *name)
|
const ssh_keyalg *find_pubkey_alg(const char *name)
|
||||||
{
|
{
|
||||||
return find_pubkey_alg_len(make_ptrlen(name, strlen(name)));
|
return find_pubkey_alg_len(ptrlen_from_asciz(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
|
struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
|
||||||
@ -798,8 +798,8 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
|
|||||||
ret = snew(struct ssh2_userkey);
|
ret = snew(struct ssh2_userkey);
|
||||||
ret->comment = comment;
|
ret->comment = comment;
|
||||||
ret->key = ssh_key_new_priv(
|
ret->key = ssh_key_new_priv(
|
||||||
alg, make_ptrlen(public_blob->u, public_blob->len),
|
alg, ptrlen_from_strbuf(public_blob),
|
||||||
make_ptrlen(private_blob->u, private_blob->len));
|
ptrlen_from_strbuf(private_blob));
|
||||||
if (!ret->key) {
|
if (!ret->key) {
|
||||||
sfree(ret);
|
sfree(ret);
|
||||||
ret = NULL;
|
ret = NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user