~ubuntu-branches/ubuntu/natty/mysql-5.1/natty-proposed

« back to all changes in this revision

Viewing changes to mysys/my_gethostbyname.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 08:30:45 UTC
  • mfrom: (1.4.1)
  • Revision ID: package-import@ubuntu.com-20120222083045-2rd53r4bnyx7qus4
Tags: 5.1.61-0ubuntu0.11.04.1
* SECURITY UPDATE: Update to 5.1.61 to fix multiple security issues
  (LP: #937869)
  - http://www.oracle.com/technetwork/topics/security/cpujan2012-366304.html
  - CVE-2011-2262
  - CVE-2012-0075
  - CVE-2012-0112
  - CVE-2012-0113
  - CVE-2012-0114
  - CVE-2012-0115
  - CVE-2012-0116
  - CVE-2012-0117
  - CVE-2012-0118
  - CVE-2012-0119
  - CVE-2012-0120
  - CVE-2012-0484
  - CVE-2012-0485
  - CVE-2012-0486
  - CVE-2012-0487
  - CVE-2012-0488
  - CVE-2012-0489
  - CVE-2012-0490
  - CVE-2012-0491
  - CVE-2012-0492
  - CVE-2012-0493
  - CVE-2012-0494
  - CVE-2012-0495
  - CVE-2012-0496

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2002, 2004 MySQL AB
2
 
   
3
 
   This library is free software; you can redistribute it and/or
4
 
   modify it under the terms of the GNU Library General Public
5
 
   License as published by the Free Software Foundation; version 2
6
 
   of the License.
7
 
   
8
 
   This library is distributed in the hope that it will be useful,
9
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
 
   Library General Public License for more details.
12
 
   
13
 
   You should have received a copy of the GNU Library General Public
14
 
   License along with this library; if not, write to the Free
15
 
   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16
 
   MA 02111-1307, USA */
17
 
 
18
 
/* Thread safe version of gethostbyname_r() */
19
 
 
20
 
#include "mysys_priv.h"
21
 
#if !defined(__WIN__)
22
 
#include <netdb.h>
23
 
#endif
24
 
#include <my_net.h>
25
 
 
26
 
/* This file is not needed if my_gethostbyname_r is a macro */
27
 
#if !defined(my_gethostbyname_r)
28
 
 
29
 
/*
30
 
  Emulate SOLARIS style calls, not because it's better, but just to make the
31
 
  usage of getbostbyname_r simpler.
32
 
*/
33
 
 
34
 
#if defined(HAVE_GETHOSTBYNAME_R)
35
 
 
36
 
#if defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE)
37
 
 
38
 
struct hostent *my_gethostbyname_r(const char *name,
39
 
                                   struct hostent *result, char *buffer,
40
 
                                   int buflen, int *h_errnop)
41
 
{
42
 
  struct hostent *hp;
43
 
  DBUG_ASSERT((size_t) buflen >= sizeof(*result));
44
 
  if (gethostbyname_r(name,result, buffer, (size_t) buflen, &hp, h_errnop))
45
 
    return 0;
46
 
  return hp;
47
 
}
48
 
 
49
 
#elif defined(HAVE_GETHOSTBYNAME_R_RETURN_INT)
50
 
 
51
 
struct hostent *my_gethostbyname_r(const char *name,
52
 
                                   struct hostent *result, char *buffer,
53
 
                                   int buflen, int *h_errnop)
54
 
{
55
 
  if (gethostbyname_r(name,result,(struct hostent_data *) buffer) == -1)
56
 
  {
57
 
    *h_errnop= errno;
58
 
    return 0;
59
 
  }
60
 
  return result;
61
 
}
62
 
 
63
 
#else
64
 
 
65
 
/* gethostbyname_r with similar interface as gethostbyname() */
66
 
 
67
 
struct hostent *my_gethostbyname_r(const char *name,
68
 
                                   struct hostent *result, char *buffer,
69
 
                                   int buflen, int *h_errnop)
70
 
{
71
 
  struct hostent *hp;
72
 
  DBUG_ASSERT(buflen >= sizeof(struct hostent_data));
73
 
  hp= gethostbyname_r(name,result,(struct hostent_data *) buffer);
74
 
  *h_errnop= errno;
75
 
  return hp;
76
 
}
77
 
#endif /* GLIBC2_STYLE_GETHOSTBYNAME_R */
78
 
 
79
 
#else /* !HAVE_GETHOSTBYNAME_R */
80
 
 
81
 
#ifdef THREAD
82
 
extern pthread_mutex_t LOCK_gethostbyname_r;
83
 
#endif
84
 
 
85
 
/*
86
 
  No gethostbyname_r() function exists.
87
 
  In this case we have to keep a mutex over the call to ensure that no
88
 
  other thread is going to reuse the internal memory.
89
 
 
90
 
  The user is responsible to call my_gethostbyname_r_free() when he
91
 
  is finished with the structure.
92
 
*/
93
 
 
94
 
struct hostent *my_gethostbyname_r(const char *name,
95
 
                                   struct hostent *res __attribute__((unused)),
96
 
                                   char *buffer __attribute__((unused)),
97
 
                                   int buflen __attribute__((unused)),
98
 
                                   int *h_errnop)
99
 
{
100
 
  struct hostent *hp;
101
 
  pthread_mutex_lock(&LOCK_gethostbyname_r);
102
 
  hp= gethostbyname(name);
103
 
  *h_errnop= h_errno;
104
 
  return hp;
105
 
}
106
 
 
107
 
void my_gethostbyname_r_free()
108
 
{
109
 
  pthread_mutex_unlock(&LOCK_gethostbyname_r);  
110
 
}
111
 
 
112
 
#endif /* !HAVE_GETHOSTBYNAME_R */
113
 
#endif /* !my_gethostbyname_r */