mirror of
https://github.com/golang/go
synced 2024-11-22 01:04:40 -07:00
gopack: preserve safe flag when not adding unsafe objects to archive
R=dsymonds CC=golang-dev https://golang.org/cl/4436060
This commit is contained in:
parent
c3e6e6ec09
commit
5eeaca12d3
@ -144,6 +144,7 @@ char *file; /* current file or member being worked on */
|
|||||||
Biobuf bout;
|
Biobuf bout;
|
||||||
Biobuf bar;
|
Biobuf bar;
|
||||||
char *prefix;
|
char *prefix;
|
||||||
|
int pkgdefsafe; /* was __.PKGDEF marked safe? */
|
||||||
|
|
||||||
void arcopy(Biobuf*, Arfile*, Armember*);
|
void arcopy(Biobuf*, Arfile*, Armember*);
|
||||||
int arcreate(char*);
|
int arcreate(char*);
|
||||||
@ -177,6 +178,7 @@ void scanpkg(Biobuf*, long);
|
|||||||
void select(int*, long);
|
void select(int*, long);
|
||||||
void setcom(void(*)(char*, int, char**));
|
void setcom(void(*)(char*, int, char**));
|
||||||
void skip(Biobuf*, vlong);
|
void skip(Biobuf*, vlong);
|
||||||
|
void checksafe(Biobuf*, vlong);
|
||||||
int symcomp(void*, void*);
|
int symcomp(void*, void*);
|
||||||
void trim(char*, char*, int);
|
void trim(char*, char*, int);
|
||||||
void usage(void);
|
void usage(void);
|
||||||
@ -322,9 +324,9 @@ rcmd(char *arname, int count, char **files)
|
|||||||
skip(&bar, bp->size);
|
skip(&bar, bp->size);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* pitch pkgdef file */
|
/* pitch pkgdef file but remember whether it was marked safe */
|
||||||
if (gflag && strcmp(file, pkgdef) == 0) {
|
if (gflag && strcmp(file, pkgdef) == 0) {
|
||||||
skip(&bar, bp->size);
|
checksafe(&bar, bp->size);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -773,6 +775,7 @@ scanpkg(Biobuf *b, long size)
|
|||||||
goto foundstart;
|
goto foundstart;
|
||||||
}
|
}
|
||||||
// fprint(2, "gopack: warning: no package import section in %s\n", file);
|
// fprint(2, "gopack: warning: no package import section in %s\n", file);
|
||||||
|
if(b != &bar || !pkgdefsafe)
|
||||||
safe = 0; // non-Go file (C or assembly)
|
safe = 0; // non-Go file (C or assembly)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -807,7 +810,7 @@ foundstart:
|
|||||||
pkgname = armalloc(pkg - data + 1);
|
pkgname = armalloc(pkg - data + 1);
|
||||||
memmove(pkgname, data, pkg - data);
|
memmove(pkgname, data, pkg - data);
|
||||||
pkgname[pkg-data] = '\0';
|
pkgname[pkg-data] = '\0';
|
||||||
if(strcmp(pkg, " safe\n") != 0)
|
if(strcmp(pkg, " safe\n") != 0 && (b != &bar || !pkgdefsafe))
|
||||||
safe = 0;
|
safe = 0;
|
||||||
start = Boffset(b); // after package statement
|
start = Boffset(b); // after package statement
|
||||||
first = 0;
|
first = 0;
|
||||||
@ -1094,6 +1097,36 @@ skip(Biobuf *bp, vlong len)
|
|||||||
Bseek(bp, len, 1);
|
Bseek(bp, len, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
checksafe(Biobuf *bp, vlong len)
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
vlong end;
|
||||||
|
|
||||||
|
if (len & 01)
|
||||||
|
len++;
|
||||||
|
end = Boffset(bp) + len;
|
||||||
|
|
||||||
|
p = Brdline(bp, '\n');
|
||||||
|
if(p == nil || strncmp(p, "go object ", 10) != 0)
|
||||||
|
goto done;
|
||||||
|
for(;;) {
|
||||||
|
p = Brdline(bp, '\n');
|
||||||
|
if(p == nil || Boffset(bp) >= end)
|
||||||
|
goto done;
|
||||||
|
if(strncmp(p, "$$\n", 3) == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
p = Brdline(bp, '\n');
|
||||||
|
if(p == nil || Boffset(bp) > end)
|
||||||
|
goto done;
|
||||||
|
if(Blinelen(bp) > 8+6 && strncmp(p, "package ", 8) == 0 && strncmp(p+Blinelen(bp)-6, " safe\n", 6) == 0)
|
||||||
|
pkgdefsafe = 1;
|
||||||
|
|
||||||
|
done:
|
||||||
|
Bseek(bp, end, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stream the three temp files to an archive
|
* Stream the three temp files to an archive
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user