mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-03-22 06:38:37 -05:00
kexinit_algorithm: switch to storing names as ptrlen.
They're now also compared as strings, fixing the slight fragility where we depended on string-literal pointer equality.
This commit is contained in:
parent
3a54f28a4e
commit
6a9e4ba24a
@ -302,17 +302,17 @@ static void ssh2_mkkey(
|
|||||||
* Find a slot in a KEXINIT algorithm list to use for a new algorithm.
|
* Find a slot in a KEXINIT algorithm list to use for a new algorithm.
|
||||||
* If the algorithm is already in the list, return a pointer to its
|
* If the algorithm is already in the list, return a pointer to its
|
||||||
* entry, otherwise return an entry from the end of the list.
|
* entry, otherwise return an entry from the end of the list.
|
||||||
* This assumes that every time a particular name is passed in, it
|
*
|
||||||
* comes from the same string constant. If this isn't true, this
|
* 'name' is expected to be a ptrlen which it's safe to keep a copy
|
||||||
* function may need to be rewritten to use strcmp() instead.
|
* of.
|
||||||
*/
|
*/
|
||||||
static struct kexinit_algorithm *ssh2_kexinit_addalg(struct kexinit_algorithm
|
static struct kexinit_algorithm *ssh2_kexinit_addalg_pl(
|
||||||
*list, const char *name)
|
struct kexinit_algorithm *list, ptrlen name)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAXKEXLIST; i++)
|
for (i = 0; i < MAXKEXLIST; i++)
|
||||||
if (list[i].name == NULL || list[i].name == name) {
|
if (list[i].name.ptr == NULL || ptrlen_eq_ptrlen(list[i].name, name)) {
|
||||||
list[i].name = name;
|
list[i].name = name;
|
||||||
return &list[i];
|
return &list[i];
|
||||||
}
|
}
|
||||||
@ -320,6 +320,12 @@ static struct kexinit_algorithm *ssh2_kexinit_addalg(struct kexinit_algorithm
|
|||||||
unreachable("Should never run out of space in KEXINIT list");
|
unreachable("Should never run out of space in KEXINIT list");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct kexinit_algorithm *ssh2_kexinit_addalg(
|
||||||
|
struct kexinit_algorithm *list, const char *name)
|
||||||
|
{
|
||||||
|
return ssh2_kexinit_addalg_pl(list, ptrlen_from_asciz(name));
|
||||||
|
}
|
||||||
|
|
||||||
bool ssh2_common_filter_queue(PacketProtocolLayer *ppl)
|
bool ssh2_common_filter_queue(PacketProtocolLayer *ppl)
|
||||||
{
|
{
|
||||||
static const char *const ssh2_disconnect_reasons[] = {
|
static const char *const ssh2_disconnect_reasons[] = {
|
||||||
@ -606,7 +612,7 @@ static void ssh2_write_kexinit_lists(
|
|||||||
|
|
||||||
for (i = 0; i < NKEXLIST; i++)
|
for (i = 0; i < NKEXLIST; i++)
|
||||||
for (j = 0; j < MAXKEXLIST; j++)
|
for (j = 0; j < MAXKEXLIST; j++)
|
||||||
kexlists[i][j].name = NULL;
|
kexlists[i][j].name = make_ptrlen(NULL, 0);
|
||||||
/* List key exchange algorithms. */
|
/* List key exchange algorithms. */
|
||||||
warn = false;
|
warn = false;
|
||||||
for (i = 0; i < n_preferred_kex; i++) {
|
for (i = 0; i < n_preferred_kex; i++) {
|
||||||
@ -832,8 +838,8 @@ static void ssh2_write_kexinit_lists(
|
|||||||
put_datapl(list, ssc->kex_override[i]);
|
put_datapl(list, ssc->kex_override[i]);
|
||||||
} else {
|
} else {
|
||||||
for (j = 0; j < MAXKEXLIST; j++) {
|
for (j = 0; j < MAXKEXLIST; j++) {
|
||||||
if (kexlists[i][j].name == NULL) break;
|
if (kexlists[i][j].name.ptr == NULL) break;
|
||||||
add_to_commasep(list, kexlists[i][j].name);
|
add_to_commasep_pl(list, kexlists[i][j].name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i == KEXLIST_KEX && first_time) {
|
if (i == KEXLIST_KEX && first_time) {
|
||||||
@ -923,8 +929,8 @@ static bool ssh2_scan_kexinits(
|
|||||||
|
|
||||||
selected[i] = NULL;
|
selected[i] = NULL;
|
||||||
for (j = 0; j < MAXKEXLIST; j++) {
|
for (j = 0; j < MAXKEXLIST; j++) {
|
||||||
if (kexlists[i][j].name &&
|
if (kexlists[i][j].name.ptr &&
|
||||||
ptrlen_eq_string(found, kexlists[i][j].name)) {
|
ptrlen_eq_ptrlen(found, kexlists[i][j].name)) {
|
||||||
selected[i] = &kexlists[i][j];
|
selected[i] = &kexlists[i][j];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#define MAXKEXLIST 16
|
#define MAXKEXLIST 16
|
||||||
struct kexinit_algorithm {
|
struct kexinit_algorithm {
|
||||||
const char *name;
|
ptrlen name;
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
const ssh_kex *kex;
|
const ssh_kex *kex;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user