Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/umbctl Fix and improve parsing of configuration files
details: https://anonhg.NetBSD.org/src/rev/9311b99ffc92
branches: trunk
changeset: 932692:9311b99ffc92
user: khorben <khorben%NetBSD.org@localhost>
date: Wed May 13 21:44:30 2020 +0000
description:
Fix and improve parsing of configuration files
XXX pull-up to netbsd-9
diffstat:
sbin/umbctl/umbctl.c | 25 +++++++++++++++++++++----
1 files changed, 21 insertions(+), 4 deletions(-)
diffs (61 lines):
diff -r 7ecdda869a9e -r 9311b99ffc92 sbin/umbctl/umbctl.c
--- a/sbin/umbctl/umbctl.c Wed May 13 21:34:01 2020 +0000
+++ b/sbin/umbctl/umbctl.c Wed May 13 21:44:30 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: umbctl.c,v 1.3 2020/03/22 07:45:02 khorben Exp $ */
+/* $NetBSD: umbctl.c,v 1.4 2020/05/13 21:44:30 khorben Exp $ */
/*
* Copyright (c) 2018 Pierre Pronchery <khorben%defora.org@localhost>
*
@@ -179,12 +179,15 @@
/* umbctl_file */
static int _umbctl_file(char const * ifname, char const * filename, int verbose)
{
+ int ret = 0;
int fd;
struct ifreq ifr;
struct umb_info umbi;
struct umb_parameter umbp;
FILE * fp;
char buf[512];
+ size_t len;
+ int i;
int eof;
char * tokens[3] = { buf, NULL, NULL };
char * p;
@@ -197,18 +200,32 @@
if(buf[0] == '#')
continue;
buf[sizeof(buf) - 1] = '\0';
- if((p = strstr(buf, "=")) != NULL)
+ if((len = strlen(buf)) > 0)
+ {
+ if(buf[len - 1] != '\n')
+ {
+ ret = _error(2, "%s: %s", filename,
+ "Line too long");
+ while((i = fgetc(fp)) != EOF && i != '\n');
+ continue;
+ }
+ else
+ buf[len - 1] = '\0';
+ }
+ if((p = strchr(buf, '=')) != NULL)
{
tokens[1] = p + 1;
*p = '\0';
} else
tokens[1] = NULL;
- if(_umbctl_set(ifname, &umbp, (p != NULL) ? 2 : 1, tokens) != 0)
- break;
+ ret |= _umbctl_set(ifname, &umbp, (p != NULL) ? 2 : 1, tokens)
+ ? 2 : 0;
}
eof = feof(fp);
if(fclose(fp) != 0 || !eof)
return _error(2, "%s: %s", filename, strerror(errno));
+ if(ret != 0)
+ return ret;
if((fd = _umbctl_socket()) < 0)
return 2;
memset(&ifr, 0, sizeof(ifr));
Home |
Main Index |
Thread Index |
Old Index