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

Collapse All | Expand All

(-)openssh-3.8.1p1/authfile.c (-3 / +53 lines)
Lines 588-604 Link Here
588
	return prv;
588
	return prv;
589
}
589
}
590
590
591
static char *
592
read_whole_line(char *line, size_t *size, FILE *f)
593
{
594
	long lstart;
595
	size_t sz = *size;
596
597
	if (!line) {
598
		fatal("read_whole_line: NULL pointer given as line argument");
599
	}
600
601
	lstart = ftell(f);
602
	if (!~lstart) {
603
		fatal("read_whole_line: cannot read the current stream offset");
604
	}
605
606
 up:
607
	line[sz - 2] = '\0';
608
609
	if (fgets(line, sz, f)) {
610
		if (line[sz - 2] != '\0') {
611
			sz <<= 1;
612
			if (sz <= *size) {
613
				fatal("read_whole_line: line buffer overflow");
614
			}
615
			
616
			line = xrealloc(line, sz);
617
618
			if (!~fseek(f, lstart, SEEK_SET)) {
619
				fatal("read_whole_line: cannot rewind to the old stream offset (%ld)", lstart);
620
			}
621
622
			goto up;
623
		}
624
625
		*size = sz;
626
627
		return line;
628
	}
629
630
	return NULL;
631
}
632
591
static int
633
static int
592
key_try_load_public(Key *k, const char *filename, char **commentp)
634
key_try_load_public(Key *k, const char *filename, char **commentp)
593
{
635
{
594
	FILE *f;
636
	FILE *f;
595
	char line[4096];
637
	size_t size;
638
	char *line;
596
	char *cp;
639
	char *cp;
597
640
598
	f = fopen(filename, "r");
641
	f = fopen(filename, "r");
599
	if (f != NULL) {
642
	if (f != NULL) {
600
		while (fgets(line, sizeof(line), f)) {
643
		size = 1024;
601
			line[sizeof(line)-1] = '\0';
644
		line = xmalloc(size);
645
646
		while (read_whole_line(line, &size, f)) {
647
			line[size-1] = '\0';
602
			cp = line;
648
			cp = line;
603
			switch (*cp) {
649
			switch (*cp) {
604
			case '#':
650
			case '#':
Lines 613-623 Link Here
613
				if (key_read(k, &cp) == 1) {
659
				if (key_read(k, &cp) == 1) {
614
					if (commentp)
660
					if (commentp)
615
						*commentp=xstrdup(filename);
661
						*commentp=xstrdup(filename);
662
663
					xfree(line);
616
					fclose(f);
664
					fclose(f);
617
					return 1;
665
					return 1;
618
				}
666
				}
619
			}
667
			}
620
		}
668
		}
669
670
		xfree(line);
621
		fclose(f);
671
		fclose(f);
622
	}
672
	}
623
	return 0;
673
	return 0;

Return to bug 884