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

Showing the changes to sys/src/cmd/git (1 of 1 file). Show all

Unified · Split

sys/src/cmd/git/pack.c+18−0
@@ -931,6 +931,22 @@ parsecommit(Object *o) · 930 unmodified lines
931931 o->commit->nmsg = np;
932932 }
933933
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+
934950 static void
935951 parsetree(Object *o)
936952 {
@@ -978,6 +994,8 @@ parsetree(Object *o) · 41 unmodified lines
978994 }
979995 if(m & 0040000) /* dir */
980996 t->mode |= DMDIR;
997+ if(!validname(p))
998+ sysfatal("invalid entry: %r");
981999 t->name = p;
9821000 p = memchr(p, 0, ep - p);
9831001 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