aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Hermann <alex@hexla.nl>2017-04-13 16:05:41 +0200
committerAndreas Schneider <asn@cryptomilk.org>2017-04-13 16:08:20 +0200
commit5f202d7ffa48f2ee989e0e6c1e761963c68ab08f (patch)
tree3db63c63fef4b10f9884eb3a929e7f900dbcb885
parentc3a8b5009ffacd7bda838ca48c79697847e83c19 (diff)
downloadlibssh-5f202d7ffa48f2ee989e0e6c1e761963c68ab08f.tar.gz
libssh-5f202d7ffa48f2ee989e0e6c1e761963c68ab08f.tar.xz
libssh-5f202d7ffa48f2ee989e0e6c1e761963c68ab08f.zip
config: Only use first occurence of each parameter
ssh_config's manpage says: "For each parameter, the first obtained value will be used." Make libssh adhere to this rule. BUG: https://red.libssh.org/issues/256 Signed-off-by: Alex Hermann <alex@hexla.nl> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--src/config.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/config.c b/src/config.c
index ae83f90f..6478fc5f 100644
--- a/src/config.c
+++ b/src/config.c
@@ -50,6 +50,8 @@ enum ssh_config_opcode_e {
SOC_GSSAPISERVERIDENTITY,
SOC_GSSAPICLIENTIDENTITY,
SOC_GSSAPIDELEGATECREDENTIALS,
+
+ SOC_END /* Keep this one last in the list */
};
struct ssh_config_keyword_table_s {
@@ -185,7 +187,7 @@ static int ssh_config_get_yesno(char **str, int notfound) {
}
static int ssh_config_parse_line(ssh_session session, const char *line,
- unsigned int count, int *parsing) {
+ unsigned int count, int *parsing, int seen[]) {
enum ssh_config_opcode_e opcode;
const char *p;
char *s, *x;
@@ -216,6 +218,12 @@ static int ssh_config_parse_line(ssh_session session, const char *line,
}
opcode = ssh_config_get_opcode(keyword);
+ if (*parsing == 1 && opcode != SOC_HOST) {
+ if (seen[opcode] == 0) {
+ return 0;
+ }
+ seen[opcode] = 1;
+ }
switch (opcode) {
case SOC_HOST: {
@@ -383,6 +391,7 @@ int ssh_config_parse_file(ssh_session session, const char *filename) {
unsigned int count = 0;
FILE *f;
int parsing;
+ int seen[SOC_END - SOC_UNSUPPORTED] = {0};
if ((f = fopen(filename, "r")) == NULL) {
return 0;
@@ -393,7 +402,7 @@ int ssh_config_parse_file(ssh_session session, const char *filename) {
parsing = 1;
while (fgets(line, sizeof(line), f)) {
count++;
- if (ssh_config_parse_line(session, line, count, &parsing) < 0) {
+ if (ssh_config_parse_line(session, line, count, &parsing, seen) < 0) {
fclose(f);
return -1;
}