]> git.lizzy.rs Git - plan9front.git/commitdiff
webfs: nstrcpy paranoia
authorcinap_lenrek <cinap_lenrek@gmx.de>
Fri, 18 May 2012 18:25:50 +0000 (20:25 +0200)
committercinap_lenrek <cinap_lenrek@gmx.de>
Fri, 18 May 2012 18:25:50 +0000 (20:25 +0200)
sys/src/cmd/webfs/fns.h
sys/src/cmd/webfs/fs.c
sys/src/cmd/webfs/http.c
sys/src/cmd/webfs/sub.c

index 747ebd7293923f2d9e7d3ad4108434e3657aaf1c..9cd6f2ae2b0ec972cd30e240cf3e82ca3142230f 100644 (file)
@@ -2,6 +2,8 @@
 void*  emalloc(int n);
 char*  estrdup(char *s);
 
+void   nstrcpy(char *to, char *from, int n);
+
 Key*   addkey(Key *h, char *key, char *val);
 Key*   delkey(Key *h, char *key);
 char*  lookkey(Key *k, char *key);
index 2d2c7c0633955028858c06940692e4c606e048d7..ab21bce7a8592b067a41f7e78034e793ea1acd81 100644 (file)
@@ -310,7 +310,7 @@ fswalk1(Fid *fid, char *name, Qid *qid)
                                Key *k;
 
                                for(k = f->client->qbody->hdr; k; k = k->next){
-                                       strncpy(buf, k->key, sizeof(buf));
+                                       nstrcpy(buf, k->key, sizeof(buf));
                                        if(!strcmp(name, fshdrname(buf)))
                                                break;
                                }
@@ -598,7 +598,7 @@ clientctl(Client *cl, char *ctl, char *arg)
        }
        else if(!strcmp(ctl, "request")){
                p = cl->request;
-               strncpy(p, arg, sizeof(cl->request));
+               nstrcpy(p, arg, sizeof(cl->request));
                for(; *p && isalpha(*p); p++)
                        *p = toupper(*p);
                *p = 0;
@@ -624,7 +624,7 @@ clientctl(Client *cl, char *ctl, char *arg)
                        nil,
                };
                for(t = tab; *t; t++){
-                       strncpy(buf, *t, sizeof(buf));
+                       nstrcpy(buf, *t, sizeof(buf));
                        if(!strcmp(ctl, fshdrname(buf))){
                                cl->hdr = delkey(cl->hdr, *t);
                                if(arg && *arg)
index 423aab124a038698ba50776d395031a90ac750a0..9b951e4fe0d1a601cc336aa7d7e352d3580ef90c 100644 (file)
@@ -108,7 +108,7 @@ hdial(Url *u)
        h->keep = 1;
        h->len = 0;
        h->fd = fd;
-       strncpy(h->addr, addr, sizeof(h->addr));
+       nstrcpy(h->addr, addr, sizeof(h->addr));
 
        return h;
 }
@@ -441,7 +441,7 @@ http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost)
 
        incref(qbody);
        if(qpost) incref(qpost);
-       strncpy(method, m, sizeof(method));
+       nstrcpy(method, m, sizeof(method));
        switch(rfork(RFPROC|RFMEM|RFNOWAIT)){
        default:
                return;
@@ -640,7 +640,7 @@ http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost)
                                        if(cistrcmp(s, "ICY"))
                                                break;
                                }
-                               strncpy(status, x, sizeof(status));
+                               nstrcpy(status, x, sizeof(status));
                                continue;
                        }
                        if((k = parsehdr(s)) == nil)
@@ -730,7 +730,7 @@ http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost)
                                qpost = nil;
                        }
                        if(cistrcmp(method, "HEAD"))
-                               strncpy(method, "GET", sizeof(method));
+                               nstrcpy(method, "GET", sizeof(method));
                case 301:       /* Moved Permanently */
                case 307:       /* Temporary Redirect */
                case 308:       /* Resume Incomplete */
index 274ef0b089942f151572b71f34a00790f970520e..b8ca1e3ac613299b9c9d65538579ddf8bdd08652 100644 (file)
@@ -26,6 +26,13 @@ estrdup(char *s)
        return s;
 }
 
+void
+nstrcpy(char *to, char *from, int n)
+{
+       strncpy(to, from, n);
+       to[n-1] = 0;
+}
+
 Key*
 addkey(Key *h, char *key, char *val)
 {