Add 88 new defect entries to HIGH and MEDIUM tables:
HIGH: mysql-0001/0002, mariadb-0001, redis-0001/0002, valkey-0001/0002, openvpn-0001,
vlc-0001, prometheus-0001, otel-collector-0001, cockroachdb-0001..0004,
tidb-0001..0008, kubernetes-0001/0002, go-0001, kotlin-0002, scala-0001,
allegro5-0001, sdl2-0001, grafana-0001, clickhouse-0001, duckdb-0001,
mongodb-0001, envoy-0001, istio-0001, cilium-0001, linkerd2-0001,
linux-0001/0002/0003, tor-0002/0003, curl-0001, julia-0001, lua-0001,
perl5-0001, nats-0001, spring-0003/0004, tomcat-0001, onos-0002, odl-0002
MEDIUM: helm-0001, mariadb-0002, openssl-0001/0002, memcached-0001,
cassandra-0001..0004, flink-0001, storm-0001/0002, zookeeper-0001..0003,
pip-0001, gradle-0001, nginx-0001, haproxy-0001, caddy-0001, varnish-0001,
ffmpeg-0001, gstreamer-0001, raylib-0001, love2d-0001, php-0001/0002,
r-source-0001, cpython-0002, ruby-0001, rabbitmq-0003/0004, activemq-0001,
ovs-0001, onos-0003, odl-0002, jetty-0001
PDF: 976K
96 lines
3.7 KiB
Diff
96 lines
3.7 KiB
Diff
diff --git a/lib/cookie.h b/lib/cookie.h
|
|
index abc1234..def5678 100644
|
|
--- a/lib/cookie.h
|
|
+++ b/lib/cookie.h
|
|
@@ -52,6 +52,7 @@
|
|
#define COOKIE_HASH_SIZE 63
|
|
|
|
struct CookieInfo {
|
|
+ struct Curl_hash name2node[COOKIE_HASH_SIZE]; /* CWE-407 fix: name→node per bucket */
|
|
struct Curl_llist cookielist[COOKIE_HASH_SIZE]; /* hash-indexed cookie lists */
|
|
time_t next_expiration; /* the next cookie to expire */
|
|
int numcookies; /* number of cookies in the jar */
|
|
|
|
diff --git a/lib/cookie.c b/lib/cookie.c
|
|
index abc1234..def5678 100644
|
|
--- a/lib/cookie.c
|
|
+++ b/lib/cookie.c
|
|
@@ -818,17 +818,43 @@ psl_check_cookie_for_domain(struct Curl_easy *data,
|
|
/* returns TRUE when replaced */
|
|
static bool replace_existing(struct Curl_easy *data,
|
|
struct Cookie *co,
|
|
struct CookieInfo *ci,
|
|
bool secure,
|
|
bool *replacep)
|
|
{
|
|
bool replace_old = FALSE;
|
|
struct Curl_llist_node *replace_n = NULL;
|
|
- struct Curl_llist_node *n;
|
|
size_t myhash = cookiehash(co->domain);
|
|
- for(n = Curl_llist_head(&ci->cookielist[myhash]); n; n = Curl_node_next(n)) {
|
|
- struct Cookie *clist = Curl_node_elem(n);
|
|
- if(!strcmp(clist->name, co->name)) {
|
|
+
|
|
+ /*
|
|
+ * CWE-407 fix: look up the candidate node by name in O(1) via the per-bucket
|
|
+ * name→node hash index, instead of walking the full linked list O(C) per call.
|
|
+ *
|
|
+ * Old: for each of C cookies in bucket, strcmp(clist->name, co->name) → O(C)
|
|
+ * New: Curl_hash_pick(&ci->name2node[myhash], co->name, namelen) → O(1)
|
|
+ *
|
|
+ * The hash maps cookie name to the llist_node so we jump directly to the
|
|
+ * candidate and do the domain/path validation only for that node.
|
|
+ */
|
|
+ size_t namelen = strlen(co->name);
|
|
+ struct Curl_llist_node *candidate =
|
|
+ Curl_hash_pick(&ci->name2node[myhash], co->name, namelen + 1);
|
|
+
|
|
+ if(candidate) {
|
|
+ struct Curl_llist_node *n = candidate;
|
|
+ {
|
|
+ struct Cookie *clist = Curl_node_elem(n);
|
|
/* the names are identical */
|
|
bool matching_domains = FALSE;
|
|
|
|
@@ -920,6 +946,10 @@ replace_existing(struct Curl_easy *data,
|
|
if(replace_n) {
|
|
struct Cookie *repl = Curl_node_elem(replace_n);
|
|
|
|
+ /* Remove from name index before freeing */
|
|
+ size_t rnamelen = strlen(repl->name);
|
|
+ Curl_hash_delete(&ci->name2node[myhash], repl->name, rnamelen + 1);
|
|
+
|
|
/* when replacing, creationtime is kept from old */
|
|
co->creationtime = repl->creationtime;
|
|
|
|
@@ -1035,6 +1065,10 @@ Curl_cookie_add(struct Curl_easy *data,
|
|
/* add this cookie to the list */
|
|
myhash = cookiehash(co->domain);
|
|
Curl_llist_append(&ci->cookielist[myhash], co, &co->node);
|
|
+ /* CWE-407 fix: update name index with the new node */
|
|
+ size_t addnamelen = strlen(co->name);
|
|
+ Curl_hash_add(&ci->name2node[myhash], co->name, addnamelen + 1, &co->node);
|
|
|
|
if(ci->running)
|
|
/* Only show this when NOT reading the cookies from a file */
|
|
@@ -1145,6 +1179,10 @@ Curl_cookie_cleanup(struct CookieInfo *ci)
|
|
if(ci) {
|
|
for(i = 0; i < COOKIE_HASH_SIZE; i++) {
|
|
Curl_llist_destroy(&ci->cookielist[i], NULL);
|
|
+ /* CWE-407 fix: destroy per-bucket name hash */
|
|
+ Curl_hash_destroy(&ci->name2node[i]);
|
|
}
|
|
free(ci);
|
|
}
|
|
@@ -115,6 +115,10 @@ Curl_cookie_init(void)
|
|
struct CookieInfo *ci = calloc(1, sizeof(struct CookieInfo));
|
|
if(ci) {
|
|
int i;
|
|
+ /* CWE-407 fix: initialize per-bucket name→node hash indices */
|
|
+ for(i = 0; i < COOKIE_HASH_SIZE; i++) {
|
|
+ Curl_hash_init(&ci->name2node[i], 7, Curl_hash_str, Curl_str_key_compare,
|
|
+ NULL);
|
|
+ }
|
|
for(i = 0; i < COOKIE_HASH_SIZE; i++)
|
|
Curl_llist_init(&ci->cookielist[i], NULL);
|
|
}
|