ref: 55ddbff77d1274c028a3be5876ca1b28e090c322
parent: 15885866cb892152519882f7d661d1dba665d712
author: cinap_lenrek <[email protected]>
date: Thu Jul 19 19:34:37 EDT 2012
fix strchr \0 bugs
--- a/sys/src/cmd/mothra/rdhtml.c
+++ b/sys/src/cmd/mothra/rdhtml.c
@@ -243,7 +243,7 @@
char *e;
e=0;
- while(strchr("\n\r\t ", *src))
+ while(*src && strchr(" \t\r\n", *src))
src++;
if(*src=='\'' || *src=='"'){
e=strrchr(src+1, *src);
--- a/sys/src/cmd/uhtml.c
+++ b/sys/src/cmd/uhtml.c
@@ -5,6 +5,7 @@
int nbuf;
char buf[64*1024+1];
char *cset = nil;
+char *whitespace = " \t\r\n";
void
usage(void)
@@ -21,11 +22,11 @@
if((s = cistrstr(s, a)) == nil)
return nil;
s += strlen(a);
- while(strchr("\r\n\t ", *s))
+ while(*s && strchr(whitespace, *s))
s++;
if(*s++ != '=')
return nil;
- while(strchr("\r\n\t ", *s))
+ while(*s && strchr(whitespace, *s))
s++;
q = 0;
if(*s == '"' || *s == '\'')
--- a/sys/src/cmd/webfs/dat.h
+++ b/sys/src/cmd/webfs/dat.h
@@ -67,3 +67,4 @@
int debug;
Url *proxy;
int timeout;
+char *whitespace;
--- a/sys/src/cmd/webfs/fs.c
+++ b/sys/src/cmd/webfs/fs.c
@@ -613,7 +613,7 @@
else if(!strcmp(ctl, "headers")){
while(arg && *arg){
ctl = arg;
- while(*ctl && strchr("\r\n\t ", *ctl))
+ while(*ctl && strchr(whitespace, *ctl))
ctl++;
if(arg = strchr(ctl, '\n'))
*arg++ = 0;
@@ -663,9 +663,9 @@
n--;
s[n] = 0;
t = s;
- while(*t && strchr("\r\n\t ", *t)==0)
+ while(*t && strchr(whitespace, *t)==0)
t++;
- while(*t && strchr("\r\n\t ", *t))
+ while(*t && strchr(whitespace, *t))
*t++ = 0;
if(f->level == Qctl)
t = clientctl(f->client, s, t);
--- a/sys/src/cmd/webfs/http.c
+++ b/sys/src/cmd/webfs/http.c
@@ -274,9 +274,9 @@
if(n > 0 && cont){
e = h->buf + h->len;
for(y = x+1; y < e; y++)
- if(!strchr("\t ", *y))
+ if(*y != ' ' && *y != '\t')
break;
- if(y >= e || strchr("\t ", *y))
+ if(y >= e || *y == 0)
break;
if(y > x+1){
if(x > h->buf && x[-1] == '\r')
--- a/sys/src/cmd/webfs/sub.c
+++ b/sys/src/cmd/webfs/sub.c
@@ -8,6 +8,8 @@
#include "dat.h"
#include "fns.h"
+char *whitespace = " \t\r\n";
+
void*
emalloc(int n)
{
@@ -85,12 +87,14 @@
{
char *v;
+ if(*s == 0)
+ return nil;
v = strchr(s, 0)-1;
- while(v >= s && strchr("\n\r\t ", *v))
+ while(v >= s && strchr(whitespace, *v))
*v-- = 0;
if(v = strchr(s, ':')){
*v++ = 0;
- while(strchr("\t ", *v))
+ while(*v == ' ' || *v == '\t')
v++;
if(*s && *v)
return addkey(0, s, v);