Skip to content

Commit cc12883

Browse files
author
Ramil Kalimullin
committed
Fix for bug#48451: my_seek and my_tell ignore MY_WME flag
my_seek() and my_tell() functions now honour MY_WME flag.
1 parent a9d18aa commit cc12883

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

include/mysys_err.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ extern const char * NEAR globerrs[]; /* my_error_messages is here */
6464
#define EE_FILE_NOT_CLOSED 30
6565
#define EE_CHANGE_OWNERSHIP 31
6666
#define EE_CHANGE_PERMISSIONS 32
67-
#define EE_ERROR_LAST 32 /* Copy last error nr */
67+
#define EE_CANT_SEEK 33
68+
#define EE_ERROR_LAST 33 /* Copy last error nr */
6869
/* Add error numbers before EE_ERROR_LAST and change it accordingly. */
6970

7071
/* exit codes for all MySQL programs */

mysys/errors.c

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const char * NEAR globerrs[GLOBERRS]=
5252
"File '%s' (fileno: %d) was not closed",
5353
"Can't change ownership of the file '%s' (Errcode: %d)",
5454
"Can't change permissions of the file '%s' (Errcode: %d)",
55+
"Can't seek in file '%s' (Errcode: %d)"
5556
};
5657

5758
void init_glob_errs(void)
@@ -94,6 +95,7 @@ void init_glob_errs()
9495
EE(EE_FILE_NOT_CLOSED) = "File '%s' (fileno: %d) was not closed";
9596
EE(EE_CHANGE_OWNERSHIP) = "Can't change ownership of the file '%s' (Errcode: %d)";
9697
EE(EE_CHANGE_PERMISSIONS) = "Can't change permissions of the file '%s' (Errcode: %d)";
98+
EE(EE_CANT_SEEK) = "Can't seek in file '%s' (Errcode: %d)";
9799
}
98100
#endif
99101

mysys/my_seek.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
1515

1616
#include "mysys_priv.h"
17+
#include "mysys_err.h"
1718

1819
/*
1920
Seek to a position in a file.
@@ -42,8 +43,7 @@
4243
actual error.
4344
*/
4445

45-
my_off_t my_seek(File fd, my_off_t pos, int whence,
46-
myf MyFlags __attribute__((unused)))
46+
my_off_t my_seek(File fd, my_off_t pos, int whence, myf MyFlags)
4747
{
4848
reg1 os_off_t newpos= -1;
4949
DBUG_ENTER("my_seek");
@@ -69,6 +69,8 @@ my_off_t my_seek(File fd, my_off_t pos, int whence,
6969
if (newpos == (os_off_t) -1)
7070
{
7171
my_errno=errno;
72+
if (MyFlags & MY_WME)
73+
my_error(EE_CANT_SEEK, MYF(0), my_filename(fd), my_errno);
7274
DBUG_PRINT("error",("lseek: %lu errno: %d", (ulong) newpos,errno));
7375
DBUG_RETURN(MY_FILEPOS_ERROR);
7476
}
@@ -83,7 +85,7 @@ my_off_t my_seek(File fd, my_off_t pos, int whence,
8385
/* Tell current position of file */
8486
/* ARGSUSED */
8587

86-
my_off_t my_tell(File fd, myf MyFlags __attribute__((unused)))
88+
my_off_t my_tell(File fd, myf MyFlags)
8789
{
8890
os_off_t pos;
8991
DBUG_ENTER("my_tell");
@@ -95,7 +97,12 @@ my_off_t my_tell(File fd, myf MyFlags __attribute__((unused)))
9597
pos=lseek(fd, 0L, MY_SEEK_CUR);
9698
#endif
9799
if (pos == (os_off_t) -1)
100+
{
98101
my_errno=errno;
102+
if (MyFlags & MY_WME)
103+
my_error(EE_CANT_SEEK, MYF(0), my_filename(fd), my_errno);
104+
DBUG_PRINT("error", ("tell: %lu errno: %d", (ulong) pos, my_errno));
105+
}
99106
DBUG_PRINT("exit",("pos: %lu", (ulong) pos));
100107
DBUG_RETURN((my_off_t) pos);
101108
} /* my_tell */

mysys/my_symlink.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ int my_is_symlink(const char *filename __attribute__((unused)))
118118
'to' may be equal to 'filename'
119119
*/
120120

121-
int my_realpath(char *to, const char *filename,
122-
myf MyFlags __attribute__((unused)))
121+
int my_realpath(char *to, const char *filename, myf MyFlags)
123122
{
124123
#if defined(HAVE_REALPATH) && !defined(HAVE_BROKEN_REALPATH)
125124
int result=0;

storage/myisam/ha_myisam.cc

+10-2
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,11 @@ int ha_myisam::net_read_dump(NET* net)
590590
int data_fd = file->dfile;
591591
int error = 0;
592592

593-
my_seek(data_fd, 0L, MY_SEEK_SET, MYF(MY_WME));
593+
if (my_seek(data_fd, 0L, MY_SEEK_SET, MYF(MY_WME)) == MY_FILEPOS_ERROR)
594+
{
595+
error= my_errno;
596+
goto err;
597+
}
594598
for (;;)
595599
{
596600
ulong packet_len = my_net_read(net);
@@ -626,7 +630,11 @@ int ha_myisam::dump(THD* thd, int fd)
626630
return ENOMEM;
627631

628632
int error = 0;
629-
my_seek(data_fd, 0L, MY_SEEK_SET, MYF(MY_WME));
633+
if (my_seek(data_fd, 0L, MY_SEEK_SET, MYF(MY_WME)) == MY_FILEPOS_ERROR)
634+
{
635+
error= my_errno;
636+
goto err;
637+
}
630638
for (; bytes_to_read > 0;)
631639
{
632640
size_t bytes = my_read(data_fd, buf, blocksize, MYF(MY_WME));

0 commit comments

Comments
 (0)