From 791237e44695d2ee123c8a6f665ef074f5fadfbb Mon Sep 17 00:00:00 2001 From: Patrick Schaaf Date: Mon, 2 Apr 2012 12:07:46 +0200 Subject: bash: fix "getcwd: cannot access parent directories: Math result..." In get_working_directory(), the getcwd call in the __ANDROID__ workaround case was obviously wrong, having sizeof(char *) as a length argument instead of the length of the malloced string itself. Also, no check for malloc failure was there. With this fix, tested on maguro, using bash with the usual prompt containing pwd references, as well as the pwd bash builtin itself, no longer spew these annoying messages mentioned in the title. Also made a small change to sh_invalidnum() to fix compile warnings. Change-Id: I9546e07731a251f80e410935619ddcf0873694af --- builtins/common.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/builtins/common.c b/builtins/common.c index b69e7a2..03d0d82 100644 --- a/builtins/common.c +++ b/builtins/common.c @@ -232,7 +232,7 @@ void sh_invalidnum (s) char *s; { - char *msg; + const char *msg; if (*s == '0' && isdigit (s[1])) msg = _("invalid octal number"); @@ -559,11 +559,13 @@ get_working_directory (for_whom) * out if PWD isn't defined when starting it up on bionic */ char *d = (char *)malloc(sizeof(char) * PATH_MAX); - the_current_working_directory = getcwd (d, sizeof(d)); - if (the_current_working_directory) - the_current_working_directory = d; - else - FREE (d); + if (d) { + the_current_working_directory = getcwd (d, sizeof(char) * PATH_MAX); + if (the_current_working_directory) + the_current_working_directory = d; + else + FREE (d); + } #else # if defined (GETCWD_BROKEN) the_current_working_directory = getcwd (0, PATH_MAX); -- cgit v1.1