bug-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Building on Mac OS X (was Re: a quick mailutils question)


From: xystrus
Subject: Re: Building on Mac OS X (was Re: a quick mailutils question)
Date: Wed, 1 May 2002 01:03:07 -0400
User-agent: Mutt/1.3.28i

On Tue, Apr 30, 2002 at 03:50:55PM +0300, Sergey Poznyakoff wrote:
> > Sergey, any suggestions on this? Maybe the whole function can
> > be commented out based on availability of getutent()?
> 
> Unfortunately, it cannot. The function determines the tty which
> the user is currently using. Without it comsatd will not function
> at all.

Well, it strikes me the whole function can be replaced with:

  int find_user(char *tty)
  {
  
      int status;
  
      status = NOT_HERE;
  
      if ( isatty(0) ){
          strncpy( tty, ttyname(0), MAX_TTY_SIZE);
          status = SUCCESS;
      }
  
  return status;
  
  }

The *utent functions are a SysV-ism.  The isatty() and ttyname()
functions are defined by POSIX.1 and should be present in OS X, unless
Apple is going out of their way to make it non-compliant.  This is
also much shorter. ;-)

Also, note that you have a potential buffer overflow in this function
as it exists.  It may not be terribly useful, but if someone were able
to, say, create a symlink to /dev/tty0 called something like

this_is_my_really_long_file_name_for_slash_dev_slash_tty0_in_my_home_directory

and then manage to open that as the controlling tty, your function
would (maybe) overflow the char *tty.  I don't know if this is
possible, but you're best off using strncpy anyway to avoid any
potential bogosity.  This really depends on what the implementation of
the getutent() fucntion is, as you would have to also overflow the
utmp structure member as well...  But why take chances?  It's not like
vendors have never shipped buggy libc implementations before...

-- 
Xy
address@hidden




reply via email to

[Prev in Thread] Current Thread [Next in Thread]