View | Details | Raw Unified | Return to bug 1157 | Differences between
and this patch

Collapse All | Expand All

(-)ssh-keygen.c (-8 / +36 lines)
Lines 302-314 do_convert_private_ssh2_from_blob(u_char Link Here
302
	return key;
302
	return key;
303
}
303
}
304
304
305
static int
306
get_line(FILE *fp, char *line, size_t len)
307
{
308
	int c;
309
	size_t pos = 0;
310
311
	if (len > INT_MAX)
312
		return -1;
313
314
	line[0] = '\0';
315
	while ((c = fgetc(fp)) != EOF) {
316
		if (pos >= len - 1) {
317
			fprintf(stderr, "input line too long.\n");
318
			exit(1);
319
		}
320
		switch(c) {
321
		case '\r':
322
			c = fgetc(fp);
323
			if (c != EOF && c != '\n' && ungetc(c, fp) == EOF) {
324
				fprintf(stderr, "unget: %s\n", strerror(errno));
325
				exit(1);
326
			}
327
			return 0;
328
		case '\n':
329
			return 0;
330
		}
331
		line[pos++] = c;
332
		line[pos] = '\0';
333
	}
334
	return 0;
335
}
336
305
static void
337
static void
306
do_convert_from_ssh2(struct passwd *pw)
338
do_convert_from_ssh2(struct passwd *pw)
307
{
339
{
308
	Key *k;
340
	Key *k;
309
	int blen;
341
	int blen;
310
	u_int len;
342
	u_int len;
311
	char line[1024], *p;
343
	char line[1024];
312
	u_char blob[8096];
344
	u_char blob[8096];
313
	char encoded[8096];
345
	char encoded[8096];
314
	struct stat st;
346
	struct stat st;
Lines 327-338 do_convert_from_ssh2(struct passwd *pw) Link Here
327
		exit(1);
359
		exit(1);
328
	}
360
	}
329
	encoded[0] = '\0';
361
	encoded[0] = '\0';
330
	while (fgets(line, sizeof(line), fp)) {
362
	while (get_line(fp, line, sizeof(line)) == 0) {
331
		if (!(p = strchr(line, '\n'))) {
363
		len = strlen(line);
332
			fprintf(stderr, "input line too long.\n");
364
		if (line[len - 1] == '\\')
333
			exit(1);
334
		}
335
		if (p > line && p[-1] == '\\')
336
			escaped++;
365
			escaped++;
337
		if (strncmp(line, "----", 4) == 0 ||
366
		if (strncmp(line, "----", 4) == 0 ||
338
		    strstr(line, ": ") != NULL) {
367
		    strstr(line, ": ") != NULL) {
Lines 349-355 do_convert_from_ssh2(struct passwd *pw) Link Here
349
			/* fprintf(stderr, "escaped: %s", line); */
378
			/* fprintf(stderr, "escaped: %s", line); */
350
			continue;
379
			continue;
351
		}
380
		}
352
		*p = '\0';
353
		strlcat(encoded, line, sizeof(encoded));
381
		strlcat(encoded, line, sizeof(encoded));
354
	}
382
	}
355
	len = strlen(encoded);
383
	len = strlen(encoded);

Return to bug 1157