shithub: opusfile

Download patch

ref: 01012058c9d39a5134799aaba263940cdd9bd38d
parent: cf594de6e8713d602ee6c4b01332155cbfac55c9
author: Timothy B. Terriberry <[email protected]>
date: Sun Sep 30 17:59:30 EDT 2012

Fix file: <host> comparison.

The previous comparison would have succeeded on things like
 "localhost123" instead of just "localhost".

--- a/src/http.c
+++ b/src/http.c
@@ -37,6 +37,17 @@
   return op_string_range_dup(_s,_s+strlen(_s));
 }
 
+static char *op_string_tolower(char *_s){
+  int i;
+  for(i=0;_s[i]!='\0';i++){
+    int c;
+    c=_s[i];
+    if(c>='A'&&c<='Z')c+='a'-'A';
+    _s[i]=(char)c;
+  }
+  return _s;
+}
+
 /*Is this an https URL?
   For now we can simply check the last letter.*/
 #define OP_URL_IS_SSL(_url) ((_url)->scheme[4]=='s')
@@ -153,8 +164,9 @@
     memcpy(host_buf,host,sizeof(*host_buf)*(host_end-host));
     host_buf[host_end-host]='\0';
     op_unescape_url_component(host_buf);
+    op_string_tolower(host_buf);
     /*Some other host: give up.*/
-    if(OP_UNLIKELY(op_strncasecmp(host_buf,"localhost",9)!=0))return NULL;
+    if(OP_UNLIKELY(strcmp(host_buf,"localhost")!=0))return NULL;
     path=host_end;
   }
   else path=scheme_end+1;
@@ -180,17 +192,6 @@
 # include <poll.h>
 # include <unistd.h>
 # include <openssl/ssl.h>
-
-static char *op_string_tolower(char *_s){
-  int i;
-  for(i=0;_s[i]!='\0';i++){
-    int c;
-    c=_s[i];
-    if(c>='A'&&c<='Z')c+='a'-'A';
-    _s[i]=(char)c;
-  }
-  return _s;
-}
 
 struct OpusParsedURL{
   /*Either "http" or "https".*/