diff options
Diffstat (limited to 'util')
| -rw-r--r-- | util/libreboot-utils/README.md | 4 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/string.c | 40 |
2 files changed, 17 insertions, 27 deletions
diff --git a/util/libreboot-utils/README.md b/util/libreboot-utils/README.md index 6e94035b..dca1b92e 100644 --- a/util/libreboot-utils/README.md +++ b/util/libreboot-utils/README.md @@ -31,7 +31,7 @@ of something like e.g. unveil, but in userspace! Mkhtemp is designed to be the most secure implementation 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 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 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 mkhtemp works in comparison. diff --git a/util/libreboot-utils/lib/string.c b/util/libreboot-utils/lib/string.c index d5e2de85..6a372dcf 100644 --- a/util/libreboot-utils/lib/string.c +++ b/util/libreboot-utils/lib/string.c @@ -359,22 +359,16 @@ no_op(void) const char * lbgetprogname(void) { - static char *rval = NULL; - static char *p; - static int setname = 0; - - if (!setname) { - if ((rval = lbsetprogname(NULL)) == NULL) - return NULL; - - p = strrchr(rval, '/'); - if (p) - rval = p + 1; - - setname = 1; - } - - return rval; + char *name = lbsetprogname(NULL); + char *p = NULL; + if (name) + p = strrchr(name, '/'); + if (p) + return p + 1; + else if (name) + return name; + else + return "libreboot-utils"; } /* singleton. if string not null, @@ -385,17 +379,13 @@ lbgetprogname(void) char * lbsetprogname(char *argv0) { - static int setname = 0; static char *progname = NULL; - size_t len; - - if (!setname) { - if (if_err(argv0 == NULL || *argv0 == '\0', EFAULT) || - slen(argv0, 4096, &len) < 0) - return NULL; + static int set = 0; - memcpy(smalloc(&progname, len + 1), argv0, len + 1); - setname = 1; + if (!set) { + if (argv0 == NULL || sdup(argv0, 4096, &progname) < 0) + return "libreboot-utils"; + set = 1; } return progname; |
