~james-page/ubuntu/precise/mysql-5.5/misc-fixes

« back to all changes in this revision

Viewing changes to sql/mysqld.cc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-06-11 07:34:33 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120611073433-l9za2ni4ipp848y3
Tags: 5.5.24-0ubuntu0.12.04.1
* SECURITY UPDATE: Update to 5.5.24 to fix security issues (LP: #1011371)
  - http://dev.mysql.com/doc/refman/5.5/en/news-5-5-24.html

Show diffs side-by-side

added added

removed removed

Lines of Context:
656
656
File_parser_dummy_hook file_parser_dummy_hook;
657
657
 
658
658
/* replication parameters, if master_host is not NULL, we are a slave */
659
 
uint report_port= MYSQL_PORT;
 
659
uint report_port= 0;
660
660
ulong master_retry_count=0;
661
661
char *master_info_file;
662
662
char *relay_log_info_file, *report_user, *report_password, *report_host;
1045
1045
  {
1046
1046
    if (ip_sock != INVALID_SOCKET)
1047
1047
    {
1048
 
      (void) shutdown(ip_sock, SHUT_RDWR);
 
1048
      (void) mysql_socket_shutdown(ip_sock, SHUT_RDWR);
1049
1049
      (void) closesocket(ip_sock);
1050
1050
      ip_sock= INVALID_SOCKET;
1051
1051
    }
1077
1077
#ifdef HAVE_SYS_UN_H
1078
1078
  if (unix_sock != INVALID_SOCKET)
1079
1079
  {
1080
 
    (void) shutdown(unix_sock, SHUT_RDWR);
 
1080
    (void) mysql_socket_shutdown(unix_sock, SHUT_RDWR);
1081
1081
    (void) closesocket(unix_sock);
1082
1082
    (void) unlink(mysqld_unix_port);
1083
1083
    unix_sock= INVALID_SOCKET;
1184
1184
  {
1185
1185
    ip_sock=INVALID_SOCKET;
1186
1186
    DBUG_PRINT("info",("calling shutdown on TCP/IP socket"));
1187
 
    (void) shutdown(tmp_sock, SHUT_RDWR);
 
1187
    (void) mysql_socket_shutdown(tmp_sock, SHUT_RDWR);
1188
1188
  }
1189
1189
  tmp_sock=unix_sock;
1190
1190
  if (tmp_sock != INVALID_SOCKET)
1191
1191
  {
1192
1192
    unix_sock=INVALID_SOCKET;
1193
1193
    DBUG_PRINT("info",("calling shutdown on unix socket"));
1194
 
    (void) shutdown(tmp_sock, SHUT_RDWR);
 
1194
    (void) mysql_socket_shutdown(tmp_sock, SHUT_RDWR);
1195
1195
    (void) unlink(mysqld_unix_port);
1196
1196
  }
1197
1197
  DBUG_VOID_RETURN;
1765
1765
}
1766
1766
 
1767
1767
 
 
1768
static my_socket create_socket(const struct addrinfo *addrinfo_list,
 
1769
                               int addr_family,
 
1770
                               struct addrinfo **use_addrinfo)
 
1771
{
 
1772
  my_socket sock= INVALID_SOCKET;
 
1773
 
 
1774
  for (const struct addrinfo *cur_ai= addrinfo_list; cur_ai != NULL;
 
1775
       cur_ai= cur_ai->ai_next)
 
1776
  {
 
1777
    if (cur_ai->ai_family != addr_family)
 
1778
      continue;
 
1779
 
 
1780
    sock= socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol);
 
1781
 
 
1782
    char ip_addr[INET6_ADDRSTRLEN];
 
1783
 
 
1784
    if (vio_get_normalized_ip_string(cur_ai->ai_addr, cur_ai->ai_addrlen,
 
1785
                                     ip_addr, sizeof (ip_addr)))
 
1786
    {
 
1787
      ip_addr[0]= 0;
 
1788
    }
 
1789
 
 
1790
    if (sock == INVALID_SOCKET)
 
1791
    {
 
1792
      sql_print_error("Failed to create a socket for %s '%s': errno: %d.",
 
1793
                      (addr_family == AF_INET) ? "IPv4" : "IPv6",
 
1794
                      (const char *) ip_addr,
 
1795
                      (int) socket_errno);
 
1796
      continue;
 
1797
    }
 
1798
 
 
1799
    sql_print_information("Server socket created on IP: '%s'.",
 
1800
                          (const char *) ip_addr);
 
1801
 
 
1802
    *use_addrinfo= (struct addrinfo *)cur_ai;
 
1803
    return sock;
 
1804
  }
 
1805
 
 
1806
  return INVALID_SOCKET;
 
1807
}
 
1808
 
 
1809
 
1768
1810
static void network_init(void)
1769
1811
{
1770
1812
#ifdef HAVE_SYS_UN_H
1784
1826
 
1785
1827
  set_ports();
1786
1828
 
 
1829
  if (report_port == 0)
 
1830
  {
 
1831
    report_port= mysqld_port;
 
1832
  }
 
1833
 
 
1834
#ifndef DBUG_OFF
 
1835
  if (!opt_disable_networking)
 
1836
    DBUG_ASSERT(report_port != 0);
 
1837
#endif
 
1838
 
1787
1839
  if (mysqld_port != 0 && !opt_disable_networking && !opt_bootstrap)
1788
1840
  {
1789
1841
    struct addrinfo *ai, *a;
1790
1842
    struct addrinfo hints;
1791
 
    int error;
1792
 
    DBUG_PRINT("general",("IP Socket is %d",mysqld_port));
1793
 
 
 
1843
 
 
1844
    sql_print_information("Server hostname (bind-address): '%s'; port: %d",
 
1845
                          my_bind_addr_str, mysqld_port);
 
1846
 
 
1847
    // Get list of IP-addresses associated with the server hostname.
1794
1848
    bzero(&hints, sizeof (hints));
1795
1849
    hints.ai_flags= AI_PASSIVE;
1796
1850
    hints.ai_socktype= SOCK_STREAM;
1797
1851
    hints.ai_family= AF_UNSPEC;
1798
1852
 
1799
1853
    my_snprintf(port_buf, NI_MAXSERV, "%d", mysqld_port);
1800
 
    error= getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai);
1801
 
    if (error != 0)
1802
 
    {
1803
 
      DBUG_PRINT("error",("Got error: %d from getaddrinfo()", error));
1804
 
      sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR));  /* purecov: tested */
1805
 
      unireg_abort(1);                          /* purecov: tested */
1806
 
    }
