scsh-users
[Top] [All Lists]

(user-info "UnKnOwN") => Segmentation fault

To: scsh-bugs@martigny.ai.mit.edu
Subject: (user-info "UnKnOwN") => Segmentation fault
From: Alan Bawden <Alan@lcs.mit.edu>
Date: Mon, 31 Mar 1997 21:18:06 -0500
Sender: Alan@lcs.mit.edu
Since I don't 100% understand how CIG is supposed to work, I don't know the
right way to fix this.  The symptom:

  curry:alan> scsh
  Scsh 0.4
  > (user-info "alan")
  '#{user-info "alan"}
  > (user-info "UnKnOwN")
  Segmentation fault
  curry:alan> 

The problem is that the the code generated by CIG for `%name->user-info'
allocates a bunch of variables and passes the addresses of those variables
in to user_info_name().  user_info_name() looks like this:

  int user_info_name(const char *name,
                     uid_t *uid, gid_t *gid, char **dir, char **shell)
  {
      struct passwd *pwd = getpwnam(name);
      if( !pwd ) return 0;
      *uid  = pwd->pw_uid;
      *gid  = pwd->pw_gid;
      *dir  = pwd->pw_dir;
      *shell = pwd->pw_shell;
      return 1;
      }

Notice that if getpwnam() returns NULL, then nothing is done with those
variable addresses.  So the variables are still uninitialized.  Next, the
CIG generated code attempts to convert those C values into Scheme48 values.
Since the C value is ininitialized garbage, this conversion sometimes
generates a segmentation fault.

I would -guess- that the fix is to re-write all those routines in
`userinfo1.c'.  Although perhaps the answer is for CIG to initialize such
variables with reasonable initial C values.

If the fix is the former, I'll fix it myself and send you the patch.  Let
me know...

Seems like this is the kind of error that might be lurking in a lot of
places.  Someone might want to browse through the code looking for other
instances.

<Prev in Thread] Current Thread [Next in Thread>