]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Use fgets instead
authorRoy Marples <roy@marples.name>
Fri, 7 Feb 2014 21:25:26 +0000 (21:25 +0000)
committerRoy Marples <roy@marples.name>
Fri, 7 Feb 2014 21:25:26 +0000 (21:25 +0000)
duid.c

diff --git a/duid.c b/duid.c
index ced513a70707d681c8190c3cb2a51c202a7c5401..acf917bdafdef060278e160e9b23db4054ad9da3 100644 (file)
--- 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);