1807
 
 
1808
 
    for (a= ai; a != NULL; a= a->ai_next)
1809
 
    {
1810
 
      ip_sock= socket(a->ai_family, a->ai_socktype, a->ai_protocol);
1811
 
      if (ip_sock != INVALID_SOCKET)
1812
 
        break;
1813
 
    }
1814
 
 
1815
 
    if (ip_sock == INVALID_SOCKET)
1816
 
    {
1817
 
      DBUG_PRINT("error",("Got error: %d from socket()",socket_errno));
1818
 
      sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR));  /* purecov: tested */
1819
 
      unireg_abort(1);                          /* purecov: tested */
1820
 
    }
1821
 
 
 
1854
    if (getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai))
 
1855
    {
 
1856
      sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR));  /* purecov: tested */
 
1857
      sql_print_error("Can't start server: cannot resolve hostname!");
 
1858
      unireg_abort(1);                          /* purecov: tested */
 
1859
    }
 
1860
 
 
1861
    // Log all the IP-addresses.
 
1862
    for (struct addrinfo *cur_ai= ai; cur_ai != NULL; cur_ai= cur_ai->ai_next)
 
1863
    {
 
1864
      char ip_addr[INET6_ADDRSTRLEN];
 
1865
 
 
1866
      if (vio_get_normalized_ip_string(cur_ai->ai_addr, cur_ai->ai_addrlen,
 
1867
                                       ip_addr, sizeof (ip_addr)))
 
1868
      {
 
1869
        sql_print_error("Fails to print out IP-address.");
 
1870
        continue;
 
1871
      }
 
1872
 
 
1873
      sql_print_information("  - '%s' resolves to '%s';",
 
1874
                            my_bind_addr_str, ip_addr);
 
1875
    }
 
