diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-07-23 20:17:20 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-07-23 20:17:20 -0700 |
commit | 5d8b80236056e229105c158c5aca8ba34d73e468 (patch) | |
tree | c13d377b2db1de47b0b618f390c20f4d3cc24790 /safepath.c | |
parent | 06540c9cef675fd8665325301384f3cc491e9f66 (diff) | |
download | safepath-5d8b80236056e229105c158c5aca8ba34d73e468.tar.gz safepath-5d8b80236056e229105c158c5aca8ba34d73e468.tar.bz2 safepath-5d8b80236056e229105c158c5aca8ba34d73e468.zip |
Map safepath errors to strings.
* safepath.[ch]: New function, safepath_strerr.
* testsp.c (main): Use new function to print message,
rather than integer code.
Diffstat (limited to 'safepath.c')
-rw-r--r-- | safepath.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -337,6 +337,27 @@ out: return ret; } +const char *safepath_strerr(int err) +{ + const char *str[] = { + [SAFEPATH_OK] = "path appears safe", + [SAFEPATH_UNSAFE] = "path contains untrusted component", + [SAFEPATH_PERM] = "path contains inaccessible component", + [SAFEPATH_NOENT] = "path contains nonexistent component", + [SAFEPATH_INVAL] = "path is syntactically invalid", + [SAFEPATH_NOMEM] = "out of memory", + [SAFEPATH_LOOP] = "too many symlink resolutions" + }; + const char *ret = "SAFEPATH_BAD_ERROR_CODE"; + + if (err >= 0 && err <= (int) (sizeof str / sizeof str[0]) && str[err] != 0) + { + ret = str[err]; + } + + return ret; +} + int safepath_open(const char *name, int flags) { int res = safepath_check(name); |