Skip to content

Commit

Permalink
Bug #16581605: REPLACE.EXE UTILITY IS BROKEN IN 5.5
Browse files Browse the repository at this point in the history
Description:- Replace, the string replacement utility fails
on the windows platform.

Analysis:- The utility takes files and multiple string
pairs as input. In the windows platform, the utility maps
the standard input incorrectly (Considers 0 as the fd for
standard input instead of 2048 on windows). Hence when the
input file is supplied to the utility due to the incorrect
mapping, a bad file descriptor error is generated causing
the utility to exit with an error.

Fix:- "my_fileno()" is used for getting the correct file
despscriptor for standard input.
  • Loading branch information
Arun Kuruvila authored and kevincrane committed Feb 10, 2015
1 parent 19fe49c commit 878a72f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions extra/replace.c
@@ -1,5 +1,5 @@
/*
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -1020,7 +1020,7 @@ FILE *in,*out;
updated=retain=0;
reset_buffer();

while ((error=fill_buffer_retaining(fileno(in),retain)) > 0)
while ((error=fill_buffer_retaining(my_fileno(in),retain)) > 0)
{
end_of_line=buffer ;
buffer[bufbytes]=0; /* Sentinel */
Expand Down
8 changes: 8 additions & 0 deletions mysql-test/mysql-test-run.pl
Expand Up @@ -2476,6 +2476,14 @@ sub environment_setup {
"$path_client_bindir/perror");
$ENV{'MY_PERROR'}= native_path($exe_perror);

# ----------------------------------------------------
# replace
# ----------------------------------------------------
my $exe_replace= mtr_exe_exists(vs_config_dirs('extra', 'replace'),
"$basedir/extra/replace",
"$path_client_bindir/replace");
$ENV{'REPLACE'}= native_path($exe_replace);

# Create an environment variable to make it possible
# to detect that valgrind is being used from test cases
$ENV{'VALGRIND_TEST'}= $opt_valgrind;
Expand Down
5 changes: 5 additions & 0 deletions mysql-test/r/windows.result
Expand Up @@ -60,3 +60,8 @@ SELECT VARIABLE_NAME FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME = 'socket';
VARIABLE_NAME
SOCKET
#
# Bug#16581605: REPLACE.EXE UTILITY IS BROKEN IN 5.5
#
xyz
def
16 changes: 16 additions & 0 deletions mysql-test/t/windows.test
Expand Up @@ -98,3 +98,19 @@ deallocate prepare abc;

SELECT VARIABLE_NAME FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME = 'socket';

--echo #
--echo # Bug#16581605: REPLACE.EXE UTILITY IS BROKEN IN 5.5
--echo #

# Creating a temporary text file.
--write_file $MYSQL_TMP_DIR/bug16581605.txt
abc
def
EOF

#REPLACE.EXE UTILITY will work fine after the fix.
--exec $REPLACE abc xyz < $MYSQL_TMP_DIR/bug16581605.txt

#Cleanup
remove_file $MYSQL_TMP_DIR/bug16581605.txt;

0 comments on commit 878a72f

Please sign in to comment.