mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-03 01:38:30 +00:00
Improve ZIP filesystem and change its prefix
The ZIP filesystem has a breaking change. You now need to use /zip/ to open() / opendir() / etc. assets within the ZIP structure of your APE binary, instead of the previous convention of using zip: or zip! URIs. This is needed because Python likes to use absolute paths, and having ZIP paths encoded like URIs simply broke too many things. Many more system calls have been updated to be able to operate on ZIP files and file descriptors. In particular fcntl() and ioctl() since Python would do things like ask if a ZIP file is a terminal and get confused when the old implementation mistakenly said yes, because the fastest way to guarantee native file descriptors is to dup(2). This change also improves the async signal safety of zipos and ensures it doesn't maintain any open file descriptors beyond that which the user has opened. This change makes a lot of progress towards adding magic numbers that are specific to platforms other than Linux. The philosophy here is that, if you use an operating system like FreeBSD, then you should be able to take advantage of FreeBSD exclusive features, even if we don't polyfill them on other platforms. For example, you can now open() a file with the O_VERIFY flag. If your program runs on other platforms, then Cosmo will automatically set O_VERIFY to zero. This lets you safely use it without the need for #ifdef or ifstatements which detract from readability. One of the blindspots of the ASAN memory hardening we use to offer Rust like assurances has always been that memory passed to the kernel via system calls (e.g. writev) can't be checked automatically since the kernel wasn't built with MODE=asan. This change makes more progress ensuring that each system call will verify the soundness of memory before it's passed to the kernel. The code for doing these checks is fast, particularly for buffers, where it can verify 64 bytes a cycle. - Correct O_LOOP definition on NT - Introduce program_executable_name - Add ASAN guards to more system calls - Improve termios compatibility with BSDs - Fix bug in Windows auxiliary value encoding - Add BSD and XNU specific errnos and open flags - Add check to ensure build doesn't talk to internet
This commit is contained in:
parent
2730c66f4a
commit
00611e9b06
319 changed files with 4418 additions and 2599 deletions
274
third_party/musl/pwd.c
vendored
274
third_party/musl/pwd.c
vendored
|
@ -1,5 +1,5 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set et ft=c ts=2 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
|
@ -36,153 +36,179 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
#define PTHREAD_CANCEL_DISABLE 0
|
||||
#define pthread_setcancelstate(x, y) (void)y
|
||||
|
||||
static unsigned atou(char **s) {
|
||||
unsigned x;
|
||||
for (x = 0; **s - '0' < 10U; ++*s) x = 10 * x + (**s - '0');
|
||||
return x;
|
||||
static unsigned
|
||||
atou(char **s)
|
||||
{
|
||||
unsigned x;
|
||||
for (x = 0; **s - '0' < 10U; ++*s) {
|
||||
x = 10 * x + (**s - '0');
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
static int __getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size,
|
||||
struct passwd **res) {
|
||||
ssize_t l;
|
||||
char *s;
|
||||
int rv = 0;
|
||||
int cs;
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
|
||||
for (;;) {
|
||||
if ((l = getline(line, size, f)) < 0) {
|
||||
rv = ferror(f) ? errno : 0;
|
||||
free(*line);
|
||||
*line = 0;
|
||||
pw = 0;
|
||||
break;
|
||||
}
|
||||
line[0][l - 1] = 0;
|
||||
s = line[0];
|
||||
pw->pw_name = s++;
|
||||
if (!(s = strchr(s, ':'))) continue;
|
||||
*s++ = 0;
|
||||
pw->pw_passwd = s;
|
||||
if (!(s = strchr(s, ':'))) continue;
|
||||
*s++ = 0;
|
||||
pw->pw_uid = atou(&s);
|
||||
if (*s != ':') continue;
|
||||
*s++ = 0;
|
||||
pw->pw_gid = atou(&s);
|
||||
if (*s != ':') continue;
|
||||
*s++ = 0;
|
||||
pw->pw_gecos = s;
|
||||
if (!(s = strchr(s, ':'))) continue;
|
||||
*s++ = 0;
|
||||
pw->pw_dir = s;
|
||||
if (!(s = strchr(s, ':'))) continue;
|
||||
*s++ = 0;
|
||||
pw->pw_shell = s;
|
||||
break;
|
||||
}
|
||||
pthread_setcancelstate(cs, 0);
|
||||
*res = pw;
|
||||
if (rv) errno = rv;
|
||||
return rv;
|
||||
static int
|
||||
__getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size,
|
||||
struct passwd **res)
|
||||
{
|
||||
ssize_t l;
|
||||
char *s;
|
||||
int rv = 0;
|
||||
int cs;
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
|
||||
for (;;) {
|
||||
if ((l = getline(line, size, f)) < 0) {
|
||||
rv = ferror(f) ? errno : 0;
|
||||
free(*line);
|
||||
*line = 0;
|
||||
pw = 0;
|
||||
break;
|
||||
}
|
||||
line[0][l - 1] = 0;
|
||||
s = line[0];
|
||||
pw->pw_name = s++;
|
||||
if (!(s = strchr(s, ':'))) continue;
|
||||
*s++ = 0;
|
||||
pw->pw_passwd = s;
|
||||
if (!(s = strchr(s, ':'))) continue;
|
||||
*s++ = 0;
|
||||
pw->pw_uid = atou(&s);
|
||||
if (*s != ':') continue;
|
||||
*s++ = 0;
|
||||
pw->pw_gid = atou(&s);
|
||||
if (*s != ':') continue;
|
||||
*s++ = 0;
|
||||
pw->pw_gecos = s;
|
||||
if (!(s = strchr(s, ':'))) continue;
|
||||
*s++ = 0;
|
||||
pw->pw_dir = s;
|
||||
if (!(s = strchr(s, ':'))) continue;
|
||||
*s++ = 0;
|
||||
pw->pw_shell = s;
|
||||
break;
|
||||
}
|
||||
pthread_setcancelstate(cs, 0);
|
||||
*res = pw;
|
||||
if (rv) errno = rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int __getpw_a(const char *name, uid_t uid, struct passwd *pw, char **buf,
|
||||
size_t *size, struct passwd **res) {
|
||||
FILE *f;
|
||||
int cs;
|
||||
int rv = 0;
|
||||
*res = 0;
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
|
||||
if ((f = fopen("/etc/passwd", "rbe"))) {
|
||||
while (!(rv = __getpwent_a(f, pw, buf, size, res)) && *res) {
|
||||
if ((name && !strcmp(name, (*res)->pw_name)) ||
|
||||
(!name && (*res)->pw_uid == uid)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
pthread_setcancelstate(cs, 0);
|
||||
if (rv) errno = rv;
|
||||
return rv;
|
||||
static int
|
||||
__getpw_a(const char *name, uid_t uid, struct passwd *pw, char **buf,
|
||||
size_t *size, struct passwd **res)
|
||||
{
|
||||
FILE *f;
|
||||
int cs;
|
||||
int rv = 0;
|
||||
*res = 0;
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
|
||||
if ((f = fopen("/etc/passwd", "rbe"))) {
|
||||
while (!(rv = __getpwent_a(f, pw, buf, size, res)) && *res) {
|
||||
if ((name && !strcmp(name, (*res)->pw_name)) ||
|
||||
(!name && (*res)->pw_uid == uid)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
pthread_setcancelstate(cs, 0);
|
||||
if (rv) errno = rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int getpw_r(const char *name, uid_t uid, struct passwd *pw, char *buf,
|
||||
size_t size, struct passwd **res) {
|
||||
static int
|
||||
getpw_r(const char *name, uid_t uid, struct passwd *pw, char *buf,
|
||||
size_t size, struct passwd **res)
|
||||
{
|
||||
#define FIX(x) (pw->pw_##x = pw->pw_##x - line + buf)
|
||||
char *line = 0;
|
||||
size_t len = 0;
|
||||
int rv = 0;
|
||||
int cs;
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
|
||||
rv = __getpw_a(name, uid, pw, &line, &len, res);
|
||||
if (*res && size < len) {
|
||||
*res = 0;
|
||||
rv = ERANGE;
|
||||
}
|
||||
if (*res) {
|
||||
memcpy(buf, line, len);
|
||||
FIX(name);
|
||||
FIX(passwd);
|
||||
FIX(gecos);
|
||||
FIX(dir);
|
||||
FIX(shell);
|
||||
}
|
||||
free(line);
|
||||
pthread_setcancelstate(cs, 0);
|
||||
if (rv) errno = rv;
|
||||
return rv;
|
||||
char *line = 0;
|
||||
size_t len = 0;
|
||||
int rv = 0;
|
||||
int cs;
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
|
||||
rv = __getpw_a(name, uid, pw, &line, &len, res);
|
||||
if (*res && size < len) {
|
||||
*res = 0;
|
||||
rv = ERANGE;
|
||||
}
|
||||
if (*res) {
|
||||
memcpy(buf, line, len);
|
||||
FIX(name);
|
||||
FIX(passwd);
|
||||
FIX(gecos);
|
||||
FIX(dir);
|
||||
FIX(shell);
|
||||
}
|
||||
free(line);
|
||||
pthread_setcancelstate(cs, 0);
|
||||
if (rv) errno = rv;
|
||||
return rv;
|
||||
#undef FIX
|
||||
}
|
||||
|
||||
int getpwnam_r(const char *name, struct passwd *pw, char *buf, size_t size,
|
||||
struct passwd **res) {
|
||||
return getpw_r(name, 0, pw, buf, size, res);
|
||||
int
|
||||
getpwnam_r(const char *name, struct passwd *pw, char *buf, size_t size,
|
||||
struct passwd **res)
|
||||
{
|
||||
return getpw_r(name, 0, pw, buf, size, res);
|
||||
}
|
||||
|
||||
int getpwuid_r(uid_t uid, struct passwd *pw, char *buf, size_t size,
|
||||
struct passwd **res) {
|
||||
return getpw_r(0, uid, pw, buf, size, res);
|
||||
int
|
||||
getpwuid_r(uid_t uid, struct passwd *pw, char *buf, size_t size,
|
||||
struct passwd **res)
|
||||
{
|
||||
return getpw_r(0, uid, pw, buf, size, res);
|
||||
}
|
||||
|
||||
static struct GetpwentState {
|
||||
FILE *f;
|
||||
char *line;
|
||||
struct passwd pw;
|
||||
size_t size;
|
||||
FILE *f;
|
||||
char *line;
|
||||
struct passwd pw;
|
||||
size_t size;
|
||||
} g_getpwent[1];
|
||||
|
||||
void endpwent() {
|
||||
setpwent();
|
||||
}
|
||||
void setpwent() {
|
||||
if (g_getpwent->f) fclose(g_getpwent->f);
|
||||
g_getpwent->f = 0;
|
||||
void
|
||||
endpwent()
|
||||
{
|
||||
setpwent();
|
||||
}
|
||||
|
||||
struct passwd *getpwent() {
|
||||
struct passwd *res;
|
||||
if (!g_getpwent->f) g_getpwent->f = fopen("/etc/passwd", "rbe");
|
||||
if (!g_getpwent->f) return 0;
|
||||
__getpwent_a(g_getpwent->f, &g_getpwent->pw, &g_getpwent->line,
|
||||
&g_getpwent->size, &res);
|
||||
return res;
|
||||
void
|
||||
setpwent()
|
||||
{
|
||||
if (g_getpwent->f) fclose(g_getpwent->f);
|
||||
g_getpwent->f = 0;
|
||||
}
|
||||
|
||||
struct passwd *getpwuid(uid_t uid) {
|
||||
struct passwd *res;
|
||||
__getpw_a(0, uid, &g_getpwent->pw, &g_getpwent->line, &g_getpwent->size,
|
||||
&res);
|
||||
return res;
|
||||
struct passwd *
|
||||
getpwent()
|
||||
{
|
||||
struct passwd *res;
|
||||
if (!g_getpwent->f) g_getpwent->f = fopen("/etc/passwd", "rbe");
|
||||
if (!g_getpwent->f) return 0;
|
||||
__getpwent_a(g_getpwent->f, &g_getpwent->pw, &g_getpwent->line,
|
||||
&g_getpwent->size, &res);
|
||||
return res;
|
||||
}
|
||||
|
||||
struct passwd *getpwnam(const char *name) {
|
||||
struct passwd *res;
|
||||
__getpw_a(name, 0, &g_getpwent->pw, &g_getpwent->line, &g_getpwent->size,
|
||||
&res);
|
||||
return res;
|
||||
struct passwd *
|
||||
getpwuid(uid_t uid)
|
||||
{
|
||||
struct passwd *res;
|
||||
__getpw_a(0, uid, &g_getpwent->pw, &g_getpwent->line, &g_getpwent->size,
|
||||
&res);
|
||||
return res;
|
||||
}
|
||||
|
||||
struct passwd *
|
||||
getpwnam(const char *name)
|
||||
{
|
||||
struct passwd *res;
|
||||
__getpw_a(name, 0, &g_getpwent->pw, &g_getpwent->line,
|
||||
&g_getpwent->size, &res);
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue