This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new e939e55  webclient.c: Limit the number of redirections
e939e55 is described below

commit e939e55a50716b1f8130b718fe885f87e2c171b1
Author: YAMAMOTO Takashi <[email protected]>
AuthorDate: Mon May 25 23:21:07 2020 +0900

    webclient.c: Limit the number of redirections
---
 netutils/webclient/webclient.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/netutils/webclient/webclient.c b/netutils/webclient/webclient.c
index 944d7f7..a2aa492 100644
--- a/netutils/webclient/webclient.c
+++ b/netutils/webclient/webclient.c
@@ -103,6 +103,11 @@
 #  define CONFIG_WEBCLIENT_TIMEOUT 10
 #endif
 
+#ifndef CONFIG_WEBCLIENT_MAX_REDIRECT
+/* The default value 50 is taken from curl's --max-redirs option. */
+#  define CONFIG_WEBCLIENT_MAX_REDIRECT 50
+#endif
+
 #define WEBCLIENT_STATE_STATUSLINE 0
 #define WEBCLIENT_STATE_HEADERS    1
 #define WEBCLIENT_STATE_DATA       2
@@ -467,6 +472,7 @@ static int wget_base(FAR const char *url, FAR char *buffer, 
int buflen,
   struct wget_s *ws;
   struct timeval tv;
   bool redirected;
+  unsigned int nredirect = 0;
   char *dest;
   int sockfd;
   int len;
@@ -685,6 +691,13 @@ static int wget_base(FAR const char *url, FAR char 
*buffer, int buflen,
               else
                 {
                   redirected = true;
+                  nredirect++;
+                  if (nredirect > CONFIG_WEBCLIENT_MAX_REDIRECT)
+                    {
+                      nerr("ERROR: too many redirects (%u)\n", nredirect);
+                      goto errout;
+                    }
+
                   close(sockfd);
                   break;
                 }

Reply via email to