mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-18 12:22:12 +00:00
fix
This commit is contained in:
parent
fe55995e04
commit
0b3f7d18ef
@ -9,9 +9,9 @@
|
||||
static void readAndAssert(DB::ReadBuffer & buf, const char * str)
|
||||
{
|
||||
size_t n = strlen(str);
|
||||
char tmp[n];
|
||||
buf.readStrict(tmp, n);
|
||||
ASSERT_EQ(strncmp(tmp, str, n), 0);
|
||||
std::vector<char> tmp(n);
|
||||
buf.readStrict(tmp.data(), n);
|
||||
ASSERT_EQ(strncmp(tmp.data(), str, n), 0);
|
||||
}
|
||||
|
||||
static void assertAvailable(DB::ReadBuffer & buf, const char * str)
|
||||
|
@ -252,7 +252,7 @@ int compressFiles(const char* out_name, const char* exec, char* filenames[], int
|
||||
|
||||
/// Store information about each file and compress it
|
||||
FileData* files_data = new FileData[count + is_exec];
|
||||
const char * names[count + is_exec];
|
||||
std::vector<const char *> names(count + is_exec);
|
||||
for (int i = 0; i <= count; ++i)
|
||||
{
|
||||
const char* filename = nullptr;
|
||||
@ -342,7 +342,7 @@ int compressFiles(const char* out_name, const char* exec, char* filenames[], int
|
||||
/// save location of files information
|
||||
metadata.start_of_files_data = htole64(pointer);
|
||||
|
||||
if (0 != saveMetaData(names, count + is_exec, output_fd, metadata, files_data, pointer, sum_file_size))
|
||||
if (0 != saveMetaData(names.data(), count + is_exec, output_fd, metadata, files_data, pointer, sum_file_size))
|
||||
{
|
||||
delete [] files_data;
|
||||
return 1;
|
||||
|
@ -240,32 +240,32 @@ int decompressFiles(int input_fd, char * path, char * name, bool & have_compress
|
||||
|
||||
size_t file_path_len = path ? strlen(path) + 1 + file_name_len : file_name_len;
|
||||
|
||||
char file_name[file_path_len];
|
||||
memset(file_name, '\0', file_path_len);
|
||||
std::vector<char> file_name(file_path_len);
|
||||
memset(file_name.data(), '\0', file_path_len);
|
||||
if (path)
|
||||
{
|
||||
strcat(file_name, path); // NOLINT(clang-analyzer-security.insecureAPI.strcpy)
|
||||
strcat(file_name, "/"); // NOLINT(clang-analyzer-security.insecureAPI.strcpy)
|
||||
strcat(file_name.data(), path); // NOLINT(clang-analyzer-security.insecureAPI.strcpy)
|
||||
strcat(file_name.data(), "/"); // NOLINT(clang-analyzer-security.insecureAPI.strcpy)
|
||||
}
|
||||
|
||||
bool same_name = false;
|
||||
if (file_info.exec)
|
||||
{
|
||||
has_exec = true;
|
||||
strcat(file_name, name); // NOLINT(clang-analyzer-security.insecureAPI.strcpy)
|
||||
strcat(file_name.data(), name); // NOLINT(clang-analyzer-security.insecureAPI.strcpy)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strcmp(name, input + files_pointer) == 0)
|
||||
same_name = true;
|
||||
strcat(file_name, input + files_pointer); // NOLINT(clang-analyzer-security.insecureAPI.strcpy)
|
||||
strcat(file_name.data(), input + files_pointer); // NOLINT(clang-analyzer-security.insecureAPI.strcpy)
|
||||
}
|
||||
|
||||
files_pointer += le64toh(file_info.name_length);
|
||||
if (file_info.exec || same_name)
|
||||
{
|
||||
strcat(file_name, ".decompressed.XXXXXX"); // NOLINT(clang-analyzer-security.insecureAPI.strcpy)
|
||||
int fd = mkstemp(file_name);
|
||||
strcat(file_name.data(), ".decompressed.XXXXXX"); // NOLINT(clang-analyzer-security.insecureAPI.strcpy)
|
||||
int fd = mkstemp(file_name.data());
|
||||
if (fd == -1)
|
||||
{
|
||||
perror("mkstemp");
|
||||
@ -273,12 +273,12 @@ int decompressFiles(int input_fd, char * path, char * name, bool & have_compress
|
||||
}
|
||||
if (0 != close(fd))
|
||||
perror("close");
|
||||
strncpy(decompressed_suffix, file_name + strlen(file_name) - 6, 6);
|
||||
strncpy(decompressed_suffix, file_name.data() + strlen(file_name.data()) - 6, 6);
|
||||
*decompressed_umask = le64toh(file_info.umask);
|
||||
have_compressed_analoge = true;
|
||||
}
|
||||
|
||||
int output_fd = open(file_name, O_RDWR | O_CREAT, le64toh(file_info.umask));
|
||||
int output_fd = open(file_name.data(), O_RDWR | O_CREAT, le64toh(file_info.umask));
|
||||
|
||||
if (output_fd == -1)
|
||||
{
|
||||
@ -330,7 +330,7 @@ int decompressFiles(int input_fd, char * path, char * name, bool & have_compress
|
||||
perror("close");
|
||||
|
||||
if (is_sudo)
|
||||
chown(file_name, info_in.st_uid, info_in.st_gid);
|
||||
chown(file_name.data(), info_in.st_uid, info_in.st_gid);
|
||||
}
|
||||
|
||||
if (0 != munmap(input, info_in.st_size))
|
||||
@ -415,19 +415,19 @@ int main(int/* argc*/, char* argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
char file_path[strlen(self) + 1];
|
||||
strcpy(file_path, self); // NOLINT(clang-analyzer-security.insecureAPI.strcpy)
|
||||
std::vector<char> file_path(strlen(self) + 1);
|
||||
strcpy(file_path.data(), self); // NOLINT(clang-analyzer-security.insecureAPI.strcpy)
|
||||
|
||||
char * path = nullptr;
|
||||
char * name = strrchr(file_path, '/');
|
||||
char * name = strrchr(file_path.data(), '/');
|
||||
if (name)
|
||||
{
|
||||
path = file_path;
|
||||
path = file_path.data();
|
||||
*name = 0;
|
||||
++name;
|
||||
}
|
||||
else
|
||||
name = file_path;
|
||||
name = file_path.data();
|
||||
|
||||
struct stat input_info;
|
||||
if (0 != stat(self, &input_info))
|
||||
@ -526,20 +526,20 @@ int main(int/* argc*/, char* argv[])
|
||||
{
|
||||
const char * const decompressed_name_fmt = "%s.decompressed.%s";
|
||||
int decompressed_name_len = snprintf(nullptr, 0, decompressed_name_fmt, self, decompressed_suffix);
|
||||
char decompressed_name[decompressed_name_len + 1];
|
||||
(void)snprintf(decompressed_name, decompressed_name_len + 1, decompressed_name_fmt, self, decompressed_suffix);
|
||||
std::vector<char> decompressed_name(decompressed_name_len + 1);
|
||||
(void)snprintf(decompressed_name.data(), decompressed_name_len + 1, decompressed_name_fmt, self, decompressed_suffix);
|
||||
|
||||
#if defined(OS_DARWIN)
|
||||
// We can't just rename it on Mac due to security issues, so we copy it...
|
||||
std::error_code ec;
|
||||
std::filesystem::copy_file(static_cast<char *>(decompressed_name), static_cast<char *>(self), ec);
|
||||
std::filesystem::copy_file(static_cast<char *>(decompressed_name.data()), static_cast<char *>(self), ec);
|
||||
if (ec)
|
||||
{
|
||||
std::cerr << ec.message() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
if (link(decompressed_name, self))
|
||||
if (link(decompressed_name.data(), self))
|
||||
{
|
||||
perror("link");
|
||||
return 1;
|
||||
@ -551,7 +551,7 @@ int main(int/* argc*/, char* argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (unlink(decompressed_name))
|
||||
if (unlink(decompressed_name.data()))
|
||||
{
|
||||
perror("unlink");
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user