[w3m-dev 04237] [patch] cookie avoid [wrong number of dots]

[email protected] Tue, 15 May 2007 11:23:46 +0900
Newsgroups gmane.comp.web.w3m.devel
Message-ID <[email protected]>
dai 



This cookie was rejected to prevent security violation.
[wrong number of dots]



 , 

 mywiki.jp,wiki.livedoor.jp 
 Wiki 


Regards,
-- 
	dai

diff -urN w3m-0.5.1+1.946-ORIG/fm.h w3m-0.5.1+1.946/fm.h
--- w3m-0.5.1+1.946-ORIG/fm.h	2004-07-16 01:44:37.000000000 +0900
+++ w3m-0.5.1+1.946/fm.h	2005-09-16 11:39:20.000000000 +0900
@@ -1083,8 +1083,10 @@
 global int accept_bad_cookie init(ACCEPT_BAD_COOKIE_DISCARD);
 global char *cookie_reject_domains init(NULL);
 global char *cookie_accept_domains init(NULL);
+global char *cookie_avoid_wrong_number_of_dots init(NULL);
 global TextList *Cookie_reject_domains;
 global TextList *Cookie_accept_domains;
+global TextList *Cookie_avoid_wrong_number_of_dots_domains;
 #endif				/* USE_COOKIE */
 
 #ifdef USE_IMAGE
diff -urN w3m-0.5.1+1.946-ORIG/rc.c w3m-0.5.1+1.946/rc.c
--- w3m-0.5.1+1.946-ORIG/rc.c	2004-08-03 00:40:50.000000000 +0900
+++ w3m-0.5.1+1.946/rc.c	2005-09-16 11:51:46.000000000 +0900
@@ -196,6 +196,7 @@
 #define CMT_ACCEPTBADCOOKIE N_("Action to be taken on invalid cookie")
 #define CMT_COOKIE_REJECT_DOMAINS N_("Domains to reject cookies from")
 #define CMT_COOKIE_ACCEPT_DOMAINS N_("Domains to accept cookies from")
+#define CMT_COOKIE_AVOID_WONG_NUMBER_OF_DOTS N_("Domains to avoid [wrong number of dots]")
 #endif
 #define CMT_FOLLOW_REDIRECTION N_("Number of redirections to follow")
 #define CMT_META_REFRESH N_("Enable processing of meta-refresh tag")
@@ -560,6 +561,9 @@
      (void *)&cookie_reject_domains, CMT_COOKIE_REJECT_DOMAINS, NULL},
     {"cookie_accept_domains", P_STRING, PI_TEXT,
      (void *)&cookie_accept_domains, CMT_COOKIE_ACCEPT_DOMAINS, NULL},
+    {"cookie_avoid_wrong_number_of_dots", P_STRING, PI_TEXT,
+     (void *)&cookie_avoid_wrong_number_of_dots,
+     CMT_COOKIE_AVOID_WONG_NUMBER_OF_DOTS, NULL},
     {NULL, 0, 0, NULL, NULL, NULL},
 };
 #endif
@@ -1090,6 +1094,9 @@
 	Cookie_reject_domains = make_domain_list(cookie_reject_domains);
     if (non_null(cookie_accept_domains))
 	Cookie_accept_domains = make_domain_list(cookie_accept_domains);
+    if (non_null(cookie_avoid_wrong_number_of_dots))
+	Cookie_avoid_wrong_number_of_dots_domains
+	       	= make_domain_list(cookie_avoid_wrong_number_of_dots);
 }
 #endif
 
diff -urN w3m-cvs1.977/cookie.c w3m/cookie.c
--- w3m-cvs1.977/cookie.c	2007-01-23 11:16:10.000000000 +0900
+++ w3m/cookie.c	2007-05-15 02:43:56.000000000 +0900
@@ -258,6 +258,30 @@
 };
 
 int
+check_avoid_wrong_number_of_dots_domain( Str domain )
+{
+   TextListItem *tl;
+    int avoid_wrong_number_of_dots_domain = FALSE;
+
+    if (Cookie_avoid_wrong_number_of_dots_domains && 
+            Cookie_avoid_wrong_number_of_dots_domains->nitem > 0) {
+        for (tl = Cookie_avoid_wrong_number_of_dots_domains->first;
+                tl != NULL; tl = tl->next) {
+            if (domain_match(domain->ptr, tl->ptr)) {
+                avoid_wrong_number_of_dots_domain = TRUE;
+                break;
+            }
+        }
+    }
+
+    if (avoid_wrong_number_of_dots_domain == TRUE) {
+        return TRUE;
+    } else {
+        return FALSE;
+    }
+}
+
+int
 add_cookie(ParsedURL *pu, Str name, Str value,
 	   time_t expires, Str domain, Str path,
 	   int flag, Str comment, int version, Str port, Str commentURL)
@@ -304,7 +328,11 @@
 				     domain->ptr + domain->length,
 				     3);
 	    if (n < 2) {
-		COOKIE_ERROR(COO_ESPECIAL);
+		if ( check_avoid_wrong_number_of_dots_domain(domain) ) {
+		    ;
+		} else {
+		    COOKIE_ERROR(COO_ESPECIAL);
+		}
 	    }
 	    else if (n == 2) {
 		char **sdomain;
@@ -315,8 +343,13 @@
 			strcasecmp(*sdomain, &domain->ptr[offset]) == 0)
 			ok = 1;
 		}
-		if (!ok)
-		    COOKIE_ERROR(COO_ESPECIAL);
+		if (!ok) {
+		    if ( check_avoid_wrong_number_of_dots_domain(domain) ) {
+		        ;
+		    } else {
+		        COOKIE_ERROR(COO_ESPECIAL);
+		    }
+		}
 	    }
 	}
 	else {