Skip to content

Commit d36155c

Browse files
committed
DB-883 tokudb broken after 'create database log002015'
[summary] In is_a_logfile_any_version, the uninitialized variable is terrible when we complied with -O3 flag, if we have a directory named 'log02015', 'n' is undefined value after sscanf Copyright (c) 2015, BohuTANG All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 parent 8f45478 commit d36155c

2 files changed

Lines changed: 88 additions & 3 deletions

File tree

ft/logger/logger.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ static void toku_print_bytes (FILE *outf, uint32_t len, char *data) {
7575

7676
static bool is_a_logfile_any_version (const char *name, uint64_t *number_result, uint32_t *version_of_log) {
7777
bool rval = true;
78-
uint64_t result;
79-
int n;
78+
uint64_t result = 0UL;
79+
int n = 0;
8080
int r;
81-
uint32_t version;
81+
uint32_t version = 0;
8282
r = sscanf(name, "log%" SCNu64 ".tokulog%" SCNu32 "%n", &result, &version, &n);
8383
if (r!=2 || name[n]!='\0' || version <= TOKU_LOG_VERSION_1) {
8484
//Version 1 does NOT append 'version' to end of '.tokulog'
@@ -644,6 +644,11 @@ int toku_logger_find_logfiles (const char *directory, char ***resultp, int *n_lo
644644
while ((de=readdir(d))) {
645645
uint64_t thisl;
646646
uint32_t version_ignore;
647+
648+
// if de is directory, skip it
649+
if (de->d_type == DT_DIR)
650+
continue;
651+
647652
if ( !(is_a_logfile_any_version(de->d_name, &thisl, &version_ignore)) ) continue; //#2424: Skip over files that don't match the exact logfile template
648653
if (n_results+1>=result_limit) {
649654
result_limit*=2;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2+
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
3+
#ident "$Id$"
4+
/*======
5+
This file is part of PerconaFT.
6+
7+
8+
Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
9+
10+
PerconaFT is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU General Public License, version 2,
12+
as published by the Free Software Foundation.
13+
14+
PerconaFT is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
21+
22+
----------------------------------------
23+
24+
PerconaFT is free software: you can redistribute it and/or modify
25+
it under the terms of the GNU Affero General Public License, version 3,
26+
as published by the Free Software Foundation.
27+
28+
PerconaFT is distributed in the hope that it will be useful,
29+
but WITHOUT ANY WARRANTY; without even the implied warranty of
30+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31+
GNU Affero General Public License for more details.
32+
33+
You should have received a copy of the GNU Affero General Public License
34+
along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
35+
======= */
36+
37+
#ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
38+
39+
// Test that find redo-log files works correctly.
40+
41+
#include "test.h"
42+
#include <libgen.h>
43+
44+
static int
45+
run_test(void) {
46+
int r;
47+
48+
// setup the test dir
49+
toku_os_recursive_delete(TOKU_TEST_FILENAME);
50+
r = toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU);
51+
assert(r == 0);
52+
53+
char testdir[TOKU_PATH_MAX+1];
54+
toku_path_join(testdir, 2, TOKU_TEST_FILENAME, "log002015");
55+
r = toku_os_mkdir(testdir, S_IRWXU);
56+
assert(r == 0);
57+
58+
char **logfiles = nullptr;
59+
int n_logfiles = 0;
60+
r = toku_logger_find_logfiles(TOKU_TEST_FILENAME, &logfiles, &n_logfiles);
61+
CKERR(r);
62+
assert(n_logfiles == 0);
63+
fprintf(stderr, "redo log nums: %d \n", n_logfiles);
64+
for (int i; i < n_logfiles; i++) {
65+
fprintf(stderr, "redo log %s \n", logfiles[i]);
66+
}
67+
68+
toku_logger_free_logfiles(logfiles, n_logfiles);
69+
70+
toku_os_recursive_delete(TOKU_TEST_FILENAME);
71+
72+
return 0;
73+
}
74+
75+
int
76+
test_main(int UU(argc), const char *UU(argv[])) {
77+
int r;
78+
r = run_test();
79+
return r;
80+
}

0 commit comments

Comments
 (0)