You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/06/07 12:09:17 UTC
[incubator-nuttx-apps] branch master updated (a5506b379 -> 610b04fa9)
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
from a5506b379 Revert "remove DISCLAIMER-WIP"
new a7de8dffe netlib_parseurl.c: Add a comment
new f7b3eb5b4 netlib_parseurl: Make the buffer size assumption explicit
new 0c4c81143 webcilent: Fix a buffer overrun on a malformed status line
new 065a130bc webclient: Be a bit strict on Location header
new 610b04fa9 webclient: Clear WGET_FLAG_GOT_CONTENT_LENGTH for each request
The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
netutils/netlib/netlib_parseurl.c | 14 ++++++++++++
netutils/webclient/webclient.c | 45 ++++++++++++++++++++++++++++++++++++---
2 files changed, 56 insertions(+), 3 deletions(-)
[incubator-nuttx-apps] 01/05: netlib_parseurl.c: Add a comment
Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit a7de8dffe70641268005d9c694773c5f67a0f918
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Mon Jun 6 16:00:03 2022 +0900
netlib_parseurl.c: Add a comment
---
netutils/netlib/netlib_parseurl.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/netutils/netlib/netlib_parseurl.c b/netutils/netlib/netlib_parseurl.c
index f1ababe9e..ddb84a65a 100644
--- a/netutils/netlib/netlib_parseurl.c
+++ b/netutils/netlib/netlib_parseurl.c
@@ -174,6 +174,11 @@ int netlib_parseurl(FAR const char *str, FAR struct url_s *url)
src++;
}
+ /* Note: the current implementation does not distinguish
+ * an empty path and "/". While it's fine for HTTP, maybe it's
+ * cleaner to move the HTTP-specific normalization to the caller.
+ */
+
*dest++ = '/';
bytesleft--;
[incubator-nuttx-apps] 02/05: netlib_parseurl: Make the buffer size assumption explicit
Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit f7b3eb5b44cda746ad8b91fa1ea70c3f970e3f1c
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Mon Jun 6 16:12:09 2022 +0900
netlib_parseurl: Make the buffer size assumption explicit
---
netutils/netlib/netlib_parseurl.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/netutils/netlib/netlib_parseurl.c b/netutils/netlib/netlib_parseurl.c
index ddb84a65a..775f2f189 100644
--- a/netutils/netlib/netlib_parseurl.c
+++ b/netutils/netlib/netlib_parseurl.c
@@ -63,6 +63,15 @@ int netlib_parseurl(FAR const char *str, FAR struct url_s *url)
int ret = OK;
size_t pathlen;
+ /* Each fields should have at least 1 byte to store
+ * the terminating NUL.
+ */
+
+ if (url->schemelen == 0 || url->hostlen == 0 || url->pathlen == 0)
+ {
+ return -EINVAL;
+ }
+
/* extract the protocol field, a set of a-z letters */
dest = url->scheme;
[incubator-nuttx-apps] 03/05: webcilent: Fix a buffer overrun on a malformed status line
Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 0c4c81143442dc96129482f07d0cb2fe10cb0a84
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Mon Jun 6 17:43:36 2022 +0900
webcilent: Fix a buffer overrun on a malformed status line
---
netutils/webclient/webclient.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/netutils/webclient/webclient.c b/netutils/webclient/webclient.c
index f5599e9ca..8378cd135 100644
--- a/netutils/webclient/webclient.c
+++ b/netutils/webclient/webclient.c
@@ -489,6 +489,16 @@ static inline int wget_parsestatus(struct webclient_context *ctx,
return -E2BIG;
}
+ /* HTTP status line is something like:
+ *
+ * HTTP/1.1 200 OK
+ *
+ * https://datatracker.ietf.org/doc/html/rfc7230#section-3.1.2
+ *
+ * > status-line = HTTP-version SP status-code \
+ * > SP reason-phrase CRLF
+ */
+
ws->line[ndx] = '\0';
if ((strncmp(ws->line, g_http10, strlen(g_http10)) == 0) ||
(strncmp(ws->line, g_http11, strlen(g_http11)) == 0))
@@ -496,7 +506,15 @@ static inline int wget_parsestatus(struct webclient_context *ctx,
unsigned long http_status;
char *ep;
- dest = &(ws->line[9]);
+ DEBUGASSERT(strlen(g_http10) == 8);
+ DEBUGASSERT(strlen(g_http11) == 8);
+
+ if (ws->line[8] != ' ') /* SP before the status-code */
+ {
+ return -EINVAL;
+ }
+
+ dest = &(ws->line[9]); /* the status-code */
ws->httpstatus = HTTPSTATUS_NONE;
errno = 0;
@@ -506,7 +524,7 @@ static inline int wget_parsestatus(struct webclient_context *ctx,
return -EINVAL;
}
- if (*ep != ' ')
+ if (*ep != ' ') /* SP before reason-phrase */
{
return -EINVAL;
}
[incubator-nuttx-apps] 04/05: webclient: Be a bit strict on Location header
Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 065a130bc8cb09ac01afb0817aecb55c16f417cd
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Mon Jun 6 18:02:48 2022 +0900
webclient: Be a bit strict on Location header
* Record Location header explicitly
* Bail out / warn on unexpected cases
---
netutils/webclient/webclient.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/netutils/webclient/webclient.c b/netutils/webclient/webclient.c
index 8378cd135..e3763265a 100644
--- a/netutils/webclient/webclient.c
+++ b/netutils/webclient/webclient.c
@@ -168,6 +168,7 @@ enum webclient_state_e
#define WGET_FLAG_GOT_CONTENT_LENGTH 1U
#define WGET_FLAG_CHUNKED 2U
+#define WGET_FLAG_GOT_LOCATION 4U
struct wget_target_s
{
@@ -576,7 +577,8 @@ static inline int wget_parsestatus(struct webclient_context *ctx,
*/
ws->state = WEBCLIENT_STATE_HEADERS;
- ws->internal_flags &= ~WGET_FLAG_CHUNKED;
+ ws->internal_flags &= ~(WGET_FLAG_CHUNKED |
+ WGET_FLAG_GOT_LOCATION);
ndx = 0;
break;
}
@@ -788,8 +790,14 @@ static inline int wget_parseheaders(struct webclient_context *ctx,
ws->line + strlen(g_httplocation));
ret = parseurl(ws->line + strlen(g_httplocation),
&ws->target, false);
+ if (ret != 0)
+ {
+ goto exit;
+ }
+
ninfo("New hostname='%s' filename='%s'\n",
ws->target.hostname, ws->target.filename);
+ ws->internal_flags |= WGET_FLAG_GOT_LOCATION;
found = true;
}
else if (strncasecmp(ws->line, g_httpcontsize,
@@ -1979,6 +1987,11 @@ int webclient_perform(FAR struct webclient_context *ctx)
FAR char *orig_buffer = ws->buffer;
int orig_buflen = ws->buflen;
+ if ((ws->internal_flags & WGET_FLAG_GOT_LOCATION) != 0)
+ {
+ nwarn("WARNING: Unexpected Location header\n");
+ }
+
if (ws->state == WEBCLIENT_STATE_CHUNKED_DATA)
{
uintmax_t chunk_left =
@@ -2052,6 +2065,13 @@ int webclient_perform(FAR struct webclient_context *ctx)
}
else
{
+ if ((ws->internal_flags & WGET_FLAG_GOT_LOCATION) == 0)
+ {
+ nerr("ERROR: Redirect w/o Location header\n");
+ ret = -EPROTO;
+ goto errout_with_errno;
+ }
+
ws->nredirect++;
if (ws->nredirect > CONFIG_WEBCLIENT_MAX_REDIRECT)
{
[incubator-nuttx-apps] 05/05: webclient: Clear WGET_FLAG_GOT_CONTENT_LENGTH for each request
Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 610b04fa97bfb6e200e21fc5952920def983aeed
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Mon Jun 6 18:04:06 2022 +0900
webclient: Clear WGET_FLAG_GOT_CONTENT_LENGTH for each request
Otherwise, a stale value might be used after a redirection.
---
netutils/webclient/webclient.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/netutils/webclient/webclient.c b/netutils/webclient/webclient.c
index e3763265a..4dc673021 100644
--- a/netutils/webclient/webclient.c
+++ b/netutils/webclient/webclient.c
@@ -577,7 +577,8 @@ static inline int wget_parsestatus(struct webclient_context *ctx,
*/
ws->state = WEBCLIENT_STATE_HEADERS;
- ws->internal_flags &= ~(WGET_FLAG_CHUNKED |
+ ws->internal_flags &= ~(WGET_FLAG_GOT_CONTENT_LENGTH |
+ WGET_FLAG_CHUNKED |
WGET_FLAG_GOT_LOCATION);
ndx = 0;
break;