From: Roy Marples Date: Fri, 7 Feb 2014 21:25:26 +0000 (+0000) Subject: Use fgets instead X-Git-Tag: v6.3.0~25 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=08e579296db68a3ef69d3515a2c140279a4e5212;p=thirdparty%2Fdhcpcd.git Use fgets instead --- diff --git a/duid.c b/duid.c index ced513a7..acf917bd 100644 --- a/duid.c +++ b/duid.c @@ -83,19 +83,25 @@ duid_make(unsigned char *d, const struct interface *ifp, uint16_t type) return p - d; } +#define DUID_STRLEN DUID_LEN * 3 static size_t duid_get(unsigned char *d, const struct interface *ifp) { FILE *fp; int x = 0; size_t len = 0; - char line[513]; + char line[DUID_STRLEN + 1]; const struct interface *ifp2; /* If we already have a DUID then use it as it's never supposed * to change once we have one even if the interfaces do */ if ((fp = fopen(DUID, "r"))) { - while (fscanf(fp, "%512s\n", line) != EOF) { + while (fgets(line, DUID_STRLEN, fp)) { + len = strlen(line); + if (len) { + if (line[len - 1] == '\n') + line[len - 1] = '\0'; + } len = hwaddr_aton(NULL, line); if (len && len <= DUID_LEN) { hwaddr_aton(d, line);