]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
netrc: replace fgets with Curl_get_line
authorDaniel Stenberg <daniel@haxx.se>
Tue, 4 Oct 2022 12:37:24 +0000 (14:37 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 24 Oct 2022 09:29:03 +0000 (11:29 +0200)
Make the parser only accept complete lines and avoid problems with
overly long lines.

Reported-by: Hiroki Kurosawa
Closes #9789

lib/curl_get_line.c
lib/netrc.c

index 6a26bb254fa5b95f9cfda1e21d336210f0498faa..22e3705f4cdec886a8f457c76a4e74cc4646f314 100644 (file)
@@ -25,7 +25,7 @@
 #include "curl_setup.h"
 
 #if !defined(CURL_DISABLE_COOKIES) || !defined(CURL_DISABLE_ALTSVC) ||  \
-  !defined(CURL_DISABLE_HSTS)
+  !defined(CURL_DISABLE_HSTS) || !defined(CURL_DISABLE_NETRC)
 
 #include "curl_get_line.h"
 #include "curl_memory.h"
@@ -33,8 +33,8 @@
 #include "memdebug.h"
 
 /*
- * get_line() makes sure to only return complete whole lines that fit in 'len'
- * bytes and end with a newline.
+ * Curl_get_line() makes sure to only return complete whole lines that fit in
+ * 'len' bytes and end with a newline.
  */
 char *Curl_get_line(char *buf, int len, FILE *input)
 {
index d620d6bb5cc9aeb8c043b9fd0179ae71af1b37af..4461b8492fda9092c9cd14665c9d59252b8d427d 100644 (file)
@@ -33,6 +33,7 @@
 #include "netrc.h"
 #include "strtok.h"
 #include "strcase.h"
+#include "curl_get_line.h"
 
 /* The last 3 #include files should be in this order */
 #include "curl_printf.h"
@@ -82,7 +83,7 @@ static int parsenetrc(const char *host,
     char netrcbuffer[4096];
     int  netrcbuffsize = (int)sizeof(netrcbuffer);
 
-    while(!done && fgets(netrcbuffer, netrcbuffsize, file)) {
+    while(!done && Curl_get_line(netrcbuffer, netrcbuffsize, file)) {
       char *tok;
       char *tok_end;
       bool quoted;
@@ -241,7 +242,7 @@ static int parsenetrc(const char *host,
         } /* switch (state) */
         tok = ++tok_end;
       }
-    } /* while fgets() */
+    } /* while Curl_get_line() */
 
     out:
     if(!retcode) {