diff options
Diffstat (limited to 'src/user')
-rw-r--r-- | src/user/lib/stdlib.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/user/lib/stdlib.c b/src/user/lib/stdlib.c index a5d2d9b..43405d7 100644 --- a/src/user/lib/stdlib.c +++ b/src/user/lib/stdlib.c @@ -104,10 +104,14 @@ int chdir(const char *path) { return 0; } -char *getcwd(char *buf, size_t size) { +char *getcwd(char *buf, size_t capacity) { const char *realcwd = getrealcwd(); - // TODO bounds checking - memcpy(buf, realcwd, strlen(realcwd) + 1); + size_t len = strlen(realcwd) + 1; + if (capacity < len) { + errno = capacity == 0 ? EINVAL : ERANGE; + return NULL; + } + memcpy(buf, realcwd, len); return buf; } |