1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-25 01:02:24 +00:00

When the first element in a preference list was unrecognised, PuTTY would

hang when reading it because strtok() kept getting the full list passed in.
Fix this, and add an assert() for an assumption documented in a comment while
I'm in the area.

[originally from svn r6294]
This commit is contained in:
Ben Harris 2005-09-12 15:45:29 +00:00
parent b65e905572
commit 456ba58329

View File

@ -2,6 +2,7 @@
* settings.c: read and write saved sessions. (platform-independent) * settings.c: read and write saved sessions. (platform-independent)
*/ */
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "putty.h" #include "putty.h"
@ -172,6 +173,7 @@ static void gprefs(void *sesskey, char *name, char *def,
int *array) int *array)
{ {
char commalist[80]; char commalist[80];
char *tokarg = commalist;
int n; int n;
unsigned long seen = 0; /* bitmap for weeding dups etc */ unsigned long seen = 0; /* bitmap for weeding dups etc */
gpps(sesskey, name, def, commalist, sizeof(commalist)); gpps(sesskey, name, def, commalist, sizeof(commalist));
@ -181,7 +183,8 @@ static void gprefs(void *sesskey, char *name, char *def,
do { do {
int v; int v;
char *key; char *key;
key = strtok(n==0 ? commalist : NULL, ","); /* sorry */ key = strtok(tokarg, ","); /* sorry */
tokarg = NULL;
if (!key) break; if (!key) break;
if (((v = key2val(mapping, nvals, key)) != -1) && if (((v = key2val(mapping, nvals, key)) != -1) &&
!(seen & 1<<v)) { !(seen & 1<<v)) {
@ -194,6 +197,7 @@ static void gprefs(void *sesskey, char *name, char *def,
{ {
int i; int i;
for (i = 0; i < nvals; i++) { for (i = 0; i < nvals; i++) {
assert(mapping[i].v < 32);
if (!(seen & 1<<mapping[i].v)) { if (!(seen & 1<<mapping[i].v)) {
array[n] = mapping[i].v; array[n] = mapping[i].v;
n++; n++;