From e456960d03dc1af25dcc21e86a5b1ec9c73d5eb8 Mon Sep 17 00:00:00 2001 From: cgf Date: Sun, 16 Sep 2001 02:56:58 +0000 Subject: [PATCH] * net.cc (dup_servent_ptr): Detect old Windows 95 misaligned structure and realign appropriately. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/net.cc | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index f50707d713..ff8cc18bdd 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +Sat Sep 15 22:54:49 2001 Christopher Faylor + + * net.cc (dup_servent_ptr): Detect old Windows 95 misaligned structure + and realign appropriately. + Sat Sep 15 00:28:40 2001 Christopher Faylor * Makefile.in: Generate libcygwin.a during the link pass rather than as diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index c53613abc3..c310c78b3a 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -932,6 +932,15 @@ free_servent_ptr (struct servent *&p) } } +#pragma pack(push,2) +struct pservent +{ + char *s_name; + char **s_aliases; + short s_port; + char *s_proto; +}; +#pragma pack(pop) static struct servent * dup_servent_ptr (struct servent *src) { @@ -947,10 +956,17 @@ dup_servent_ptr (struct servent *src) dst->s_port = src->s_port; if (src->s_name && !(dst->s_name = strdup (src->s_name))) goto out; - if (src->s_proto && !(dst->s_proto = strdup (src->s_proto))) - goto out; if (src->s_aliases && !(dst->s_aliases = dup_char_list (src->s_aliases))) goto out; + char *s_proto; + if (IsBadReadPtr (src->s_proto, sizeof (src->s_proto)) + && !IsBadReadPtr (((pservent *) src)->s_proto, sizeof (src->s_proto))) + s_proto = ((pservent *)src)->s_proto; + else + s_proto = src->s_proto; + + if (s_proto && !(dst->s_proto = strdup (s_proto))) + goto out; debug_printf ("servent: copied %s", dst->s_name); -- 2.11.0