1876
 
 
1877
    /*
 
1878
      If the 'bind-address' option specifies the hostname, which resolves to
 
1879
      multiple IP-address, use the following rule:
 
1880
      - if there are IPv4-addresses, use the first IPv4-address
 
1881
      returned by getaddrinfo();
 
1882
      - if there are IPv6-addresses, use the first IPv6-address
 
1883
      returned by getaddrinfo();
 
1884
    */
 
1885
 
 
1886
    ip_sock= create_socket(ai, AF_INET, &a);
 
1887
 
 
1888
    if (ip_sock == INVALID_SOCKET)
 
1889
      ip_sock= create_socket(ai, AF_INET6, &a);
 
1890
 
 
1891
    // Report user-error if we failed to create a socket.
 
1892
    if (ip_sock == INVALID_SOCKET)
 
1893
    {
 
1894
      sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR));  /* purecov: tested */
 
1895
      unireg_abort(1);                          /* purecov: tested */
 
1896
    }
1822
1897
#ifndef __WIN__
1823
1898
    /*
1824
1899
      We should not use SO_REUSEADDR on windows as this would enable a
2406
2481
 
2407
2482
#endif /* __WIN__ */
2408
2483
 
2409
 
#ifdef HAVE_LINUXTHREADS
2410
 
#define UNSAFE_DEFAULT_LINUX_THREADS 200
2411
 
#endif
2412
 
 
2413
2484
 
2414
2485
#if BACKTRACE_DEMANGLE
2415
2486
#include <cxxabi.h>
5191
5262
          if (req.sink)
5192
5263
            ((void (*)(int))req.sink)(req.fd);
5193
5264
 
5194
 
          (void) shutdown(new_sock, SHUT_RDWR);
 
5265
          (void) mysql_socket_shutdown(new_sock, SHUT_RDWR);
5195
5266
          (void) closesocket(new_sock);
5196
5267
          continue;
5197
5268
        }
5207
5278
                  (SOCKET_SIZE_TYPE *)&dummyLen) < 0  )
5208
5279
      {
5209
5280
        sql_perror("Error on new connection socket");
5210
 
        (void) shutdown(new_sock, SHUT_RDWR);
 
5281
        (void) mysql_socket_shutdown(new_sock, SHUT_RDWR);
5211
5282
        (void) closesocket(new_sock);
5212
5283
        continue;
5213
5284
      }
5219
5290
 
5220
5291
    if (!(thd= new THD))
5221
5292
    {
5222
 
      (void) shutdown(new_sock, SHUT_RDWR);
 
5293
      (void) mysql_socket_shutdown(new_sock, SHUT_RDWR);
5223
5294
      (void) closesocket(new_sock);
5224
5295
      continue;
5225
5296
    }
5238
5309
        vio_delete(vio_tmp);
5239
5310
      else
5240
5311
      {
5241
 
        (void) shutdown(new_sock, SHUT_RDWR);
 
5312
        (void) mysql_socket_shutdown(new_sock, SHUT_RDWR);
5242
5313
        (void) closesocket(new_sock);
5243
5314
      }
5244
5315
      delete thd;
7026
7097
  case (int) OPT_SKIP_STACK_TRACE:
7027
7098
    test_flags|=TEST_NO_STACKTRACE;
7028
7099
    break;
7029
 
  case (int) OPT_BIND_ADDRESS:
7030
 
    {
7031
 
      struct addrinfo *res_lst, hints;    
7032
 
 
7033
 
      bzero(&hints, sizeof(struct addrinfo));
7034
 
      hints.ai_socktype= SOCK_STREAM;
7035
 
      hints.ai_protocol= IPPROTO_TCP;
7036
 
 
7037
 
      if (getaddrinfo(argument, NULL, &hints, &res_lst) != 0) 
7038
 
      {
7039
 
        sql_print_error("Can't start server: cannot resolve hostname!");
7040
 
        return 1;
7041
 
      }
7042
 
 
7043
 
      if (res_lst->ai_next)
7044
 
      {
7045
 
        sql_print_error("Can't start server: bind-address refers to multiple interfaces!");
7046
 
        return 1;
7047
 
      }
7048
 
      freeaddrinfo(res_lst);
7049
 
    }
7050
 
    break;
7051
7100
  case OPT_CONSOLE:
7052
7101
    if (opt_console)
7053
7102
      opt_error_log= 0;                 // Force logs to stdout