Skip to content

Commit aa5337e

Browse files
rootDylan Souza
authored andcommitted
Implementing suggestions from PR review
1 parent bb2f87e commit aa5337e

File tree

1 file changed

+14
-6
lines changed
  • plugins/experimental/uri_signing

1 file changed

+14
-6
lines changed

plugins/experimental/uri_signing/parse.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,26 @@
3131
cjose_jws_t *
3232
get_jws_from_uri(const char *uri, size_t uri_ct, const char *paramName)
3333
{
34+
/* Reserved characters as defined by the URI Generic Syntax RFC: https://tools.ietf.org/html/rfc3986#section-2.2 */
3435
const char *reserved_string = ":/?#[]@!$&\'()*+,;=";
3536

36-
/* If param name ends in reserved character this will be treated as the termination sybmol when parsing for package. Default is
37+
/* If param name ends in reserved character this will be treated as the termination symbol when parsing for package. Default is
3738
* '='. */
3839
char termination_symbol;
3940
size_t termination_ct;
40-
if (strchr(reserved_string, paramName[strlen(paramName) - 1])) {
41-
termination_symbol = paramName[strlen(paramName) - 1];
42-
termination_ct = strlen(paramName) + 1;
41+
size_t param_ct = strlen(paramName);
42+
43+
if (param_ct <= 0) {
44+
PluginDebug("URI signing package name cannot be empty");
45+
return NULL;
46+
}
47+
48+
if (strchr(reserved_string, paramName[param_ct - 1])) {
49+
termination_symbol = paramName[param_ct - 1];
50+
termination_ct = param_ct - 1;
4351
} else {
4452
termination_symbol = '=';
45-
termination_ct = strlen(paramName);
53+
termination_ct = param_ct;
4654
}
4755

4856
PluginDebug("Parsing JWS from query string: %.*s", (int)uri_ct, uri);
@@ -74,7 +82,7 @@ get_jws_from_uri(const char *uri, size_t uri_ct, const char *paramName)
7482
key_end = value;
7583

7684
/* If the Parameter key is our target parameter name, attempt to import a JWS from the value. */
77-
if (!strncmp(paramName, key, (size_t)(key_end - key)) && (size_t)(key_end - key) == termination_ct) {
85+
if ((size_t)(key_end - key) == termination_ct && !strncmp(paramName, key, (size_t)(key_end - key))) {
7886
value_end = ++value;
7987
while (value_end != end && strchr(reserved_string, *value_end) == NULL) {
8088
++value_end;

0 commit comments

Comments
 (0)