|
31 | 31 | cjose_jws_t * |
32 | 32 | get_jws_from_uri(const char *uri, size_t uri_ct, const char *paramName) |
33 | 33 | { |
| 34 | + /* Reserved characters as defined by the URI Generic Syntax RFC: https://tools.ietf.org/html/rfc3986#section-2.2 */ |
34 | 35 | const char *reserved_string = ":/?#[]@!$&\'()*+,;="; |
35 | 36 |
|
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 |
37 | 38 | * '='. */ |
38 | 39 | char termination_symbol; |
39 | 40 | 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; |
43 | 51 | } else { |
44 | 52 | termination_symbol = '='; |
45 | | - termination_ct = strlen(paramName); |
| 53 | + termination_ct = param_ct; |
46 | 54 | } |
47 | 55 |
|
48 | 56 | 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) |
74 | 82 | key_end = value; |
75 | 83 |
|
76 | 84 | /* 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))) { |
78 | 86 | value_end = ++value; |
79 | 87 | while (value_end != end && strchr(reserved_string, *value_end) == NULL) { |
80 | 88 | ++value_end; |
|
0 commit comments