Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!lll-lcc!styx!ptsfa!ihnp4!occrsh!occrsh.ATT.COM!uokmet.UUCP!authorplaceholder From: authorplaceholder@uokmet.UUCP.UUCP Newsgroups: comp.bugs.2bsd Subject: Minor bug in getwd() Message-ID: <1500030@uokmet.UUCP> Date: Mon, 4-May-87 20:48:00 EDT Article-I.D.: uokmet.1500030 Posted: Mon May 4 20:48:00 1987 Date-Received: Fri, 8-May-87 03:37:27 EDT Lines: 49 Nf-ID: #N:uokmet.UUCP:1500030:000:1220 Nf-From: uokmet.UUCP!root May 4 19:48:00 1987 Subject: Getwd() returns an array with a garbage character at the end. Index: /usr/src/lib/c/gen/getwd.c 2.9bsd Description: Getwd() returns an array with a garbage character at the end. This only occurs when the length of a particular directory is exactly 14 (DIRSIZ). There is no NULL terminated array in this case, and no provisions are made for it. Repeat-By: Make a directory of length 14 characters. Cd to that directory. Run a program that displays the output from the getwd() call. Take a look at the output using any favorite program that displays trash characters. Fix: 22c22 < char *strcpy(); --- > char *strcpy(),*strncpy(); 29a30 > char name[DIRSIZ+1]; /* "clean" name */ 36a38 > int n; 79c81,89 < pnptr = prepend(PATHSEP, prepend(dir.d_name, pnptr)); --- > /* > * pnptr = prepend(PATHSEP, prepend(dir.d_name, pnptr)); > */ > n = strlen(dir.d_name); > if (n > DIRSIZ) > n = DIRSIZ; > strncpy(name,dir.d_name,n); > name[n] = 0; > pnptr = prepend(PATHSEP, prepend(name, pnptr)); Comments: Since 2.9bsd only looks at the first 14 characters, this bug hardly breaks anything. Kevin W. Thomas UUCP: ihnp4!occrsh!uokmet!kwthomas ihnp4!okstate!uokmax!uokmet!kwthomas