Skip to content

Commit 43741a3

Browse files
committed
Fixed bug #62889
Our minimum libmysqlclient version requirement is high enough that we don't need to check for MYSQL_OPT_LOCAL_INFILE support. However, the mysql_get_option() function seems to only be available since 5.7 (though it's really hard to find any definitie information on when MySQL introduced certain functions or changes...) so we need to store the value of the flag locally to make it available through getAttribute().
1 parent c927c83 commit 43741a3

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ PHP NEWS
5656
missing). (Nikita)
5757
. Fixed bug #72368 (PdoStatement->execute() fails but does not throw an
5858
exception). (Nikita)
59+
. Fixed bug #62889 (LOAD DATA INFILE broken). (Nikita)
5960

6061
- Phar:
6162
. Fixed bug #73809 (Phar Zip parse crash - mmap fail). (cmb)

ext/pdo_mysql/mysql_driver.c

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,11 @@ static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_
508508
case PDO_MYSQL_ATTR_MAX_BUFFER_SIZE:
509509
ZVAL_LONG(return_value, H->max_buffer_size);
510510
break;
511-
#else
511+
#endif
512+
512513
case PDO_MYSQL_ATTR_LOCAL_INFILE:
513-
ZVAL_BOOL(
514-
return_value,
515-
(H->server->data->options->flags & CLIENT_LOCAL_FILES) == CLIENT_LOCAL_FILES);
514+
ZVAL_BOOL(return_value, H->local_infile);
516515
break;
517-
#endif
518516

519517
default:
520518
PDO_DBG_RETURN(0);
@@ -709,18 +707,15 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options)
709707
goto cleanup;
710708
}
711709

712-
#if defined(MYSQL_OPT_LOCAL_INFILE) || defined(PDO_USE_MYSQLND)
713-
unsigned int local_infile = (unsigned int) pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_LOCAL_INFILE, 0);
714-
# ifndef PDO_USE_MYSQLND
715-
if (PG(open_basedir) && PG(open_basedir)[0] != '\0') {
716-
local_infile = 0;
717-
}
718-
# endif
719-
if (mysql_options(H->server, MYSQL_OPT_LOCAL_INFILE, (const char *)&local_infile)) {
720-
pdo_mysql_error(dbh);
721-
goto cleanup;
722-
}
710+
if (pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_LOCAL_INFILE, 0)) {
711+
H->local_infile = 1;
712+
#ifndef PDO_USE_MYSQLND
713+
if (PG(open_basedir) && PG(open_basedir)[0] != '\0') {
714+
H->local_infile = 0;
715+
}
723716
#endif
717+
}
718+
724719
#ifdef MYSQL_OPT_RECONNECT
725720
/* since 5.0.3, the default for this option is 0 if not specified.
726721
* we want the old behaviour
@@ -824,15 +819,13 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options)
824819
}
825820
}
826821
#endif
827-
} else {
828-
#if defined(MYSQL_OPT_LOCAL_INFILE) || defined(PDO_USE_MYSQLND)
829-
// in case there are no driver options disable 'local infile' explicitly
830-
unsigned int local_infile = 0;
831-
if (mysql_options(H->server, MYSQL_OPT_LOCAL_INFILE, (const char *)&local_infile)) {
832-
pdo_mysql_error(dbh);
833-
goto cleanup;
834-
}
835-
#endif
822+
}
823+
824+
/* Always explicitly set the LOCAL_INFILE option. */
825+
unsigned int local_infile = H->local_infile;
826+
if (mysql_options(H->server, MYSQL_OPT_LOCAL_INFILE, (const char *)&local_infile)) {
827+
pdo_mysql_error(dbh);
828+
goto cleanup;
836829
}
837830

838831
if (vars[0].optval && mysql_options(H->server, MYSQL_SET_CHARSET_NAME, vars[0].optval)) {

ext/pdo_mysql/php_pdo_mysql_int.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ typedef struct {
104104
unsigned buffered:1;
105105
unsigned emulate_prepare:1;
106106
unsigned fetch_table_names:1;
107+
unsigned local_infile:1;
107108
#ifndef PDO_USE_MYSQLND
108109
zend_ulong max_buffer_size;
109110
#endif

0 commit comments

Comments
 (0)