From: millert Date: Thu, 16 Dec 2021 19:12:43 +0000 (+0000) Subject: getwd(3): don't malloc space for buf if it is NULL X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=7b407ed550ed1d8f12d5067ceb03d87e25c42113;p=openbsd getwd(3): don't malloc space for buf if it is NULL The 4.3BSD getwd(3) did not malloc space, use __getcwd(2) directly so the compat function doesn't either. OK deraadt@ --- diff --git a/lib/libc/compat-43/getwd.c b/lib/libc/compat-43/getwd.c index 3062d46b169..2ae13683744 100644 --- a/lib/libc/compat-43/getwd.c +++ b/lib/libc/compat-43/getwd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getwd.c,v 1.12 2017/11/28 06:55:49 tb Exp $ */ +/* $OpenBSD: getwd.c,v 1.13 2021/12/16 19:12:43 millert Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. @@ -34,15 +34,17 @@ #include #include +int __getcwd(char *buf, size_t len); +PROTO_NORMAL(__getcwd); + char * getwd(char *buf) { - char *p; - - if ((p = getcwd(buf, PATH_MAX))) - return(p); - strlcpy(buf, strerror(errno), PATH_MAX); - return(NULL); + if (__getcwd(buf, PATH_MAX) == -1) { + strlcpy(buf, strerror(errno), PATH_MAX); + return NULL; + } + return buf; } __warn_references(getwd,