2001-12-06 13:10:51 +01:00
|
|
|
/* Copyright (C) 2000 MySQL AB
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
2000-11-16 02:58:58 +01:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2001-12-06 13:10:51 +01:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
2000-11-16 02:58:58 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
More functions to be used with IO_CACHE files
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MAP_TO_USE_RAID
|
|
|
|
#include "mysys_priv.h"
|
|
|
|
#include <m_string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <m_ctype.h>
|
2002-01-27 06:26:24 +01:00
|
|
|
|
2006-10-02 15:08:40 +02:00
|
|
|
/*
|
|
|
|
Copy contents of an IO_CACHE to a file.
|
|
|
|
|
|
|
|
SYNOPSIS
|
BUG#19459 (BINLOG RBR command does not lock tables correctly causing
crash for, e.g., NDB):
Before, mysqlbinlog printed table map events as a separate statement, so
when executing the event, the opened table was subsequently closed
when the statement ended. Instead, the row-based events that make up
a statement are now printed as *one* BINLOG statement, which means
that the table maps and the following *_rows_log_event events are
executed fully before the statement ends.
Changing implementation of BINLOG statement to be able to read the
emitted format, which now consists of several chunks of BASE64-encoded
data.
client/mysqlbinlog.cc:
Using IO_CACHE to print events instead of directly to file.
Factoring out code to write event header and base64 representation into
separate function.
mysys/mf_iocache2.c:
Correcting name in documentation.
sql/log_event.cc:
Adding class Write_on_release_cache that holds an IO_CACHE and that
will write contents of IO_CACHE to a designated file on destruction.
Changing signature of event printing functions print_header() and print_base64()
to write to IO_CACHE and changing *all* calls in those functions in accordance.
This means that all printing functions now print to an IO_CACHE instead of to a file,
and that the IO_CACHE is then copied to the file.
The print() function have the same signature as before, but since it is
using print_header() and print_base64(), the data will now be printed
to an IO_CACHE and then copied to the file.
Changing row-based replication events to incrementally build one
BINLOG statement for all events making up a statement.
sql/log_event.h:
Changing signature of event printing functions print_header() and
print_base64() to write to an IO_CACHE instead of a file.
Changing row-based replication events to incrementally build one
BINLOG statement for all events making up a statement.
Adding a head_cache and a body_cache to cache statement comment
and statement body respectively. In addition, the head_cache is used
when printing other events than the RBR events.
sql/sql_binlog.cc:
Changing code to be able to decode several pieces of base64-encoded data
for a BINLOG statement. The BINLOG statement now consists of several pieces
of BASE64-encoded data, so once a block has been decoded and executed, the
next block has to be read from the statement until there is no more
data to read.
2006-10-06 10:17:02 +02:00
|
|
|
my_b_copy_to_file()
|
2006-10-02 15:08:40 +02:00
|
|
|
cache IO_CACHE to copy from
|
|
|
|
file File to copy to
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
Copy the contents of the cache to the file. The cache will be
|
|
|
|
re-inited to a read cache and will read from the beginning of the
|
|
|
|
cache.
|
|
|
|
|
|
|
|
If a failure to write fully occurs, the cache is only copied
|
|
|
|
partially.
|
|
|
|
|
|
|
|
TODO
|
|
|
|
Make this function solid by handling partial reads from the cache
|
|
|
|
in a correct manner: it should be atomic.
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
0 All OK
|
|
|
|
1 An error occured
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
my_b_copy_to_file(IO_CACHE *cache, FILE *file)
|
|
|
|
{
|
|
|
|
byte buf[IO_SIZE];
|
2006-10-10 12:29:24 +02:00
|
|
|
uint bytes_in_cache;
|
2006-10-02 15:08:40 +02:00
|
|
|
DBUG_ENTER("my_b_copy_to_file");
|
|
|
|
|
|
|
|
/* Reinit the cache to read from the beginning of the cache */
|
|
|
|
if (reinit_io_cache(cache, READ_CACHE, 0L, FALSE, FALSE))
|
|
|
|
DBUG_RETURN(1);
|
2006-10-10 12:29:24 +02:00
|
|
|
bytes_in_cache= my_b_bytes_in_cache(cache);
|
2006-10-02 15:08:40 +02:00
|
|
|
while (bytes_in_cache > 0) {
|
|
|
|
uint const read_bytes= min(bytes_in_cache, sizeof(buf));
|
|
|
|
DBUG_PRINT("debug", ("Remaining %u bytes - Reading %u bytes",
|
|
|
|
bytes_in_cache, read_bytes));
|
|
|
|
if (my_b_read(cache, buf, read_bytes))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
if (my_fwrite(file, buf, read_bytes, MYF(MY_WME | MY_NABP)) == (uint) -1)
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
bytes_in_cache -= read_bytes;
|
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2002-01-27 06:26:24 +01:00
|
|
|
my_off_t my_b_append_tell(IO_CACHE* info)
|
|
|
|
{
|
2002-06-11 10:20:31 +02:00
|
|
|
/*
|
|
|
|
Prevent optimizer from putting res in a register when debugging
|
|
|
|
we need this to be able to see the value of res when the assert fails
|
2002-01-31 19:02:11 +01:00
|
|
|
*/
|
|
|
|
dbug_volatile my_off_t res;
|
2002-06-11 10:20:31 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
We need to lock the append buffer mutex to keep flush_io_cache()
|
|
|
|
from messing with the variables that we need in order to provide the
|
|
|
|
answer to the question.
|
|
|
|
*/
|
2002-01-27 06:26:24 +01:00
|
|
|
#ifdef THREAD
|
|
|
|
pthread_mutex_lock(&info->append_buffer_lock);
|
|
|
|
#endif
|
2002-02-01 00:17:24 +01:00
|
|
|
#ifndef DBUG_OFF
|
2002-06-11 10:20:31 +02:00
|
|
|
/*
|
|
|
|
Make sure EOF is where we think it is. Note that we cannot just use
|
|
|
|
my_tell() because we have a reader thread that could have left the
|
|
|
|
file offset in a non-EOF location
|
|
|
|
*/
|
2002-02-01 00:17:24 +01:00
|
|
|
{
|
2002-06-11 10:20:31 +02:00
|
|
|
volatile my_off_t save_pos;
|
|
|
|
save_pos = my_tell(info->file,MYF(0));
|
|
|
|
my_seek(info->file,(my_off_t)0,MY_SEEK_END,MYF(0));
|
|
|
|
/*
|
|
|
|
Save the value of my_tell in res so we can see it when studying coredump
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT(info->end_of_file - (info->append_read_pos-info->write_buffer)
|
|
|
|
== (res=my_tell(info->file,MYF(0))));
|
|
|
|
my_seek(info->file,save_pos,MY_SEEK_SET,MYF(0));
|
2002-02-01 00:17:24 +01:00
|
|
|
}
|
|
|
|
#endif
|
2002-01-27 06:26:24 +01:00
|
|
|
res = info->end_of_file + (info->write_pos-info->append_read_pos);
|
|
|
|
#ifdef THREAD
|
|
|
|
pthread_mutex_unlock(&info->append_buffer_lock);
|
|
|
|
#endif
|
|
|
|
return res;
|
|
|
|
}
|
2000-11-16 02:58:58 +01:00
|
|
|
|
This will be pushed only after I fix the testsuite.
This is the main commit for Worklog tasks:
* A more dynamic binlog format which allows small changes (1064)
* Log session variables in Query_log_event (1063)
Below 5.0 means 5.0.0.
MySQL 5.0 is able to replicate FOREIGN_KEY_CHECKS, UNIQUE_KEY_CHECKS (for speed),
SQL_AUTO_IS_NULL, SQL_MODE. Not charsets (WL#1062), not some vars (I can only think
of SQL_SELECT_LIMIT, which deserves a special treatment). Note that this
works for queries, except LOAD DATA INFILE (for this it would have to wait
for Dmitri's push of WL#874, which in turns waits for the present push, so...
the deadlock must be broken!). Note that when Dmitri pushes WL#874 in 5.0.1,
5.0.0 won't be able to replicate a LOAD DATA INFILE from 5.0.1.
Apart from that, the new binlog format is designed so that it can tolerate
a little variation in the events (so that a 5.0.0 slave could replicate a
5.0.1 master, except for LOAD DATA INFILE unfortunately); that is, when I
later add replication of charsets it should break nothing. And when I later
add a UID to every event, it should break nothing.
The main change brought by this patch is a new type of event, Format_description_log_event,
which describes some lengthes in other event types. This event is needed for
the master/slave/mysqlbinlog to understand a 5.0 log. Thanks to this event,
we can later add more bytes to the header of every event without breaking compatibility.
Inside Query_log_event, we have some additional dynamic format, as every Query_log_event
can have a different number of status variables, stored as pairs (code, value); that's
how SQL_MODE and session variables and catalog are stored. Like this, we can later
add count of affected rows, charsets... and we can have options --don't-log-count-affected-rows
if we want.
MySQL 5.0 is able to run on 4.x relay logs, 4.x binlogs.
Upgrading a 4.x master to 5.0 is ok (no need to delete binlogs),
upgrading a 4.x slave to 5.0 is ok (no need to delete relay logs);
so both can be "hot" upgrades.
Upgrading a 3.23 master to 5.0 requires as much as upgrading it to 4.0.
3.23 and 4.x can't be slaves of 5.0.
So downgrading from 5.0 to 4.x may be complicated.
Log_event::log_pos is now the position of the end of the event, which is
more useful than the position of the beginning. We take care about compatibility
with <5.0 (in which log_pos is the beginning).
I added a short test for replication of SQL_MODE and some other variables.
TODO:
- after committing this, merge the latest 5.0 into it
- fix all tests
- update the manual with upgrade notes.
client/Makefile.am:
mysqlbinlog.cc depends slightly on sql/mysql_priv.h
client/mysqlbinlog.cc:
Make mysqlbinlog able to read the new binlog format,
by seeking to the start and reading the first few events, to
detect the format of the binlog.
include/my_sys.h:
a correct tell() for SEQ_READ_APPEND caches.
mysys/mf_iocache2.c:
a correct tell() for SEQ_READ_APPEND caches
(my_b_tell() is not working for such caches).
sql/ha_innodb.cc:
we are getting rid of event lengthes here and there, which is good.
sql/log.cc:
Start events will have created==0 if generated by rotation (like in 3.23).
In 5.0 we always write a Format_description_log_event at the beginning of
every master's binary log and of every slave's relay log.
We also add Rotate and Stop to relay logs (like there already was in
master's binary logs).
When we rotate a relay log, we write the previous relay log's Start event
(the one which was sent from the master) to the beginning of the new log,
so that we don't need the previous relay log to understand the new one;
that's the purpose of MYSQL_LOG::description_event_for_queue.
Removed logging of SET FOREIGN_KEY_CHECKS, because we handle it as flags
in the Query event now.
sql/log_event.cc:
New event type: Format_description_log_event, to describe the log's format.
read_log_event() needs to be passed this event to be able to read 5.0 events.
Query_log_event has new members flags2 and sql_mode for replication of session
variables (except charsets which are WL#1062) and SQL_MODE.
flags2 is in fact a kind of copy of thd->options (&'d with a mask).
Now with this replication of FOREIGN_KEY_CHECKS, SQL_AUTO_IS_NULL, UNIQUE_CHECKS
and SQL_MODE work; with mysqlbinlog too.
sql/log_event.h:
Binlog version is changed to 4.
New classes (details in sql/log_event.cc).
Removing some useless #defines.
sql/mysql_priv.h:
Definition of SELECT_DISTINCT and others must be visible in client/mysqlbinlog.cc,
so adding #ifdefs.
sql/mysqld.cc:
update for prototype change
sql/slave.cc:
When the slave opens a relay log, it reads the first few events to know the format.
When slave I/O thread receives a Rotate from the master, it rotates its relay log
(to avoid mixed format in the relay log).
sql/slave.h:
in the slave we avoid lengthes and rely on absolute positions instead;
hence the introduction of future_group_master_log_pos and future_event_relay_log_pos
(explained in code).
sql/sql_class.cc:
catalog in THD
sql/sql_class.h:
catalog, and new members in MYSQL_LOG
sql/sql_repl.cc:
When the master starts sending binlog to slave, it must
first read the first few events to detect the binlog's format.
Same for SHOW BINLOG EVENTS.
2003-12-18 01:09:05 +01:00
|
|
|
my_off_t my_b_safe_tell(IO_CACHE *info)
|
|
|
|
{
|
|
|
|
if (unlikely(info->type == SEQ_READ_APPEND))
|
|
|
|
return my_b_append_tell(info);
|
|
|
|
return my_b_tell(info);
|
|
|
|
}
|
|
|
|
|
2000-11-16 02:58:58 +01:00
|
|
|
/*
|
2002-01-27 06:26:24 +01:00
|
|
|
Make next read happen at the given position
|
|
|
|
For write cache, make next write happen at the given position
|
2000-11-16 02:58:58 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
void my_b_seek(IO_CACHE *info,my_off_t pos)
|
|
|
|
{
|
2006-01-03 17:54:54 +01:00
|
|
|
my_off_t offset;
|
2001-11-28 01:55:52 +01:00
|
|
|
DBUG_ENTER("my_b_seek");
|
|
|
|
DBUG_PRINT("enter",("pos: %lu", (ulong) pos));
|
|
|
|
|
2002-01-20 03:16:52 +01:00
|
|
|
/*
|
2002-06-11 10:20:31 +02:00
|
|
|
TODO:
|
|
|
|
Verify that it is OK to do seek in the non-append
|
|
|
|
area in SEQ_READ_APPEND cache
|
2002-01-20 03:16:52 +01:00
|
|
|
a) see if this always works
|
|
|
|
b) see if there is a better way to make it work
|
|
|
|
*/
|
|
|
|
if (info->type == SEQ_READ_APPEND)
|
2006-01-03 17:54:54 +01:00
|
|
|
VOID(flush_io_cache(info));
|
|
|
|
|
2002-01-20 03:16:52 +01:00
|
|
|
offset=(pos - info->pos_in_file);
|
2006-01-03 17:54:54 +01:00
|
|
|
|
2002-01-20 03:16:52 +01:00
|
|
|
if (info->type == READ_CACHE || info->type == SEQ_READ_APPEND)
|
Lots of fixes for BDB tables
Change DROP TABLE to first drop the data, then the .frm file
Docs/manual.texi:
Updated TODO and Changelog
include/Makefile.am:
Portability fix
mysql-test/misc/select.res:
***MISSING WEAVE***
mysys/mf_iocache2.c:
cleanup
scripts/mysqlhotcopy.sh:
Fixed --noindices
sql-bench/Results/ATIS-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/RUN-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/alter-table-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/big-tables-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/connect-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/create-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/insert-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/select-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/wisconsin-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/limits/pg.cfg:
Updated to new crash-me
sql-bench/server-cfg.sh:
Fixes for pg 7.0.2
sql/ha_berkeley.cc:
Lots of BDB table fixes
sql/ha_berkeley.h:
Lots of BDB table fixes
sql/handler.cc:
Change DROP TABLE to first drop the data, then the .frm file
sql/hostname.cc:
Fixes for empty hostnames
sql/log.cc:
Fixed transaction logging
sql/share/swedish/errmsg.OLD:
cleanup
sql/sql_delete.cc:
Fixes for logging
sql/sql_insert.cc:
Fixes for logging
sql/sql_select.cc:
Fixes for BDB tables
sql/sql_table.cc:
Change DROP TABLE to first drop the data, then the .frm file
sql/sql_update.cc:
Fixes for logging
BitKeeper/etc/ignore:
Added scripts/mysqld_multi to the ignore list
BitKeeper/etc/logging_ok:
Logging to logging@openlogging.org accepted
2000-12-08 16:04:57 +01:00
|
|
|
{
|
2002-01-20 03:16:52 +01:00
|
|
|
/* TODO: explain why this works if pos < info->pos_in_file */
|
2001-11-28 02:47:15 +01:00
|
|
|
if ((ulonglong) offset < (ulonglong) (info->read_end - info->buffer))
|
2001-11-28 01:55:52 +01:00
|
|
|
{
|
2001-11-28 02:47:15 +01:00
|
|
|
/* The read is in the current buffer; Reuse it */
|
|
|
|
info->read_pos = info->buffer + offset;
|
2001-11-28 01:55:52 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Force a new read on next my_b_read */
|
|
|
|
info->read_pos=info->read_end=info->buffer;
|
|
|
|
}
|
Lots of fixes for BDB tables
Change DROP TABLE to first drop the data, then the .frm file
Docs/manual.texi:
Updated TODO and Changelog
include/Makefile.am:
Portability fix
mysql-test/misc/select.res:
***MISSING WEAVE***
mysys/mf_iocache2.c:
cleanup
scripts/mysqlhotcopy.sh:
Fixed --noindices
sql-bench/Results/ATIS-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/RUN-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/alter-table-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/big-tables-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/connect-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/create-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/insert-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/select-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/wisconsin-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/limits/pg.cfg:
Updated to new crash-me
sql-bench/server-cfg.sh:
Fixes for pg 7.0.2
sql/ha_berkeley.cc:
Lots of BDB table fixes
sql/ha_berkeley.h:
Lots of BDB table fixes
sql/handler.cc:
Change DROP TABLE to first drop the data, then the .frm file
sql/hostname.cc:
Fixes for empty hostnames
sql/log.cc:
Fixed transaction logging
sql/share/swedish/errmsg.OLD:
cleanup
sql/sql_delete.cc:
Fixes for logging
sql/sql_insert.cc:
Fixes for logging
sql/sql_select.cc:
Fixes for BDB tables
sql/sql_table.cc:
Change DROP TABLE to first drop the data, then the .frm file
sql/sql_update.cc:
Fixes for logging
BitKeeper/etc/ignore:
Added scripts/mysqld_multi to the ignore list
BitKeeper/etc/logging_ok:
Logging to logging@openlogging.org accepted
2000-12-08 16:04:57 +01:00
|
|
|
}
|
|
|
|
else if (info->type == WRITE_CACHE)
|
|
|
|
{
|
2001-11-28 01:55:52 +01:00
|
|
|
/* If write is in current buffer, reuse it */
|
2001-11-28 02:47:15 +01:00
|
|
|
if ((ulonglong) offset <
|
|
|
|
(ulonglong) (info->write_end - info->write_buffer))
|
2001-11-28 01:55:52 +01:00
|
|
|
{
|
2001-11-28 02:47:15 +01:00
|
|
|
info->write_pos = info->write_buffer + offset;
|
2001-11-28 01:55:52 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
2006-01-03 17:54:54 +01:00
|
|
|
VOID(flush_io_cache(info));
|
2001-11-28 15:11:05 +01:00
|
|
|
/* Correct buffer end so that we write in increments of IO_SIZE */
|
|
|
|
info->write_end=(info->write_buffer+info->buffer_length-
|
|
|
|
(pos & (IO_SIZE-1)));
|
Lots of fixes for BDB tables
Change DROP TABLE to first drop the data, then the .frm file
Docs/manual.texi:
Updated TODO and Changelog
include/Makefile.am:
Portability fix
mysql-test/misc/select.res:
***MISSING WEAVE***
mysys/mf_iocache2.c:
cleanup
scripts/mysqlhotcopy.sh:
Fixed --noindices
sql-bench/Results/ATIS-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/RUN-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/alter-table-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/big-tables-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/connect-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/create-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/insert-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/select-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/Results/wisconsin-pg-Linux_2.2.14_my_SMP_i686-cmp-mysql,pg:
Updated benchmarks
sql-bench/limits/pg.cfg:
Updated to new crash-me
sql-bench/server-cfg.sh:
Fixes for pg 7.0.2
sql/ha_berkeley.cc:
Lots of BDB table fixes
sql/ha_berkeley.h:
Lots of BDB table fixes
sql/handler.cc:
Change DROP TABLE to first drop the data, then the .frm file
sql/hostname.cc:
Fixes for empty hostnames
sql/log.cc:
Fixed transaction logging
sql/share/swedish/errmsg.OLD:
cleanup
sql/sql_delete.cc:
Fixes for logging
sql/sql_insert.cc:
Fixes for logging
sql/sql_select.cc:
Fixes for BDB tables
sql/sql_table.cc:
Change DROP TABLE to first drop the data, then the .frm file
sql/sql_update.cc:
Fixes for logging
BitKeeper/etc/ignore:
Added scripts/mysqld_multi to the ignore list
BitKeeper/etc/logging_ok:
Logging to logging@openlogging.org accepted
2000-12-08 16:04:57 +01:00
|
|
|
}
|
2000-11-16 02:58:58 +01:00
|
|
|
info->pos_in_file=pos;
|
2000-11-25 03:49:13 +01:00
|
|
|
info->seek_not_done=1;
|
2002-04-02 06:46:23 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2000-11-16 02:58:58 +01:00
|
|
|
}
|
|
|
|
|
2001-11-28 15:11:05 +01:00
|
|
|
|
2000-11-16 02:58:58 +01:00
|
|
|
/*
|
2001-11-28 15:11:05 +01:00
|
|
|
Fill buffer. Note that this assumes that you have already used
|
|
|
|
all characters in the CACHE, independent of the read_pos value!
|
|
|
|
return: 0 on error or EOF (info->error = -1 on error)
|
|
|
|
number of characters
|
2000-11-16 02:58:58 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
uint my_b_fill(IO_CACHE *info)
|
|
|
|
{
|
2001-11-28 01:55:52 +01:00
|
|
|
my_off_t pos_in_file=(info->pos_in_file+
|
|
|
|
(uint) (info->read_end - info->buffer));
|
2000-11-16 02:58:58 +01:00
|
|
|
my_off_t max_length;
|
|
|
|
uint diff_length,length;
|
|
|
|
if (info->seek_not_done)
|
|
|
|
{ /* File touched, do seek */
|
|
|
|
if (my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)) ==
|
|
|
|
MY_FILEPOS_ERROR)
|
|
|
|
{
|
|
|
|
info->error= 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
info->seek_not_done=0;
|
|
|
|
}
|
|
|
|
diff_length=(uint) (pos_in_file & (IO_SIZE-1));
|
|
|
|
max_length= (my_off_t) (info->end_of_file - pos_in_file);
|
|
|
|
if (max_length > (my_off_t) (info->read_length-diff_length))
|
|
|
|
max_length=(my_off_t) (info->read_length-diff_length);
|
|
|
|
if (!max_length)
|
|
|
|
{
|
|
|
|
info->error= 0;
|
|
|
|
return 0; /* EOF */
|
|
|
|
}
|
|
|
|
else if ((length=my_read(info->file,info->buffer,(uint) max_length,
|
|
|
|
info->myflags)) == (uint) -1)
|
|
|
|
{
|
|
|
|
info->error= -1;
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-28 01:55:52 +01:00
|
|
|
info->read_pos=info->buffer;
|
|
|
|
info->read_end=info->buffer+length;
|
2000-11-16 02:58:58 +01:00
|
|
|
info->pos_in_file=pos_in_file;
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2001-11-28 15:11:05 +01:00
|
|
|
|
2000-11-16 02:58:58 +01:00
|
|
|
/*
|
2001-11-28 15:11:05 +01:00
|
|
|
Read a string ended by '\n' into a buffer of 'max_length' size.
|
|
|
|
Returns number of characters read, 0 on error.
|
|
|
|
last byte is set to '\0'
|
|
|
|
If buffer is full then to[max_length-1] will be set to \0.
|
2000-11-16 02:58:58 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
uint my_b_gets(IO_CACHE *info, char *to, uint max_length)
|
|
|
|
{
|
2001-01-07 23:04:30 +01:00
|
|
|
char *start = to;
|
2000-11-16 02:58:58 +01:00
|
|
|
uint length;
|
|
|
|
max_length--; /* Save place for end \0 */
|
|
|
|
/* Calculate number of characters in buffer */
|
2000-12-12 03:34:56 +01:00
|
|
|
if (!(length= my_b_bytes_in_cache(info)) &&
|
|
|
|
!(length= my_b_fill(info)))
|
|
|
|
return 0;
|
2000-11-16 02:58:58 +01:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
char *pos,*end;
|
|
|
|
if (length > max_length)
|
|
|
|
length=max_length;
|
2001-11-28 01:55:52 +01:00
|
|
|
for (pos=info->read_pos,end=pos+length ; pos < end ;)
|
2000-11-16 02:58:58 +01:00
|
|
|
{
|
|
|
|
if ((*to++ = *pos++) == '\n')
|
|
|
|
{
|
2001-11-28 01:55:52 +01:00
|
|
|
info->read_pos=pos;
|
2000-11-16 02:58:58 +01:00
|
|
|
*to='\0';
|
2001-01-07 23:04:30 +01:00
|
|
|
return (uint) (to-start);
|
2000-11-16 02:58:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!(max_length-=length))
|
|
|
|
{
|
|
|
|
/* Found enough charcters; Return found string */
|
2001-11-28 01:55:52 +01:00
|
|
|
info->read_pos=pos;
|
2000-11-16 02:58:58 +01:00
|
|
|
*to='\0';
|
2001-01-07 23:04:30 +01:00
|
|
|
return (uint) (to-start);
|
2000-11-16 02:58:58 +01:00
|
|
|
}
|
|
|
|
if (!(length=my_b_fill(info)))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-28 15:11:05 +01:00
|
|
|
|
2002-08-08 02:12:02 +02:00
|
|
|
my_off_t my_b_filelength(IO_CACHE *info)
|
|
|
|
{
|
|
|
|
if (info->type == WRITE_CACHE)
|
|
|
|
{
|
|
|
|
return my_b_tell(info);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-08-21 21:04:22 +02:00
|
|
|
info->seek_not_done=1;
|
2002-08-08 02:12:02 +02:00
|
|
|
return my_seek(info->file,0L,MY_SEEK_END,MYF(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-16 02:58:58 +01:00
|
|
|
/*
|
|
|
|
Simple printf version. Supports '%s', '%d', '%u', "%ld" and "%lu"
|
|
|
|
Used for logging in MySQL
|
|
|
|
returns number of written character, or (uint) -1 on error
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint my_b_printf(IO_CACHE *info, const char* fmt, ...)
|
|
|
|
{
|
2000-11-17 01:36:46 +01:00
|
|
|
int result;
|
2000-11-16 02:58:58 +01:00
|
|
|
va_list args;
|
2000-11-17 01:36:46 +01:00
|
|
|
va_start(args,fmt);
|
|
|
|
result=my_b_vprintf(info, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint my_b_vprintf(IO_CACHE *info, const char* fmt, va_list args)
|
|
|
|
{
|
2000-11-16 02:58:58 +01:00
|
|
|
uint out_length=0;
|
SECURITY FIX
Bug#17667: An attacker has the opportunity to bypass query logging.
This adds a new, local-only printf format specifier to our *printf functions
that allows us to print known-size buffers that must not be interpreted as
NUL-terminated "strings."
It uses this format-specifier to print to the log, thus fixing this
problem.
include/my_sys.h:
Add prototype for my_memmem() .
mysys/Makefile.am:
Add reference to new file, my_memmem.c
mysys/mf_iocache2.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
Also, simplify the code a bit.
TODO: This code should be unified with the strings/my_vnsprintf.c code in
the future.
sql/sql_parse.cc:
The query is not a C-string, but is a sized buffer, containing any character
at all, which may include NUL characters.
strings/my_vsnprintf.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
tests/Makefile.am:
We may need some of our local functions.
tests/mysql_client_test.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
mysql-test/t/mysql_client_test.opt:
New BitKeeper file ``mysql-test/t/mysql_client_test.opt''
Add '--log' server parameter.
mysys/my_memmem.c:
New BitKeeper file ``mysys/my_memmem.c''
Implement memmem, a black-box work-alike of the GNU memmem(), which functions
like strstr() but for arbitrary blocks of memory.
2006-05-02 04:10:50 +02:00
|
|
|
uint minimum_width; /* as yet unimplemented */
|
|
|
|
uint minimum_width_sign;
|
|
|
|
uint precision; /* as yet unimplemented for anything but %b */
|
2000-11-16 02:58:58 +01:00
|
|
|
|
SECURITY FIX
Bug#17667: An attacker has the opportunity to bypass query logging.
This adds a new, local-only printf format specifier to our *printf functions
that allows us to print known-size buffers that must not be interpreted as
NUL-terminated "strings."
It uses this format-specifier to print to the log, thus fixing this
problem.
include/my_sys.h:
Add prototype for my_memmem() .
mysys/Makefile.am:
Add reference to new file, my_memmem.c
mysys/mf_iocache2.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
Also, simplify the code a bit.
TODO: This code should be unified with the strings/my_vnsprintf.c code in
the future.
sql/sql_parse.cc:
The query is not a C-string, but is a sized buffer, containing any character
at all, which may include NUL characters.
strings/my_vsnprintf.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
tests/Makefile.am:
We may need some of our local functions.
tests/mysql_client_test.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
mysql-test/t/mysql_client_test.opt:
New BitKeeper file ``mysql-test/t/mysql_client_test.opt''
Add '--log' server parameter.
mysys/my_memmem.c:
New BitKeeper file ``mysys/my_memmem.c''
Implement memmem, a black-box work-alike of the GNU memmem(), which functions
like strstr() but for arbitrary blocks of memory.
2006-05-02 04:10:50 +02:00
|
|
|
/*
|
|
|
|
Store the location of the beginning of a format directive, for the
|
|
|
|
case where we learn we shouldn't have been parsing a format string
|
|
|
|
at all, and we don't want to lose the flag/precision/width/size
|
|
|
|
information.
|
|
|
|
*/
|
|
|
|
const char* backtrack;
|
|
|
|
|
|
|
|
for (; *fmt != '\0'; fmt++)
|
2000-11-16 02:58:58 +01:00
|
|
|
{
|
SECURITY FIX
Bug#17667: An attacker has the opportunity to bypass query logging.
This adds a new, local-only printf format specifier to our *printf functions
that allows us to print known-size buffers that must not be interpreted as
NUL-terminated "strings."
It uses this format-specifier to print to the log, thus fixing this
problem.
include/my_sys.h:
Add prototype for my_memmem() .
mysys/Makefile.am:
Add reference to new file, my_memmem.c
mysys/mf_iocache2.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
Also, simplify the code a bit.
TODO: This code should be unified with the strings/my_vnsprintf.c code in
the future.
sql/sql_parse.cc:
The query is not a C-string, but is a sized buffer, containing any character
at all, which may include NUL characters.
strings/my_vsnprintf.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
tests/Makefile.am:
We may need some of our local functions.
tests/mysql_client_test.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
mysql-test/t/mysql_client_test.opt:
New BitKeeper file ``mysql-test/t/mysql_client_test.opt''
Add '--log' server parameter.
mysys/my_memmem.c:
New BitKeeper file ``mysys/my_memmem.c''
Implement memmem, a black-box work-alike of the GNU memmem(), which functions
like strstr() but for arbitrary blocks of memory.
2006-05-02 04:10:50 +02:00
|
|
|
/* Copy everything until '%' or end of string */
|
|
|
|
const char *start=fmt;
|
|
|
|
uint length;
|
|
|
|
|
|
|
|
for (; (*fmt != '\0') && (*fmt != '%'); fmt++) ;
|
|
|
|
|
|
|
|
length= (uint) (fmt - start);
|
|
|
|
out_length+=length;
|
|
|
|
if (my_b_write(info, start, length))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (*fmt == '\0') /* End of format */
|
2000-11-16 02:58:58 +01:00
|
|
|
{
|
SECURITY FIX
Bug#17667: An attacker has the opportunity to bypass query logging.
This adds a new, local-only printf format specifier to our *printf functions
that allows us to print known-size buffers that must not be interpreted as
NUL-terminated "strings."
It uses this format-specifier to print to the log, thus fixing this
problem.
include/my_sys.h:
Add prototype for my_memmem() .
mysys/Makefile.am:
Add reference to new file, my_memmem.c
mysys/mf_iocache2.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
Also, simplify the code a bit.
TODO: This code should be unified with the strings/my_vnsprintf.c code in
the future.
sql/sql_parse.cc:
The query is not a C-string, but is a sized buffer, containing any character
at all, which may include NUL characters.
strings/my_vsnprintf.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
tests/Makefile.am:
We may need some of our local functions.
tests/mysql_client_test.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
mysql-test/t/mysql_client_test.opt:
New BitKeeper file ``mysql-test/t/mysql_client_test.opt''
Add '--log' server parameter.
mysys/my_memmem.c:
New BitKeeper file ``mysys/my_memmem.c''
Implement memmem, a black-box work-alike of the GNU memmem(), which functions
like strstr() but for arbitrary blocks of memory.
2006-05-02 04:10:50 +02:00
|
|
|
return out_length;
|
2000-11-16 02:58:58 +01:00
|
|
|
}
|
SECURITY FIX
Bug#17667: An attacker has the opportunity to bypass query logging.
This adds a new, local-only printf format specifier to our *printf functions
that allows us to print known-size buffers that must not be interpreted as
NUL-terminated "strings."
It uses this format-specifier to print to the log, thus fixing this
problem.
include/my_sys.h:
Add prototype for my_memmem() .
mysys/Makefile.am:
Add reference to new file, my_memmem.c
mysys/mf_iocache2.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
Also, simplify the code a bit.
TODO: This code should be unified with the strings/my_vnsprintf.c code in
the future.
sql/sql_parse.cc:
The query is not a C-string, but is a sized buffer, containing any character
at all, which may include NUL characters.
strings/my_vsnprintf.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
tests/Makefile.am:
We may need some of our local functions.
tests/mysql_client_test.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
mysql-test/t/mysql_client_test.opt:
New BitKeeper file ``mysql-test/t/mysql_client_test.opt''
Add '--log' server parameter.
mysys/my_memmem.c:
New BitKeeper file ``mysys/my_memmem.c''
Implement memmem, a black-box work-alike of the GNU memmem(), which functions
like strstr() but for arbitrary blocks of memory.
2006-05-02 04:10:50 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
By this point, *fmt must be a percent; Keep track of this location and
|
|
|
|
skip over the percent character.
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT(*fmt == '%');
|
|
|
|
backtrack= fmt;
|
|
|
|
fmt++;
|
|
|
|
|
|
|
|
minimum_width= 0;
|
|
|
|
precision= 0;
|
|
|
|
minimum_width_sign= 1;
|
2004-06-03 18:52:54 +02:00
|
|
|
/* Skip if max size is used (to be compatible with printf) */
|
SECURITY FIX
Bug#17667: An attacker has the opportunity to bypass query logging.
This adds a new, local-only printf format specifier to our *printf functions
that allows us to print known-size buffers that must not be interpreted as
NUL-terminated "strings."
It uses this format-specifier to print to the log, thus fixing this
problem.
include/my_sys.h:
Add prototype for my_memmem() .
mysys/Makefile.am:
Add reference to new file, my_memmem.c
mysys/mf_iocache2.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
Also, simplify the code a bit.
TODO: This code should be unified with the strings/my_vnsprintf.c code in
the future.
sql/sql_parse.cc:
The query is not a C-string, but is a sized buffer, containing any character
at all, which may include NUL characters.
strings/my_vsnprintf.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
tests/Makefile.am:
We may need some of our local functions.
tests/mysql_client_test.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
mysql-test/t/mysql_client_test.opt:
New BitKeeper file ``mysql-test/t/mysql_client_test.opt''
Add '--log' server parameter.
mysys/my_memmem.c:
New BitKeeper file ``mysys/my_memmem.c''
Implement memmem, a black-box work-alike of the GNU memmem(), which functions
like strstr() but for arbitrary blocks of memory.
2006-05-02 04:10:50 +02:00
|
|
|
while (*fmt == '-') { fmt++; minimum_width_sign= -1; }
|
|
|
|
if (*fmt == '*') {
|
|
|
|
precision= (int) va_arg(args, int);
|
|
|
|
fmt++;
|
|
|
|
} else {
|
|
|
|
while (my_isdigit(&my_charset_latin1, *fmt)) {
|
|
|
|
minimum_width=(minimum_width * 10) + (*fmt - '0');
|
|
|
|
fmt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
minimum_width*= minimum_width_sign;
|
|
|
|
|
|
|
|
if (*fmt == '.') {
|
2000-11-16 02:58:58 +01:00
|
|
|
fmt++;
|
SECURITY FIX
Bug#17667: An attacker has the opportunity to bypass query logging.
This adds a new, local-only printf format specifier to our *printf functions
that allows us to print known-size buffers that must not be interpreted as
NUL-terminated "strings."
It uses this format-specifier to print to the log, thus fixing this
problem.
include/my_sys.h:
Add prototype for my_memmem() .
mysys/Makefile.am:
Add reference to new file, my_memmem.c
mysys/mf_iocache2.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
Also, simplify the code a bit.
TODO: This code should be unified with the strings/my_vnsprintf.c code in
the future.
sql/sql_parse.cc:
The query is not a C-string, but is a sized buffer, containing any character
at all, which may include NUL characters.
strings/my_vsnprintf.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
tests/Makefile.am:
We may need some of our local functions.
tests/mysql_client_test.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
mysql-test/t/mysql_client_test.opt:
New BitKeeper file ``mysql-test/t/mysql_client_test.opt''
Add '--log' server parameter.
mysys/my_memmem.c:
New BitKeeper file ``mysys/my_memmem.c''
Implement memmem, a black-box work-alike of the GNU memmem(), which functions
like strstr() but for arbitrary blocks of memory.
2006-05-02 04:10:50 +02:00
|
|
|
if (*fmt == '*') {
|
|
|
|
precision= (int) va_arg(args, int);
|
|
|
|
fmt++;
|
|
|
|
} else {
|
|
|
|
while (my_isdigit(&my_charset_latin1, *fmt)) {
|
|
|
|
precision=(precision * 10) + (*fmt - '0');
|
|
|
|
fmt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-16 02:58:58 +01:00
|
|
|
if (*fmt == 's') /* String parameter */
|
|
|
|
{
|
|
|
|
reg2 char *par = va_arg(args, char *);
|
|
|
|
uint length = (uint) strlen(par);
|
SECURITY FIX
Bug#17667: An attacker has the opportunity to bypass query logging.
This adds a new, local-only printf format specifier to our *printf functions
that allows us to print known-size buffers that must not be interpreted as
NUL-terminated "strings."
It uses this format-specifier to print to the log, thus fixing this
problem.
include/my_sys.h:
Add prototype for my_memmem() .
mysys/Makefile.am:
Add reference to new file, my_memmem.c
mysys/mf_iocache2.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
Also, simplify the code a bit.
TODO: This code should be unified with the strings/my_vnsprintf.c code in
the future.
sql/sql_parse.cc:
The query is not a C-string, but is a sized buffer, containing any character
at all, which may include NUL characters.
strings/my_vsnprintf.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
tests/Makefile.am:
We may need some of our local functions.
tests/mysql_client_test.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
mysql-test/t/mysql_client_test.opt:
New BitKeeper file ``mysql-test/t/mysql_client_test.opt''
Add '--log' server parameter.
mysys/my_memmem.c:
New BitKeeper file ``mysys/my_memmem.c''
Implement memmem, a black-box work-alike of the GNU memmem(), which functions
like strstr() but for arbitrary blocks of memory.
2006-05-02 04:10:50 +02:00
|
|
|
/* TODO: implement minimum width and precision */
|
2000-11-16 02:58:58 +01:00
|
|
|
out_length+=length;
|
|
|
|
if (my_b_write(info, par, length))
|
|
|
|
goto err;
|
|
|
|
}
|
SECURITY FIX
Bug#17667: An attacker has the opportunity to bypass query logging.
This adds a new, local-only printf format specifier to our *printf functions
that allows us to print known-size buffers that must not be interpreted as
NUL-terminated "strings."
It uses this format-specifier to print to the log, thus fixing this
problem.
include/my_sys.h:
Add prototype for my_memmem() .
mysys/Makefile.am:
Add reference to new file, my_memmem.c
mysys/mf_iocache2.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
Also, simplify the code a bit.
TODO: This code should be unified with the strings/my_vnsprintf.c code in
the future.
sql/sql_parse.cc:
The query is not a C-string, but is a sized buffer, containing any character
at all, which may include NUL characters.
strings/my_vsnprintf.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
tests/Makefile.am:
We may need some of our local functions.
tests/mysql_client_test.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
mysql-test/t/mysql_client_test.opt:
New BitKeeper file ``mysql-test/t/mysql_client_test.opt''
Add '--log' server parameter.
mysys/my_memmem.c:
New BitKeeper file ``mysys/my_memmem.c''
Implement memmem, a black-box work-alike of the GNU memmem(), which functions
like strstr() but for arbitrary blocks of memory.
2006-05-02 04:10:50 +02:00
|
|
|
else if (*fmt == 'b') /* Sized buffer parameter, only precision makes sense */
|
|
|
|
{
|
|
|
|
char *par = va_arg(args, char *);
|
|
|
|
out_length+= precision;
|
|
|
|
if (my_b_write(info, par, precision))
|
|
|
|
goto err;
|
|
|
|
}
|
2000-11-16 02:58:58 +01:00
|
|
|
else if (*fmt == 'd' || *fmt == 'u') /* Integer parameter */
|
|
|
|
{
|
|
|
|
register int iarg;
|
|
|
|
uint length;
|
|
|
|
char buff[17];
|
|
|
|
|
|
|
|
iarg = va_arg(args, int);
|
|
|
|
if (*fmt == 'd')
|
|
|
|
length= (uint) (int10_to_str((long) iarg,buff, -10) - buff);
|
|
|
|
else
|
|
|
|
length= (uint) (int10_to_str((long) (uint) iarg,buff,10)- buff);
|
|
|
|
out_length+=length;
|
|
|
|
if (my_b_write(info, buff, length))
|
|
|
|
goto err;
|
|
|
|
}
|
2000-11-25 03:49:13 +01:00
|
|
|
else if ((*fmt == 'l' && fmt[1] == 'd') || fmt[1] == 'u')
|
|
|
|
/* long parameter */
|
2000-11-16 02:58:58 +01:00
|
|
|
{
|
|
|
|
register long iarg;
|
|
|
|
uint length;
|
|
|
|
char buff[17];
|
|
|
|
|
|
|
|
iarg = va_arg(args, long);
|
|
|
|
if (*++fmt == 'd')
|
|
|
|
length= (uint) (int10_to_str(iarg,buff, -10) - buff);
|
|
|
|
else
|
|
|
|
length= (uint) (int10_to_str(iarg,buff,10)- buff);
|
|
|
|
out_length+=length;
|
|
|
|
if (my_b_write(info, buff, length))
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* %% or unknown code */
|
SECURITY FIX
Bug#17667: An attacker has the opportunity to bypass query logging.
This adds a new, local-only printf format specifier to our *printf functions
that allows us to print known-size buffers that must not be interpreted as
NUL-terminated "strings."
It uses this format-specifier to print to the log, thus fixing this
problem.
include/my_sys.h:
Add prototype for my_memmem() .
mysys/Makefile.am:
Add reference to new file, my_memmem.c
mysys/mf_iocache2.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
Also, simplify the code a bit.
TODO: This code should be unified with the strings/my_vnsprintf.c code in
the future.
sql/sql_parse.cc:
The query is not a C-string, but is a sized buffer, containing any character
at all, which may include NUL characters.
strings/my_vsnprintf.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
tests/Makefile.am:
We may need some of our local functions.
tests/mysql_client_test.c:
Add a "%.1234b" and "%.*b" percent-code. It takes a width, just like "%s",
but unlike the string-indicator, it requires the width and doesn't stop printing
at NUL characters.
mysql-test/t/mysql_client_test.opt:
New BitKeeper file ``mysql-test/t/mysql_client_test.opt''
Add '--log' server parameter.
mysys/my_memmem.c:
New BitKeeper file ``mysys/my_memmem.c''
Implement memmem, a black-box work-alike of the GNU memmem(), which functions
like strstr() but for arbitrary blocks of memory.
2006-05-02 04:10:50 +02:00
|
|
|
if (my_b_write(info, backtrack, fmt-backtrack))
|
|
|
|
goto err;
|
|
|
|
out_length+= fmt-backtrack;
|
2000-11-16 02:58:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return out_length;
|
|
|
|
|
|
|
|
err:
|
|
|
|
return (uint) -1;
|
|
|
|
}
|