Subject: pkg/5153: Scotty dumps core -- getcwd
To: None <gnats-bugs@gnats.netbsd.org>
From: Juergen Hannken-Illjes <hannken@eis.cs.tu-bs.de>
List: netbsd-bugs
Date: 03/12/1998 13:12:20
>Number: 5153
>Category: pkg
>Synopsis: Scotty dumps core -- getcwd
>Confidential: no
>Severity: critical
>Priority: high
>Responsible: gnats-admin (GNATS administrator)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Mar 12 04:20:01 1998
>Last-Modified:
>Originator: Juergen Hannken-Illjes
>Organization:
Juergen Hannken-Illjes - hannken@eis.cs.tu-bs.de - TU Braunschweig (W Germany)
>Release: <NetBSD-current source date>-current as of Mar 6., 1998
>Environment:
System: NetBSD watcher 1.3E NetBSD 1.3E (CUSTOM) #86: Mon Mar 9 14:01:52 MET 1998 hannken@watcher:/usr/src/sys/arch/sparc/compile/CUSTOM sparc
>Description:
Scotty dumps core. Reason is the call 'cwd = getcwd ((char *) NULL, 1024)' in
tkined/generic/tkiEditor.c.
lib/libc/gen/getcwd.c reads:
if (size != 0) {
if (pwdlen + 1 > size) {
errno = ERANGE;
return (NULL);
}
} else if ((pt = malloc(pwdlen + 1)) == NULL)
return (NULL);
memmove(pt, pwd, pwdlen);
Here malloc doesn't get called because size == 1024, memmove dumps core.
>How-To-Repeat:
Run Scotty.
>Fix:
If the problem is in Scotty:
--- tkined/generic/tkiEditor.c~ Thu Oct 3 19:58:08 1996
+++ tkined/generic/tkiEditor.c Thu Mar 12 12:43:19 1998
@@ -1048,5 +1048,5 @@
FileName (editor, interp, 1, &defaultName);
- if (! (cwd = getcwd ((char *) NULL, 1024))) cwd = "";
+ if (! (cwd = getcwd ((char *) NULL, 0))) cwd = "";
DirName (editor, interp, 1, &cwd);
A better fix would be in getcwd.c:
if (size != 0) {
if (pwdlen + 1 > size) {
errno = ERANGE;
return (NULL);
}
}
if (pt == NULL && (pt = malloc(pwdlen + 1)) == NULL)
return (NULL);
>Audit-Trail:
>Unformatted: