summaryrefslogtreecommitdiff
path: root/innobase/include
diff options
context:
space:
mode:
authorunknown <marko@hundin.mysql.fi>2004-04-01 16:51:34 +0300
committerunknown <marko@hundin.mysql.fi>2004-04-01 16:51:34 +0300
commit025ddfea288890236d4da04b46b3fff926707de3 (patch)
treefab5076a83cb8b112b16f76355f3a96a708c48ba /innobase/include
parent95367941561263fac5ee399dd8eb4a408690bc0d (diff)
downloadmariadb-git-025ddfea288890236d4da04b46b3fff926707de3.tar.gz
InnoDB cleanup: fixing buffer overflows and quoting of quotes
innobase/dict/dict0crea.c: Remove unneeded prototypes for static functions Remove unused parameters from some functions Replace some assertions with compile-time checks dict_create_add_foreigns_to_dictionary(): allocate space dynamically for the SQL, and quote quotes innobase/dict/dict0dict.c: Remove unnecessary prototypes for static functions dict_tables_have_same_db(): Remove length limitation dict_remove_db_name(): Use strchr() dict_get_db_name_len(): Use strchr() Replace mem_heap_alloc()+strlen()+memcpy() with mem_heap_strdup() Remove unnecessary strlen() calls Allocate space dynamically for generated strings dict_scan_id(): allow quotes within quoted strings innobase/dict/dict0load.c: Remove unnecessary strlen() calls Replace mem_heap_alloc()+strlen()+memcpy() with mem_heap_strdup() innobase/dict/dict0mem.c: Replace mem_heap_alloc()+strlen()+memcpy() with mem_heap_strdup() innobase/eval/eval0eval.c: Make TO_CHAR() work with any machine word width innobase/fil/fil0fil.c: Replace mem_alloc()+strlen()+strcpy() with mem_strdup() innobase/ibuf/ibuf0ibuf.c: Make some global variables static Add #ifdef UNIV_IBUF_DEBUG around debug statements innobase/include/data0data.h: Add #ifdef UNIV_DEBUG around dtuple_validate() innobase/include/data0data.ic: Replace = with == in ut_ad(tuple->magic_n == DATA_TUPLE_MAGIC_N) innobase/include/dict0dict.h: Add const qualifiers innobase/include/lock0lock.h: Add UL suffixes to unsigned long masks innobase/include/log0log.h: Remove unused parameter "type" of log_group_write_buf() innobase/include/mem0mem.h: Add mem_strdup(), mem_strdupl(), mem_strdupq(), mem_heap_strdup(), and mem_heap_strdupl() innobase/include/mem0mem.ic: Add mem_strdup(), mem_strdupl(), mem_strdupq(), mem_heap_strdup(), and mem_heap_strdupl() innobase/include/row0uins.h: Remove unused parameter "thr" of row_undo_ins() innobase/include/row0undo.h: Remvoe unused parameter "thr" of row_undo_search_clust_to_pcur() innobase/include/ut0byte.h: Add const qualifier to ut_cpy_in_lower_case() Remove parameter "len" of ut_cmp_in_lower_case() innobase/include/ut0mem.h: Add ut_strlenq(), ut_strcpyq() and ut_memcpyq() innobase/include/ut0mem.ic: Add ut_strlenq() innobase/include/ut0ut.h: Declare ut_sprintf() as a printf-style function innobase/lock/lock0lock.c: lock_clust_rec_modify_check_and_lock(): Remove unused variable "trx" innobase/log/log0log.c: Remove unused parameters innobase/log/log0recv.c: Remove parameter "type" from log_group_write_buf() innobase/mem/mem0mem.c: Simplify the initialization of block->init_block innobase/mtr/mtr0log.c: Add a debug assertion to mlog_parse_initial_log_record() innobase/page/page0cur.c: Add debug assertion to page_cur_insert_rec_write_log() Remove hard-coded buffer size in page_cur_parse_insert_rec() innobase/page/page0page.c: Remove unneeded variable rec innobase/pars/pars0opt.c: Correct a potential buffer overflow innobase/pars/pars0pars.c: Replace mem_heap_alloc()+strlen()+memcpy() with mem_heap_strdup() innobase/row/row0ins.c: Replace parameter "thr" with "trx" in row_ins_foreign_report_add_err() Remove unnecessary strlen() call Use strchr() innobase/row/row0mysql.c: Add row_mysql_is_recovered_tmp_table() Add row_mysql_is_system_table() Compare reserved table names with exact match Use strstr() and strchr() and mem_strdupl() Compute space needed for generated SQL, and allocate it dynamically innobase/row/row0purge.c: Remove unused parameters "thr" innobase/row/row0row.c: Simplify row_get_clust_rec() innobase/row/row0uins.c: Remove unused parameters "thr" innobase/row/row0umod.c: Remove unused variable "index" row_undo_mod_del_unmark_sec_and_undo_update(): Remove parameter "node" and variable "rec" Remove unused parameters "thr" innobase/row/row0undo.c: Remove unused parameters "thr" innobase/srv/srv0srv.c: Replace UT_NOT_USED() with __attribute__((unused)) innobase/srv/srv0start.c: Remove unnecessary strlen() calls Remove unused parameter "create_new_db" of open_or_create_log_file() innobase/trx/trx0roll.c: Replace mem_alloc()+strlen()+memcpy() with mem_strdup() innobase/trx/trx0sys.c: Remove unnecessary strlen() call innobase/ut/ut0byte.c: Add const qualifier to ut_cpy_in_lower_case() Remove parameter "len" of ut_cmp_in_lower_case() innobase/ut/ut0mem.c: Add ut_strlenq() and ut_memcpyq() sql/ha_innodb.cc: Remove parameter "len" of ut_cmp_in_lower_case()
Diffstat (limited to 'innobase/include')
-rw-r--r--innobase/include/data0data.h2
-rw-r--r--innobase/include/data0data.ic4
-rw-r--r--innobase/include/dict0dict.h23
-rw-r--r--innobase/include/lock0lock.h4
-rw-r--r--innobase/include/log0log.h3
-rw-r--r--innobase/include/mem0mem.h53
-rw-r--r--innobase/include/mem0mem.ic96
-rw-r--r--innobase/include/row0uins.h3
-rw-r--r--innobase/include/row0undo.h3
-rw-r--r--innobase/include/ut0byte.h16
-rw-r--r--innobase/include/ut0mem.h33
-rw-r--r--innobase/include/ut0mem.ic20
-rw-r--r--innobase/include/ut0ut.h4
13 files changed, 233 insertions, 31 deletions
diff --git a/innobase/include/data0data.h b/innobase/include/data0data.h
index c4e93bec738..b100ef5b583 100644
--- a/innobase/include/data0data.h
+++ b/innobase/include/data0data.h
@@ -294,6 +294,7 @@ dtuple_check_typed_no_assert(
/*=========================*/
/* out: TRUE if ok */
dtuple_t* tuple); /* in: tuple */
+#ifdef UNIV_DEBUG
/**************************************************************
Validates the consistency of a tuple which must be complete, i.e,
all fields must have been set. */
@@ -303,6 +304,7 @@ dtuple_validate(
/*============*/
/* out: TRUE if ok */
dtuple_t* tuple); /* in: tuple */
+#endif /* UNIV_DEBUG */
/*****************************************************************
Pretty prints a dfield value according to its data type. */
diff --git a/innobase/include/data0data.ic b/innobase/include/data0data.ic
index def80d3f430..697a272ccd6 100644
--- a/innobase/include/data0data.ic
+++ b/innobase/include/data0data.ic
@@ -299,7 +299,7 @@ dtuple_get_data_size(
ut_ad(tuple);
ut_ad(dtuple_check_typed(tuple));
- ut_ad(tuple->magic_n = DATA_TUPLE_MAGIC_N);
+ ut_ad(tuple->magic_n == DATA_TUPLE_MAGIC_N);
n_fields = tuple->n_fields;
@@ -355,7 +355,7 @@ dtuple_fold(
ulint fold;
ut_ad(tuple);
- ut_ad(tuple->magic_n = DATA_TUPLE_MAGIC_N);
+ ut_ad(tuple->magic_n == DATA_TUPLE_MAGIC_N);
ut_ad(dtuple_check_typed(tuple));
fold = ut_fold_dulint(tree_id);
diff --git a/innobase/include/dict0dict.h b/innobase/include/dict0dict.h
index 2e51fecdb8d..f0523c5f204 100644
--- a/innobase/include/dict0dict.h
+++ b/innobase/include/dict0dict.h
@@ -32,20 +32,21 @@ Get the database name length in a table name. */
ulint
dict_get_db_name_len(
/*=================*/
- /* out: database name length */
- char* name); /* in: table name in the form dbname '/' tablename */
+ /* out: database name length */
+ const char* name); /* in: table name in the form
+ dbname '/' tablename */
/*************************************************************************
Accepts a specified string. Comparisons are case-insensitive. */
-char*
+const char*
dict_accept(
/*========*/
- /* out: if string was accepted, the pointer
- is moved after that, else ptr is returned */
- char* ptr, /* in: scan from this */
- const char* string,/* in: accept only this string as the next
- non-whitespace string */
- ibool* success);/* out: TRUE if accepted */
+ /* out: if string was accepted, the pointer
+ is moved after that, else ptr is returned */
+ const char* ptr, /* in: scan from this */
+ const char* string, /* in: accept only this string as the next
+ non-whitespace string */
+ ibool* success);/* out: TRUE if accepted */
/************************************************************************
Decrements the count of open MySQL handles to a table. */
@@ -216,7 +217,7 @@ dict_foreign_parse_drop_constraints(
dict_table_t* table, /* in: table */
ulint* n, /* out: number of constraints
to drop */
- char*** constraints_to_drop); /* out: id's of the
+ const char*** constraints_to_drop); /* out: id's of the
constraints to drop */
/**************************************************************************
Returns a table object and memoryfixes it. NOTE! This is a high-level
@@ -321,7 +322,7 @@ dict_table_print_by_name(
/*=====================*/
char* name);
/**************************************************************************
-Sprintfs to a string info on foreign keys of a table. */
+Outputs info on foreign keys of a table. */
void
dict_print_info_on_foreign_keys(
diff --git a/innobase/include/lock0lock.h b/innobase/include/lock0lock.h
index 0fd1696b882..103d28cd130 100644
--- a/innobase/include/lock0lock.h
+++ b/innobase/include/lock0lock.h
@@ -526,12 +526,12 @@ extern lock_sys_t* lock_sys;
#define LOCK_X 5 /* exclusive */
#define LOCK_AUTO_INC 6 /* locks the auto-inc counter of a table
in an exclusive mode */
-#define LOCK_MODE_MASK 0xF /* mask used to extract mode from the
+#define LOCK_MODE_MASK 0xFUL /* mask used to extract mode from the
type_mode field in a lock */
/* Lock types */
#define LOCK_TABLE 16 /* these type values should be so high that */
#define LOCK_REC 32 /* they can be ORed to the lock mode */
-#define LOCK_TYPE_MASK 0xF0 /* mask used to extract lock type from the
+#define LOCK_TYPE_MASK 0xF0UL /* mask used to extract lock type from the
type_mode field in a lock */
/* Waiting lock flag */
#define LOCK_WAIT 256 /* this wait bit should be so high that
diff --git a/innobase/include/log0log.h b/innobase/include/log0log.h
index 9fba0c46407..3295bc2d231 100644
--- a/innobase/include/log0log.h
+++ b/innobase/include/log0log.h
@@ -366,7 +366,6 @@ Writes a buffer to a log file group. */
void
log_group_write_buf(
/*================*/
- ulint type, /* in: LOG_FLUSH or LOG_RECOVER */
log_group_t* group, /* in: log group */
byte* buf, /* in: buffer */
ulint len, /* in: buffer len; must be divisible
@@ -551,7 +550,7 @@ extern log_t* log_sys;
highest bit is set to 1 if this is the
first log block in a log flush write
segment */
-#define LOG_BLOCK_FLUSH_BIT_MASK 0x80000000
+#define LOG_BLOCK_FLUSH_BIT_MASK 0x80000000UL
/* mask used to get the highest bit in
the preceding field */
#define LOG_BLOCK_HDR_DATA_LEN 4 /* number of bytes of log written to
diff --git a/innobase/include/mem0mem.h b/innobase/include/mem0mem.h
index 9ab3b2cd754..89e2a337c99 100644
--- a/innobase/include/mem0mem.h
+++ b/innobase/include/mem0mem.h
@@ -271,6 +271,59 @@ mem_realloc(
ulint n, /* in: desired number of bytes */
char* file_name,/* in: file name where called */
ulint line); /* in: line where called */
+
+/**************************************************************************
+Duplicates a NUL-terminated string. */
+UNIV_INLINE
+char*
+mem_strdup(
+/*=======*/
+ /* out, own: a copy of the string,
+ must be deallocated with mem_free */
+ const char* str); /* in: string to be copied */
+/**************************************************************************
+Makes a NUL-terminated copy of a nonterminated string. */
+UNIV_INLINE
+char*
+mem_strdupl(
+/*========*/
+ /* out, own: a copy of the string,
+ must be deallocated with mem_free */
+ const char* str, /* in: string to be copied */
+ ulint len); /* in: length of str, in bytes */
+
+/**************************************************************************
+Makes a NUL-terminated quoted copy of a NUL-terminated string. */
+UNIV_INLINE
+char*
+mem_strdupq(
+/*========*/
+ /* out, own: a quoted copy of the string,
+ must be deallocated with mem_free */
+ const char* str, /* in: string to be copied */
+ char q); /* in: quote character */
+
+/**************************************************************************
+Duplicates a NUL-terminated string, allocated from a memory heap. */
+UNIV_INLINE
+char*
+mem_heap_strdup(
+/*============*/
+ /* out, own: a copy of the string */
+ mem_heap_t* heap, /* in: memory heap where string is allocated */
+ const char* str); /* in: string to be copied */
+/**************************************************************************
+Makes a NUL-terminated copy of a nonterminated string,
+allocated from a memory heap. */
+UNIV_INLINE
+char*
+mem_heap_strdupl(
+/*=============*/
+ /* out, own: a copy of the string */
+ mem_heap_t* heap, /* in: memory heap where string is allocated */
+ const char* str, /* in: string to be copied */
+ ulint len); /* in: length of str, in bytes */
+
#ifdef MEM_PERIODIC_CHECK
/**********************************************************************
Goes through the list of all allocated mem blocks, checks their magic
diff --git a/innobase/include/mem0mem.ic b/innobase/include/mem0mem.ic
index fb4cef49ec9..c250e6948ec 100644
--- a/innobase/include/mem0mem.ic
+++ b/innobase/include/mem0mem.ic
@@ -579,3 +579,99 @@ mem_realloc(
return(mem_alloc_func(n, file_name, line));
}
+
+/**************************************************************************
+Duplicates a NUL-terminated string. */
+UNIV_INLINE
+char*
+mem_strdup(
+/*=======*/
+ /* out, own: a copy of the string,
+ must be deallocated with mem_free */
+ const char* str) /* in: string to be copied */
+{
+ ulint len = strlen(str) + 1;
+ return(memcpy(mem_alloc(len), str, len));
+}
+
+/**************************************************************************
+Makes a NUL-terminated copy of a nonterminated string. */
+UNIV_INLINE
+char*
+mem_strdupl(
+/*========*/
+ /* out, own: a copy of the string,
+ must be deallocated with mem_free */
+ const char* str, /* in: string to be copied */
+ ulint len) /* in: length of str, in bytes */
+{
+ char* s = mem_alloc(len + 1);
+ s[len] = 0;
+ return(memcpy(s, str, len));
+}
+
+/**************************************************************************
+Makes a NUL-terminated quoted copy of a NUL-terminated string. */
+UNIV_INLINE
+char*
+mem_strdupq(
+/*========*/
+ /* out, own: a quoted copy of the string,
+ must be deallocated with mem_free */
+ const char* str, /* in: string to be copied */
+ char q) /* in: quote character */
+{
+ char* dst;
+ char* d;
+ const char* s = str;
+ int len = strlen(str) + 3;
+ /* calculate the number of quote characters in the string */
+ while((s = strchr(s, q)) != NULL) {
+ s++;
+ len++;
+ }
+ /* allocate the quoted string, and copy it */
+ d = dst = mem_alloc(len);
+ *d++ = q;
+ s = str;
+ while(*s) {
+ if ((*d++ = *s++) == q) {
+ *d++ = q;
+ }
+ }
+ *d++ = q;
+ *d++ = '\0';
+ ut_ad(len == d - dst);
+ return(dst);
+}
+
+/**************************************************************************
+Duplicates a NUL-terminated string, allocated from a memory heap. */
+UNIV_INLINE
+char*
+mem_heap_strdup(
+/*============*/
+ /* out, own: a copy of the string */
+ mem_heap_t* heap, /* in: memory heap where string is allocated */
+ const char* str) /* in: string to be copied */
+{
+ ulint len = strlen(str) + 1;
+ return(memcpy(mem_heap_alloc(heap, len), str, len));
+}
+
+/**************************************************************************
+Makes a NUL-terminated copy of a nonterminated string,
+allocated from a memory heap. */
+UNIV_INLINE
+char*
+mem_heap_strdupl(
+/*=============*/
+ /* out, own: a copy of the string */
+ mem_heap_t* heap, /* in: memory heap where string is allocated */
+ const char* str, /* in: string to be copied */
+ ulint len) /* in: length of str, in bytes */
+{
+ char* s = mem_heap_alloc(heap, len + 1);
+ s[len] = 0;
+ return(memcpy(s, str, len));
+}
diff --git a/innobase/include/row0uins.h b/innobase/include/row0uins.h
index df5e072487e..fc57881f691 100644
--- a/innobase/include/row0uins.h
+++ b/innobase/include/row0uins.h
@@ -26,8 +26,7 @@ ulint
row_undo_ins(
/*=========*/
/* out: DB_SUCCESS */
- undo_node_t* node, /* in: row undo node */
- que_thr_t* thr); /* in: query thread */
+ undo_node_t* node); /* in: row undo node */
#ifndef UNIV_NONINL
diff --git a/innobase/include/row0undo.h b/innobase/include/row0undo.h
index 5402f1d9236..d64a00dcb8f 100644
--- a/innobase/include/row0undo.h
+++ b/innobase/include/row0undo.h
@@ -41,8 +41,7 @@ row_undo_search_clust_to_pcur(
/* out: TRUE if found; NOTE the node->pcur
must be closed by the caller, regardless of
the return value */
- undo_node_t* node, /* in: row undo node */
- que_thr_t* thr); /* in: query thread */
+ undo_node_t* node); /* in: row undo node */
/***************************************************************
Undoes a row operation in a table. This is a high-level function used
in SQL execution graphs. */
diff --git a/innobase/include/ut0byte.h b/innobase/include/ut0byte.h
index 4fb45221899..dd13b19b864 100644
--- a/innobase/include/ut0byte.h
+++ b/innobase/include/ut0byte.h
@@ -235,21 +235,19 @@ Copies a string to a memory location, setting characters to lower case. */
void
ut_cpy_in_lower_case(
/*=================*/
- char* dest, /* in: destination */
- char* source, /* in: source */
- ulint len); /* in: string length */
+ char* dest, /* in: destination */
+ const char* source, /* in: source */
+ ulint len); /* in: string length */
/****************************************************************
Compares two strings when converted to lower case. */
int
ut_cmp_in_lower_case(
/*=================*/
- /* out: -1, 0, 1 if str1 < str2, str1 == str2,
- str1 > str2, respectively */
- char* str1, /* in: string1 */
- char* str2, /* in: string2 */
- ulint len); /* in: length of both strings */
-
+ /* out: -1, 0, 1 if str1 < str2, str1 == str2,
+ str1 > str2, respectively */
+ const char* str1, /* in: string1 */
+ const char* str2); /* in: string2 */
#ifndef UNIV_NONINL
#include "ut0byte.ic"
diff --git a/innobase/include/ut0mem.h b/innobase/include/ut0mem.h
index 13ee8d5f5fa..bfda5ded40c 100644
--- a/innobase/include/ut0mem.h
+++ b/innobase/include/ut0mem.h
@@ -76,6 +76,39 @@ int
ut_strcmp(void* str1, void* str2);
/**************************************************************************
+Determine the length of a string when it is quoted with ut_strcpyq(). */
+UNIV_INLINE
+ulint
+ut_strlenq(
+/*=======*/
+ /* out: length of the string when quoted */
+ const char* str, /* in: null-terminated string */
+ char q); /* in: the quote character */
+
+/**************************************************************************
+Make a quoted copy of a string. */
+
+char*
+ut_strcpyq(
+/*=======*/
+ /* out: pointer to end of dest */
+ char* dest, /* in: output buffer */
+ char q, /* in: the quote character */
+ const char* src); /* in: null-terminated string */
+
+/**************************************************************************
+Make a quoted copy of a fixed-length string. */
+
+char*
+ut_memcpyq(
+/*=======*/
+ /* out: pointer to end of dest */
+ char* dest, /* in: output buffer */
+ char q, /* in: the quote character */
+ const char* src, /* in: string to be quoted */
+ ulint len); /* in: length of src */
+
+/**************************************************************************
Catenates two strings into newly allocated memory. The memory must be freed
using mem_free. */
diff --git a/innobase/include/ut0mem.ic b/innobase/include/ut0mem.ic
index 1049aee8ecc..951d9538424 100644
--- a/innobase/include/ut0mem.ic
+++ b/innobase/include/ut0mem.ic
@@ -48,3 +48,23 @@ ut_strcmp(void* str1, void* str2)
return(strcmp((char*)str1, (char*)str2));
}
+/**************************************************************************
+Determine the length of a string when it is quoted with ut_strcpyq(). */
+UNIV_INLINE
+ulint
+ut_strlenq(
+/*=======*/
+ /* out: length of the string when quoted */
+ const char* str, /* in: null-terminated string */
+ char q) /* in: the quote character */
+{
+ ulint len;
+
+ for (len = 0; *str; len++, str++) {
+ if (*str == q) {
+ len++;
+ }
+ }
+
+ return(len);
+}
diff --git a/innobase/include/ut0ut.h b/innobase/include/ut0ut.h
index 8ec23b23dcd..637c9a68174 100644
--- a/innobase/include/ut0ut.h
+++ b/innobase/include/ut0ut.h
@@ -28,7 +28,9 @@ ut_sprintf(
/*=======*/
char* buf, /* in/out: buffer where to print */
const char* format, /* in: format of prints */
- ...); /* in: arguments to be printed */
+ ...) /* in: arguments to be printed */
+ __attribute__((__format__ (__printf__, 2, 3)));
+
/************************************************************
Gets the high 32 bits in a ulint. That is makes a shift >> 32,
but since there seem to be compiler bugs in both gcc and Visual C++,