authorplaceholder@uokmet.UUCP.UUCP (05/05/87)
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