while this is not, as far as I'm aware, a security issue because the kernel validates the path elements, we should bail and make it systematically impossible to see '../../etc/shadow' and similar.
Unified · Split
| @@ -931,6 +931,22 @@ parsecommit(Object *o) · 930 unmodified lines | |||
| 931 | o->commit->nmsg = np; | 931 | o->commit->nmsg = np; |
| 932 | } | 932 | } |
| 933 | 933 | ||
| 934 | static int | ||
| 935 | validname(char *s) | ||
| 936 | { | ||
| 937 | if(*s == 0) | ||
| 938 | return 0; | ||
| 939 | if(strcmp(s, ".") == 0 || strcmp(s, "..") == 0) | ||
| 940 | return 0; | ||
| 941 | for(; *s; s++){ | ||
| 942 | if((*s&0xff) < 0x20 || *s == 0x7f || *s == '/'){ | ||
| 943 | werrstr("invalid character in sath: %02x", *(uchar*)s); | ||
| 944 | return 0; | ||
| 945 | } | ||
| 946 | } | ||
| 947 | return 1; | ||
| 948 | } | ||
| 949 | |||
| 934 | static void | 950 | static void |
| 935 | parsetree(Object *o) | 951 | parsetree(Object *o) |
| 936 | { | 952 | { |
| @@ -978,6 +994,8 @@ parsetree(Object *o) · 41 unmodified lines | |||
| 978 | } | 994 | } |
| 979 | if(m & 0040000) /* dir */ | 995 | if(m & 0040000) /* dir */ |
| 980 | t->mode |= DMDIR; | 996 | t->mode |= DMDIR; |
| 997 | if(!validname(p)) | ||
| 998 | sysfatal("invalid entry: %r"); | ||
| 981 | t->name = p; | 999 | t->name = p; |
| 982 | p = memchr(p, 0, ep - p); | 1000 | p = memchr(p, 0, ep - p); |
| 983 | if(p == nil || *p++ != 0 || ep - p < sizeof(t->h.h)) | 1001 | if(p == nil || *p++ != 0 || ep - p < sizeof(t->h.h)) |