Browse Source

Treat empty parameter value as an error.

If a URI parameter has an empty value, treat that as an immediate
general error (even if the parameter is not unrecognized and therefore
ignored) instead of dealing with it later.
master
Damien Goutte-Gattat 3 months ago
parent
commit
83e096379e
  1. 3
      src/secretcfg.c
  2. 5
      tests/t-parseuri.c

3
src/secretcfg.c

@ -205,6 +205,9 @@ parse_parameter(const char **uri, gfsec_share_t *share)
if ( ! (eq = strchr(*uri, '=')) || amp < eq )
return GFSEC_ERR_CONFIG_INVALID_URI; /* Missing value. */
if ( *(eq + 1) == '\0' || *(eq + 1) == '&' )
return GFSEC_ERR_CONFIG_INVALID_URI; /* Empty value. */
if ( strncmp(*uri, "share", eq - *uri) == 0 ) {
eq += 1;
if ( strncmp(eq, "no", amp - eq) == 0 )

5
tests/t-parseuri.c

@ -86,8 +86,8 @@ struct test tests[] = {
GFSEC_ERR_CONFIG_INVALID_URI },
/* Parameter with empty value. */
{ "file:///path/to/share.123?param=",
0, GFSEC_SCHEME_FILE, "", "/path/to/share.123", 123, 0 },
{ "file:///path/to/share.123?param=", GFSEC_ERR_CONFIG_INVALID_URI },
{ "file:///path/to/share.123?param1=&param2=val", GFSEC_ERR_CONFIG_INVALID_URI },
/* Handling the share parameter. */
{ "file:///path/to/share?share=no",
@ -106,7 +106,6 @@ struct test tests[] = {
0, GFSEC_SCHEME_FILE, "", "/path/to/share.123", 124, 0 },
/* Hash with invalid length. */
{ "file:///path/to/share.123?sha256=", GFSEC_ERR_CONFIG_INVALID_HASH },
{ "file:///path/to/share.123?sha256=decafbad", GFSEC_ERR_CONFIG_INVALID_HASH },
{ "file:///path/to/share.123?sha256="
"decafbaddecafbaddecafbaddecafbaddecafbaddecafbaddecafbaddecafbadd",

Loading…
Cancel
Save