mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-16 22:23:37 +02:00
libreboot-utils: simplify lbgetprogname
make it more reliable; it can't segfault now, under any circumstance. not even once. the problem arised when lbsetname was not called in a program, before calling the function: lbgetprogname. a segfault would occur, due to it being NULL. not every os/libc has getprogname, so i have my own implementation. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -31,7 +31,7 @@ of something like e.g. unveil, but in userspace!
|
|||||||
|
|
||||||
Mkhtemp is designed to be the most secure implementation
|
Mkhtemp is designed to be the most secure implementation
|
||||||
possible, of mktemp, offering a heavy amount of hardening
|
possible, of mktemp, offering a heavy amount of hardening
|
||||||
over traditional mktemp. Written in C89, and the plan is
|
over traditional mktemp. Written in C99, and the plan is
|
||||||
very much to keep this code portable over time - patches
|
very much to keep this code portable over time - patches
|
||||||
very much welcome.
|
very much welcome.
|
||||||
|
|
||||||
@@ -241,7 +241,7 @@ a drop-in replacement on Linux distros (and BSDs if they
|
|||||||
want it), while providing a more hardened version and
|
want it), while providing a more hardened version and
|
||||||
recommending that where possible.
|
recommending that where possible.
|
||||||
|
|
||||||
~~Rewrite it in rust~~ (nothing against it though, I just like C89 for some reason)
|
~~Rewrite it in rust~~ (nothing against it though, I just like C99 for some reason)
|
||||||
|
|
||||||
Also, generally document the history of mktemp, and how
|
Also, generally document the history of mktemp, and how
|
||||||
mkhtemp works in comparison.
|
mkhtemp works in comparison.
|
||||||
|
|||||||
@@ -359,22 +359,16 @@ no_op(void)
|
|||||||
const char *
|
const char *
|
||||||
lbgetprogname(void)
|
lbgetprogname(void)
|
||||||
{
|
{
|
||||||
static char *rval = NULL;
|
char *name = lbsetprogname(NULL);
|
||||||
static char *p;
|
char *p = NULL;
|
||||||
static int setname = 0;
|
if (name)
|
||||||
|
p = strrchr(name, '/');
|
||||||
if (!setname) {
|
if (p)
|
||||||
if ((rval = lbsetprogname(NULL)) == NULL)
|
return p + 1;
|
||||||
return NULL;
|
else if (name)
|
||||||
|
return name;
|
||||||
p = strrchr(rval, '/');
|
else
|
||||||
if (p)
|
return "libreboot-utils";
|
||||||
rval = p + 1;
|
|
||||||
|
|
||||||
setname = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* singleton. if string not null,
|
/* singleton. if string not null,
|
||||||
@@ -385,17 +379,13 @@ lbgetprogname(void)
|
|||||||
char *
|
char *
|
||||||
lbsetprogname(char *argv0)
|
lbsetprogname(char *argv0)
|
||||||
{
|
{
|
||||||
static int setname = 0;
|
|
||||||
static char *progname = NULL;
|
static char *progname = NULL;
|
||||||
size_t len;
|
static int set = 0;
|
||||||
|
|
||||||
if (!setname) {
|
if (!set) {
|
||||||
if (if_err(argv0 == NULL || *argv0 == '\0', EFAULT) ||
|
if (argv0 == NULL || sdup(argv0, 4096, &progname) < 0)
|
||||||
slen(argv0, 4096, &len) < 0)
|
return "libreboot-utils";
|
||||||
return NULL;
|
set = 1;
|
||||||
|
|
||||||
memcpy(smalloc(&progname, len + 1), argv0, len + 1);
|
|
||||||
setname = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return progname;
|
return progname;
|
||||||
|
|||||||
Reference in New Issue
Block a user