Commit graph

8 commits

Author SHA1 Message Date
Jeff King db85a8a9c2 compat/inet_ntop: fix off-by-one in inet_ntop4
Our compat inet_ntop4 function writes to a temporary buffer
with snprintf, and then uses strcpy to put the result into
the final "dst" buffer. We check the return value of
snprintf against the size of "dst", but fail to account for
the NUL terminator. As a result, we may overflow "dst" with
a single NUL. In practice, this doesn't happen because the
output of inet_ntop is limited, and we provide buffers that
are way oversized.

We can fix the off-by-one check easily, but while we are
here let's also use strlcpy for increased safety, just in
case there are other bugs lurking.

As a side note, this compat code seems to be BSD-derived.
Searching for "vixie inet_ntop" turns up NetBSD's latest
version of the same code, which has an identical fix (and
switches to strlcpy, too!).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-09-25 10:18:18 -07:00
Ben Walton cd4c4e2481 Drop system includes from inet_pton/inet_ntop compatibility wrappers
As both of these compatibility wrappers include git-compat-utils.h,
all of the system includes were redundant.

Dropping these system includes also makes git-compat-utils.h the first
include which avoids a compiler warning on Solaris due to the
redefinition of _FILE_OFFSET_BITS.

Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-05 16:32:33 -08:00
Sebastian Schuberth 185528a859 inet_ntop.c: Work around GCC 4.6's detection of uninitialized variables
GCC 4.6 claims that

    error: 'best.len' may be used uninitialized in this function

so silence that warning which is treated as an error by also initializing
the "len" members of the struct.

Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-10-18 10:34:07 -07:00
Erik Faye-Lund bb34c5aabe inet_ntop: fix a couple of old-style decls
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-04 16:53:50 -07:00
Mike Pape da523cc597 compat: add inet_pton and inet_ntop prototypes
Windows doesn't have inet_pton and inet_ntop, so
add prototypes in git-compat-util.h for them.

At the same time include git-compat-util.h in
the sources for these functions, so they use the
network-wrappers from there on Windows.

Signed-off-by: Mike Pape <dotzenlabs@gmail.com>
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-04 16:53:49 -07:00
Marco Costalba d8e21ba896 Remove a couple of duplicated include
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-11-05 20:50:38 -08:00
Junio C Hamano 1d182bd5f4 compat/inet_ntop: do not use u_int
It is pointless.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-12-20 13:45:55 -08:00
Yakov Lerner 6ba68ab288 NO_INET_NTOP and compat/inet_ntop.c for some systems (e.g. old Cygwin).
For systems which lack inet_ntop(), this adds compat/inet_ntop.c,
and related build constant, NO_INET_NTOP. Older Cygwin(s) lack
inet_ntop().

Signed-off-by: Yakov Lerner <iler.ml@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-05-21 16:44:36 -07:00