]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/ip/torrent.c
[9front] walk: properly format permissions
[plan9front.git] / sys / src / cmd / ip / torrent.c
index 5ce321b4cae1900bed4ba74a2638757b65c8c5cf..374fd97ad67bc158b3b20643983233b16002fad6 100644 (file)
@@ -295,7 +295,7 @@ unpack(uchar *s, int n, char *fmt, ...)
                        s += 4;
                        break;
                case 'v':
-                       if(s+4 > e) goto Err;
+                       if(s+8 > e) goto Err;
                        *va_arg(arg, vlong*) = 
                                (vlong)s[0]<<56 | 
                                (vlong)s[1]<<48 | 
@@ -605,7 +605,7 @@ server(void)
 
        afd = -1;
        nprocs = 0;
-       for(port=6881; port<6890; port++){
+       for(port=6881; port<9000; port++){
                snprint(addr, sizeof(addr), "tcp!*!%d", port);
                if((afd = announce(addr, adir)) >= 0)
                        break;
@@ -811,7 +811,8 @@ Error:
                        }
                }
        }
-       havepiece(off / blocksize, w->str);
+       if(off < f->off + f->len)
+               havepiece(off / blocksize, w->str);
        havepiece(f->off / blocksize, w->str);
        close(fd);
        exits(0);
@@ -906,7 +907,7 @@ udpaddr(char addr[64], int naddr, char *url)
                if((x = strchr(url, '/')) == nil)
                        x = strchr(url, 0);
        }
-       snprint(addr, naddr, "udp!%.*s!%d", (int)(x-url), url, port);
+       snprint(addr, naddr, "udp!%.*s!%d", utfnlen(url, x-url), url, port);
        return 0;
 }