summaryrefslogtreecommitdiff
path: root/mysys/my_getwd.c
diff options
context:
space:
mode:
authorGeorgi Kodinov <joro@sun.com>2010-05-05 11:54:52 +0300
committerGeorgi Kodinov <joro@sun.com>2010-05-05 11:54:52 +0300
commitaddd0a3e67164037149140b71c027272ecbaee49 (patch)
tree3e5ae4df9250bbbafbe8258494b8f2b3e1cec431 /mysys/my_getwd.c
parented4819bbf7ebeeac1c64d5ea772dd2507af9b1d2 (diff)
downloadmariadb-git-addd0a3e67164037149140b71c027272ecbaee49.tar.gz
On behalf of Kristofer :
Bug#53417 my_getwd() makes assumptions on the buffer sizes which not always hold true The mysys library contains many functions for rewriting file paths. Most of these functions makes implicit assumptions on the buffer sizes they write to. If a path is put in my_realpath() it will propagate to my_getwd() which assumes that the buffer holding the path name is greater than 2. This is not true in cases. In the special case where a VARBIN_ITEM is passed as argument to the LOAD_FILE function this can lead to a crash. This patch fixes the issue by introduce more safe guards agaist buffer overruns.
Diffstat (limited to 'mysys/my_getwd.c')
-rw-r--r--mysys/my_getwd.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/mysys/my_getwd.c b/mysys/my_getwd.c
index e0c5b94b53e..e6b867e2753 100644
--- a/mysys/my_getwd.c
+++ b/mysys/my_getwd.c
@@ -50,11 +50,16 @@ int my_getwd(char * buf, size_t size, myf MyFlags)
DBUG_PRINT("my",("buf: 0x%lx size: %u MyFlags %d",
(long) buf, (uint) size, MyFlags));
+ if (size < 1)
+ return(-1);
+
if (curr_dir[0]) /* Current pos is saved here */
VOID(strmake(buf,&curr_dir[0],size-1));
else
{
#if defined(HAVE_GETCWD)
+ if (size < 2)
+ return(-1);
if (!getcwd(buf,(uint) (size-2)) && MyFlags & MY_WME)
{
my_errno=errno;
@@ -68,6 +73,8 @@ int my_getwd(char * buf, size_t size, myf MyFlags)
strmake(buf,pathname,size-1);
}
#elif defined(VMS)
+ if (size < 2)
+ return(-1);
if (!getcwd(buf,size-2,1) && MyFlags & MY_WME)
{
my_errno=errno;