Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Aug 2003 13:38:44 -0700 (PDT)
From:      Garrett Wollman <wollman@FreeBSD.org>
To:        src-committers@FreeBSD.org, cvs-src@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   cvs commit: src/lib/libc/gen gethostname.3 gethostname.c
Message-ID:  <200308192038.h7JKcisC081051@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
wollman     2003/08/19 13:38:44 PDT

  FreeBSD src repository

  Modified files:
    lib/libc/gen         gethostname.3 gethostname.c 
  Log:
  Change gethostname() to set errno to ENAMETOOLONG instead of ENOMEM
  when the buffer is not long enough to hold the current host name.
  POSIX does not standardize error returns for gethostname(), so it
  doesn't matter which one we use, but ENAMETOOLONG is at least a little
  more intuitive, and mi suggests the existence of prior art.  I've been
  running with this change for a while on my home machine with no
  effect.  At the same time, I've updated the prototype for
  gethostname() to use the correct standard type (size_t) for the
  namelen argument.
  
  All of the in-tree callers fall into one of the following categories:
  1) Call perror() or equivalent when gethostname() fails.
  2) Ignore gethostname()'s return value entirely, potentially resulting
  in data corruption if the buffer is too small.
  3) Fall back to a (possibly sensible) default value if gethostname()
  fails.
  
  Many of the callers I examined shows signs of confusion about the
  correct sizing of the host name buffer.  gethostname(3) now has more
  information about this, as well as updated standards information.
  
  PR:             48114
  Submitted by:   mi (in part)
  
  Revision  Changes    Path
  1.14      +44 -14    src/lib/libc/gen/gethostname.3
  1.4       +7 -4      src/lib/libc/gen/gethostname.c



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200308192038.h7JKcisC081051>