Bug #5652 [patch] tcpwrapper support is broken on systems using an unmodified tcpwrapper
Submitted: 19 Sep 2004 15:33 Modified: 24 Dec 2004 15:35
Reporter: Peter Edwards Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.0, 4.1, 5.0 OS:FreeBSD (FreeBSD (and possibly others))
Assigned to: Ramil Kalimullin CPU Architecture:Any

[19 Sep 2004 15:33] Peter Edwards
Description:
The FreeBSD ports collection includes a patch for compiling MySQL servers on freebsd. It adds a predicate to the conditional macro definitions of "my_fromhost", "my_hosts_access", and "my_eval_client" so that the use the parameterless calls to those functions on FreeBSD or if running on FreeBSD >= 5.0

This causes a crash on FreeBSD 5.0 when connecting to the server remotely

The issue is that the functions fromhost, eval_client, and hosts_access always take an argument, irrespective of what the header says: the original tcpwrapper's tcpd.h had old-style K&R function declarations, which didn't include the argument types. Calling the function with no argument is wrong: the header just meant that the parameter list was undefined. I think most Linux implementations use a modified version of the orignal Weitse "libwrap" headers.

Of course, this is contrary to what the C++ compiler understands of the argument-free function prototype, which makes the old-style K&R prototyped functions unusable from a C++ translation unit. (See sect C.1.6, clause 8 of the C++ standard)

I'll ask about ANSIfying the FreeBSD librwap a bit, and see how receptive people are to it, and I'll talk to the FreeBSD port maintainer about including a patch for the FreeBSD ports collection, but the root MySQL source is still wrong. 

I suspect someone cut-and-paste the __STDC__ from a patched tcpd.h without paying attention to what its for, and it's unlikely any platform that actually compiles mysql source unmodified has this issue, but the source is misleading, and has zero chance of compiling against an unmodified Weitse tcpwrapper.

How to repeat:
Install any version of MySQL from the ports collection on FreeBSD >= 5.0
Connect to a server using "mysql -h <hostname> ..." where hostname != "localhost".
You'll get the following error:

> ERROR 2013 (HY000): Lost connection to MySQL server during query

Suggested fix:
You could, of course, just remove the !__STDC__ stuff, and assume that people compiling have a patched version of libwrap. Alternatively, the following patch works for me: Create a C translation unit, mylibwrap.c (ie, an ISO C source file, not a C++ one), declare the my_*() functions in mylibwrap.h, and call via these wrappers from the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GXLTD'0EH/.<7'(]>SJ?3<15)DNTNZ`O=M3THC`_82G),.LW3DS82
M.W&%*!Z3'AQB;#JZ%2UH#\6SZ\@-:6]KJCCY3[C)$O++?I(,\F[$'W;#ISBW
M(0$MS"#4+4H<:4$]ZBRZD#C)MY'D+_FS]"\T5$^,N/Z/^[KM=XV=][].B^O_
MVJS_@Y:P[/\>@];]'Y?\K/][2QR$%,A'5Y;A![J[CKSI_SB+8O_7Z'15->O_
MY!,9B<J)VF#%37R6PAX=Z*ZS-%<UXX`QEPNZ1&_Z?VH8RNF[R_X%I_E[J'N+
MFO$';YPMS^P%\<8U%X((W<K2=VW##<(C^')&>@@M%*MI(52;I8N.808=R#=H
M(C9ZC/5<$/]F7DPGC)TP08")KM,@V.7(IV'D.RAGPOO4#>*CX]@MO2'0<UDF
M=79N+_7*6V1.GT'),Y?[J&Y;\6_LP3%'N_#?4IL9_MMJ@O_R_O<H=!?_Q@_C
MW[AS_VMV5>4._L]2^,=(QUCWK"A@OX)(OX04SOK!X`!]VQSN-9<!&^W$-0-&
M:@`81@^",&>38/0A"&5&V]XA0^63:CIR^&<W([BO[GN-'?A7%(7#?X=]_YN=
M3K/$_V-0AO\T^0GZ=__[=V-0!+^JP/<_`S\D]T2!VPU[)K>;!":H?HPFFC;$
ML[]F['<\?8W?H..Z$..775H_XX#>4-\,;^&6Q<2CR:OI\T2^H,YM4?RN?SD9
M35X_%R1!VB!T-A\.,`8&3$V'Y@I)OUI!"''3G%JN?O2KJ##/Z?)5`U11?@ZJ
MU`KH@S;Q`WMX^!;B':R#OHX)B_5]_127([XEB],#0JY98]D[/^]/\)NG5?=*
:*JFDDDHJJ:222BJII)+^;_0/X;Q96``H````
`
end
[9 Nov 2004 12:31] pineau benjamin
Same thing there with GNU/Linux, Slackware 9.1 (that uses Venema's original tcpd code from 1996, and gcc 3.2.3): mysql 4.1.7 won't even compile !

Here are the last lines of logs from compilation on Linux Slackware:

./configure --prefix=/usr/local/mysql \
                --enable-thread-safe-client \
                --with-berkeley-db \
                --with-innodb \
                --with-csv-storage-engine \
                --with-libwrap \
                --with-mysqld-user="_mysql" \
                --with-openssl \
                --enable-assembler \
                --enable-local-infile \
                --with-vio \
                --with-extra-charsets=complex \
                --with-ndbcluster \
                --with-ndb-shm

gmake

[...]

if g++ -DMYSQL_SERVER -DDEFAULT_MYSQL_HOME="\"/usr/local/mysql\"" -DDATADIR="\"/usr/local/mysql/var\"" -DSHAREDIR="\"/usr/local/mysql/share/mysql\"" -DHAVE_CONFIG_H -I. -I. -I.. -I../bdb/build_unix -I../innobase/include -I../ndb/include -I../ndb/include/ndbapi -I../include -I../regex -I.     -O3 -DDBUG_OFF  -DHAVE_BROKEN_REALPATH -felide-constructors -fno-exceptions -fno-rtti   -fno-implicit-templates -fno-exceptions -fno-rtti  -MT mysqld.o -MD -MP -MF ".deps/mysqld.Tpo" \
  -c -o mysqld.o `test -f 'mysqld.cc' || echo './'`mysqld.cc; \
then mv -f ".deps/mysqld.Tpo" ".deps/mysqld.Po"; \
else rm -f ".deps/mysqld.Tpo"; exit 1; \
fi
/usr/include/tcpd.h: In function `void* handle_connections_sockets(void*)':
/usr/include/tcpd.h:131: too many arguments to function `void sock_host()'
mysqld.cc:3528: at this point in file
/usr/include/tcpd.h:69: too many arguments to function `int hosts_access()'
mysqld.cc:3529: at this point in file
/usr/include/tcpd.h:124: too many arguments to function `char* eval_client()'
mysqld.cc:3537: at this point in file
make[4]: *** [mysqld.o] Error 1
make[4]: Leaving directory `/tmp/mysql-4.1.7/sql'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/tmp/mysql-4.1.7/sql'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/tmp/mysql-4.1.7/sql'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/tmp/mysql-4.1.7'
make: *** [all] Error 2
[24 Dec 2004 15:35] Ramil Kalimullin
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

fixed in 4.0.24