diff --git a/include/libwebsockets/lws-http.h b/include/libwebsockets/lws-http.h index 41628da48..82bda9ed6 100644 --- a/include/libwebsockets/lws-http.h +++ b/include/libwebsockets/lws-http.h @@ -436,7 +436,7 @@ lws_hdr_copy(struct lws *wsi, char *dest, int len, enum lws_token_indexes h); /** * lws_hdr_copy_fragment() - copy a single fragment of the given header to a buffer * The buffer length len must include space for an additional - * terminating '\0', or it will fail returning -1. + * terminating '\0', or it will fail returning -2. * If the requested fragment index is not present, it fails * returning -1. * diff --git a/lib/core-net/wsi.c b/lib/core-net/wsi.c index ce8c5294c..b4a17ce32 100644 --- a/lib/core-net/wsi.c +++ b/lib/core-net/wsi.c @@ -746,10 +746,11 @@ lws_get_urlarg_by_name_safe(struct lws *wsi, const char *name, char *buf, int le fraglen = lws_hdr_copy_fragment(wsi, buf, len, WSI_TOKEN_HTTP_URI_ARGS, n); - if (fraglen < 0) + if (fraglen == -1) /* no fragment or basic problem */ break; - if (fraglen + 1 < len && + if (fraglen > 0 && /* fragment could fit */ + fraglen + 1 < len && fraglen >= sl && !strncmp(buf, name, (size_t)sl)) { /* diff --git a/lib/roles/http/parsers.c b/lib/roles/http/parsers.c index 220f9cf82..717390151 100644 --- a/lib/roles/http/parsers.c +++ b/lib/roles/http/parsers.c @@ -520,7 +520,7 @@ int lws_hdr_copy_fragment(struct lws *wsi, char *dst, int len, } if (wsi->http.ah->frags[f].len >= len) - return -1; + return -2; memcpy(dst, wsi->http.ah->data + wsi->http.ah->frags[f].offset, wsi->http.ah->frags[f].len);