summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--content/urldb.c12
-rw-r--r--test/urldbtest.c5
2 files changed, 13 insertions, 4 deletions
diff --git a/content/urldb.c b/content/urldb.c
index ef0222d2e..67ba5701d 100644
--- a/content/urldb.c
+++ b/content/urldb.c
@@ -2954,7 +2954,7 @@ struct cookie_internal_data *urldb_parse_cookie(const char *url,
assert(url && cookie && *cookie);
c = calloc(1, sizeof(struct cookie_internal_data));
- if (!c)
+ if (c == NULL)
return NULL;
c->expires = -1;
@@ -3140,7 +3140,7 @@ struct cookie_internal_data *urldb_parse_cookie(const char *url,
}
/* Now fix-up default values */
- if (!c->domain) {
+ if (c->domain == NULL) {
res = url_host(url, &c->domain);
if (res != URL_FUNC_OK) {
urldb_free_cookie(c);
@@ -3148,7 +3148,7 @@ struct cookie_internal_data *urldb_parse_cookie(const char *url,
}
}
- if (!c->path) {
+ if (c->path == NULL) {
char *path;
char *slash;
@@ -3160,7 +3160,11 @@ struct cookie_internal_data *urldb_parse_cookie(const char *url,
/* Strip leafname and trailing slash (4.3.1) */
slash = strrchr(path, '/');
- if (slash) {
+ if (slash != NULL) {
+ /* Special case: retain first slash in path */
+ if (slash == path)
+ slash++;
+
slash = strndup(path, slash - path);
if (slash == NULL) {
free(path);
diff --git a/test/urldbtest.c b/test/urldbtest.c
index 4d9737a1b..3de24f3be 100644
--- a/test/urldbtest.c
+++ b/test/urldbtest.c
@@ -190,6 +190,11 @@ int main(void)
assert(urldb_set_cookie("name=value\r\n", "http://www.example.org/foo/bar/baz/bat.html", NULL));
assert(urldb_get_cookie("http://www.example.org/foo/bar/baz/quux.htm"));
+ /* Defaulted path with no non-leaf path segments */
+ assert(urldb_set_cookie("name=value\r\n", "http://no-non-leaf.example.org/index.html", NULL));
+ assert(urldb_get_cookie("http://no-non-leaf.example.org/page2.html"));
+ assert(urldb_get_cookie("http://no-non-leaf.example.org/"));
+
/* Valid path (includes leafname) */
assert(urldb_set_cookie("name=value;Version=1;Path=/index.cgi\r\n", "http://example.org/index.cgi", NULL));
assert(urldb_get_cookie("http://example.org/index.cgi"));