diff --git a/libc/unistd/getcwd.c b/libc/unistd/getcwd.c index 1cf80e975..117244554 100644 --- a/libc/unistd/getcwd.c +++ b/libc/unistd/getcwd.c @@ -26,10 +26,15 @@ * SUCH DAMAGE. */ #include +#include extern int __getcwd(char * buf, size_t size); char *getcwd(char *buf, size_t size) { + if (buf == NULL || size == 0) { + errno = EINVAL; + return NULL; + } return ( __getcwd(buf, size) < 0 ) ? NULL : buf; }