summaryrefslogtreecommitdiff
path: root/session.c
diff options
context:
space:
mode:
authormarkus@openbsd.org <markus@openbsd.org>2018-06-06 18:29:18 +0000
committerDamien Miller <djm@mindrot.org>2018-06-07 04:34:05 +1000
commit7f90635216851f6cb4bf3999e98b825f85d604f8 (patch)
treeac302db18a71c1e3c5d9077d1a820e37fbc2b9b5 /session.c
parent392db2bc83215986a91c0b65feb0e40e7619ce7e (diff)
upstream: switch config file parsing to getline(3) as this avoids
static limits noted by gerhard@; ok dtucker@, djm@ OpenBSD-Commit-ID: 6d702eabef0fa12e5a1d75c334a8c8b325298b5c
Diffstat (limited to 'session.c')
-rw-r--r--session.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/session.c b/session.c
index e72fcb0a8..511fc4e87 100644
--- a/session.c
+++ b/session.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: session.c,v 1.297 2018/06/06 18:23:32 djm Exp $ */ 1/* $OpenBSD: session.c,v 1.298 2018/06/06 18:29:18 markus Exp $ */
2/* 2/*
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved 4 * All rights reserved
@@ -873,18 +873,18 @@ read_environment_file(char ***env, u_int *envsize,
873 const char *filename) 873 const char *filename)
874{ 874{
875 FILE *f; 875 FILE *f;
876 char buf[4096]; 876 char *line = NULL, *cp, *value;
877 char *cp, *value; 877 size_t linesize = 0;
878 u_int lineno = 0; 878 u_int lineno = 0;
879 879
880 f = fopen(filename, "r"); 880 f = fopen(filename, "r");
881 if (!f) 881 if (!f)
882 return; 882 return;
883 883
884 while (fgets(buf, sizeof(buf), f)) { 884 while (getline(&line, &linesize, f) != -1) {
885 if (++lineno > 1000) 885 if (++lineno > 1000)
886 fatal("Too many lines in environment file %s", filename); 886 fatal("Too many lines in environment file %s", filename);
887 for (cp = buf; *cp == ' ' || *cp == '\t'; cp++) 887 for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
888 ; 888 ;
889 if (!*cp || *cp == '#' || *cp == '\n') 889 if (!*cp || *cp == '#' || *cp == '\n')
890 continue; 890 continue;
@@ -905,6 +905,7 @@ read_environment_file(char ***env, u_int *envsize,
905 value++; 905 value++;
906 child_set_env(env, envsize, cp, value); 906 child_set_env(env, envsize, cp, value);
907 } 907 }
908 free(line);
908 fclose(f); 909 fclose(f);
909} 910}
910 911