History

git: disallow parsing sketchy names in packs

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.

Ori Bernstein committed 5 months ago

Commit c679fb11 parent f3f4ff71 file · +18 −0Browse files

Unified · Split

sys/src/cmd/git/pack.c+18−0
@@ -931,6 +931,22 @@ parsecommit(Object *o) · 930 unmodified lines
931 o->commit->nmsg = np;931 o->commit->nmsg = np;
932}932}
933 933
934static int
935validname(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
934static void950static void
935parsetree(Object *o)951parsetree(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))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t