rolfh@garmidt.unit.no (Rolf P Halle) (02/13/90)
X Window System Bug Report
xbugs@expo.lcs.mit.edu
VERSION:
R4
CLIENT MACHINE and OPERATING SYSTEM:
Discovered on a Sun 3/60, SunOS 4.0.1(Export), but I guess any
machine or OS would do :-)
DISPLAY TYPE:
All
WINDOW MANAGER:
twm
AREA:
twm
SYNOPSIS:
Calls to the ExpandFilename function sometimes return wrong answer.
DESCRIPTION:
We're doing some extensions to twm (like f.source). In connection with
this, we had to use the ExpandFilename-function. When giving
ExpandFilename ~rolfh/foo.bar as argument, it will return something
like /home/solan4/rolfh/rolfh/foo.bar, assuming I'm logged in as rolfh.
This should really be /home/solan4/rolfh/foo.bar.
REPEAT BY:
Try a call like name = ExpandFilename("~root/foo.bar");
SAMPLE FIX:
Apply the patch included below in the mit/clients/twm directory.
*** util.c Sun Feb 11 22:40:10 1990
--- util.c.new Sun Feb 11 22:42:31 1990
***************
*** 42,47 ****
--- 42,49 ----
#endif
#include <stdio.h>
+ #include <string.h>
+ #include <pwd.h>
#include "twm.h"
#include "util.h"
#include "gram.h"
***************
*** 322,339 ****
char *name;
{
char *newname;
if (name[0] != '~') return name;
! newname = (char *) malloc (HomeLen + strlen(name) + 2);
! if (!newname) {
! fprintf (stderr,
"%s: unable to allocate %d bytes to expand filename %s/%s\n",
ProgramName, HomeLen + strlen(name) + 2, Home, &name[1]);
! } else {
! (void) sprintf (newname, "%s/%s", Home, &name[1]);
}
!
return newname;
}
--- 324,365 ----
char *name;
{
char *newname;
+ char *username;
+ struct passwd *user;
if (name[0] != '~') return name;
! /* Is this my own HOME? */
! if (name[1]=='/') /* yes */
! {
! newname = (char *) malloc (HomeLen + strlen(name) + 2);
! if (!newname) {
! fprintf (stderr,
"%s: unable to allocate %d bytes to expand filename %s/%s\n",
ProgramName, HomeLen + strlen(name) + 2, Home, &name[1]);
! } else {
! (void) sprintf (newname, "%s/%s", Home, &name[1]);
! }
}
! else
! {
! /* Get rid of the ~ in name */
! ++name;
! username = strtok(name,"/"); /* Get the username */
! name = strtok(NULL,""); /* Get rest of filename */
! user = getpwnam(username);
! newname = (char *) malloc (strlen(user->pw_dir)
! + strlen(name) + 2);
!
! if (!newname) {
! fprintf (stderr,
! "%s: unable to allocate %d bytes to expand filename %s/%s\n",
! ProgramName, strlen(user->pw_dir) +
! strlen(name) + 20, user->pw_dir, name);
! } else {
! (void) sprintf (newname, "%s/%s", user->pw_dir, name);
! }
! }
return newname;
}
--
Rolf Halle
rolfh@idt.unit.no