1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

Check and remove high stack usage

I checked all stack overflow potential problems found with
gcc -Wstack-usage=16384
and
clang -Wframe-larger-than=16384 -no-inline

Fixes:
Added '#pragma clang diagnostic ignored "-Wframe-larger-than="'
  to a lot of function to where stack usage large but resonable.
- Added stack check warnings to BUILD scrips when using clang and debug.

Function changed to use malloc instead allocating things on stack:
- read_bootstrap_query() now allocates line_buffer (20000 bytes) with
  malloc() instead of using stack. This has a small performance impact
  but this is not releant for bootstrap.
- mroonga grn_select() used 65856 bytes on stack. Changed it to use
  malloc().
- Wsrep_schema::replay_transaction() and
  Wsrep_schema::recover_sr_transactions().
- Connect zipOpen3()

Not fixed:
- mroonga/vendor/groonga/lib/expr.c grn_proc_call() uses
  43712 byte on stack.  However this is not easy to fix as the stack
  used is caused by a lot of code generated by defines.
- Most changes in mroonga/groonga where only adding of pragmas to disable
  stack warnings.
- rocksdb/options/options_helper.cc uses 20288 of stack space.
  (no reason to fix except to get rid of the compiler warning)
- Causes using alloca() where the allocation size is resonable.
- An issue in libmariadb (reported to connectors).
This commit is contained in:
Monty
2024-04-19 13:10:58 +03:00
parent 07faba08b9
commit 0ccdf54b64
32 changed files with 296 additions and 109 deletions

View File

@@ -33,26 +33,35 @@ extern "C" int read_bootstrap_query(char *query, int *query_length,
fgets_input_t input, fgets_fn_t fgets_fn,
int preserve_delimiter, int *error)
{
char line_buffer[MAX_BOOTSTRAP_LINE_SIZE];
char *line_buffer;
const char *line;
size_t len;
size_t query_len= 0;
int fgets_error= 0;
int exit_code= 0;
*error= 0;
line_buffer= (char*) malloc(MAX_BOOTSTRAP_LINE_SIZE);
*query_length= 0;
for ( ; ; )
{
line= (*fgets_fn)(line_buffer, sizeof(line_buffer), input, &fgets_error);
line= (*fgets_fn)(line_buffer, MAX_BOOTSTRAP_LINE_SIZE, input, &fgets_error);
if (error)
*error= fgets_error;
if (fgets_error != 0)
return READ_BOOTSTRAP_ERROR;
{
exit_code= READ_BOOTSTRAP_ERROR;
break;
}
if (line == NULL)
return (query_len == 0) ? READ_BOOTSTRAP_EOF : READ_BOOTSTRAP_ERROR;
{
exit_code= (query_len == 0) ? READ_BOOTSTRAP_EOF : READ_BOOTSTRAP_ERROR;
break;
}
len= strlen(line);
@@ -98,7 +107,8 @@ extern "C" int read_bootstrap_query(char *query, int *query_length,
if (!p || !p[1])
{
/* Invalid DELIMITER specifier */
return READ_BOOTSTRAP_ERROR;
exit_code= READ_BOOTSTRAP_ERROR;
break;
}
delimiter.assign(p+1);
if (preserve_delimiter)
@@ -106,7 +116,8 @@ extern "C" int read_bootstrap_query(char *query, int *query_length,
memcpy(query,line,len);
query[len]=0;
*query_length = (int)len;
return READ_BOOTSTRAP_SUCCESS;
exit_code= READ_BOOTSTRAP_SUCCESS;
break;
}
continue;
}
@@ -125,7 +136,8 @@ extern "C" int read_bootstrap_query(char *query, int *query_length,
}
query[query_len]= '\0';
*query_length= (int)query_len;
return READ_BOOTSTRAP_QUERY_SIZE;
exit_code= READ_BOOTSTRAP_QUERY_SIZE;
break;
}
if (query_len != 0)
@@ -152,8 +164,11 @@ extern "C" int read_bootstrap_query(char *query, int *query_length,
}
query[query_len]= 0;
*query_length= (int)query_len;
return READ_BOOTSTRAP_SUCCESS;
exit_code= READ_BOOTSTRAP_SUCCESS;
break;
}
}
free(line_buffer);
return exit_code;
}