summaryrefslogtreecommitdiff
path: root/ssh-keygen.c
diff options
context:
space:
mode:
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r--ssh-keygen.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c
index 8acbf7783..bea4ed59b 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -12,7 +12,7 @@
12 */ 12 */
13 13
14#include "includes.h" 14#include "includes.h"
15RCSID("$OpenBSD: ssh-keygen.c,v 1.136 2006/02/20 17:19:54 stevesk Exp $"); 15RCSID("$OpenBSD: ssh-keygen.c,v 1.137 2006/03/13 08:43:16 dtucker Exp $");
16 16
17#include <sys/types.h> 17#include <sys/types.h>
18#include <sys/stat.h> 18#include <sys/stat.h>
@@ -305,13 +305,42 @@ do_convert_private_ssh2_from_blob(u_char *blob, u_int blen)
305 return key; 305 return key;
306} 306}
307 307
308static int
309get_line(FILE *fp, char *line, size_t len)
310{
311 int c;
312 size_t pos = 0;
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 pos;
328 case '\n':
329 return pos;
330 }
331 line[pos++] = c;
332 line[pos] = '\0';
333 }
334 return pos;
335}
336
308static void 337static void
309do_convert_from_ssh2(struct passwd *pw) 338do_convert_from_ssh2(struct passwd *pw)
310{ 339{
311 Key *k; 340 Key *k;
312 int blen; 341 int blen;
313 u_int len; 342 u_int len;
314 char line[1024], *p; 343 char line[1024];
315 u_char blob[8096]; 344 u_char blob[8096];
316 char encoded[8096]; 345 char encoded[8096];
317 struct stat st; 346 struct stat st;
@@ -330,12 +359,8 @@ do_convert_from_ssh2(struct passwd *pw)
330 exit(1); 359 exit(1);
331 } 360 }
332 encoded[0] = '\0'; 361 encoded[0] = '\0';
333 while (fgets(line, sizeof(line), fp)) { 362 while ((blen = get_line(fp, line, sizeof(line))) != -1) {
334 if (!(p = strchr(line, '\n'))) { 363 if (line[blen - 1] == '\\')
335 fprintf(stderr, "input line too long.\n");
336 exit(1);
337 }
338 if (p > line && p[-1] == '\\')
339 escaped++; 364 escaped++;
340 if (strncmp(line, "----", 4) == 0 || 365 if (strncmp(line, "----", 4) == 0 ||
341 strstr(line, ": ") != NULL) { 366 strstr(line, ": ") != NULL) {
@@ -352,7 +377,6 @@ do_convert_from_ssh2(struct passwd *pw)
352 /* fprintf(stderr, "escaped: %s", line); */ 377 /* fprintf(stderr, "escaped: %s", line); */
353 continue; 378 continue;
354 } 379 }
355 *p = '\0';
356 strlcat(encoded, line, sizeof(encoded)); 380 strlcat(encoded, line, sizeof(encoded));
357 } 381 }
358 len = strlen(encoded); 382 len = strlen(encoded);