Update rust logging inclusion based on feedback

Convert cli_dbgmsg to inline function to ensure ctx check for debug flag
is always run

Add copyright and licensing info

Fix valgrind uninitialized buffer issue in cliunzip.c

Windows build fix
pull/376/head
Mickey Sola 4 years ago committed by Micah Snyder
parent e8d78c9627
commit 6cbb648113
  1. 2
      libclamav/others.c
  2. 4
      libclamav/others_common.c
  3. 2
      libclamav/unzip.c
  4. 4
      libclamav_rust/CMakeLists.txt
  5. 20
      libclamav_rust/lib.rs
  6. 29
      libclamav_rust/logging.rs

@ -80,6 +80,8 @@
#include "stats.h"
#include "json_api.h"
#include "libclamav_rust/clamav_rust.h"
cl_unrar_error_t (*cli_unrar_open)(const char *filename, void **hArchive, char **comment, uint32_t *comment_size, uint8_t debug_flag);
cl_unrar_error_t (*cli_unrar_peek_file_header)(void *hArchive, unrar_metadata_t *file_metadata);
cl_unrar_error_t (*cli_unrar_extract_file)(void *hArchive, const char *destPath, char *outputBuffer);

@ -62,8 +62,6 @@
#include "str.h"
#include "entconv.h"
#include "libclamav_rust/clamav_rust.h"
#define MSGBUFSIZ 8192
static unsigned char name_salt[16] = {16, 38, 97, 12, 8, 4, 72, 196, 217, 144, 33, 124, 18, 11, 17, 253};
@ -175,7 +173,7 @@ void cli_infomsg_simple(const char *str, ...)
inline void cli_dbgmsg(const char *str, ...)
{
if (!UNLIKELY(cli_get_debug_flag())) {
if (UNLIKELY(cli_get_debug_flag())) {
MSGCODE(buff, len, "LibClamAV debug: ");
fputs(buff, stderr);
}

@ -633,6 +633,8 @@ static unsigned int parse_local_file_header(
zip = local_header + SIZEOF_LOCAL_HEADER;
zsize -= SIZEOF_LOCAL_HEADER;
memset(name, '\0', 256);
if (zsize <= LOCAL_HEADER_flen) {
cli_dbgmsg("cli_unzip: local header - fname out of file\n");
fmap_unneed_off(map, loff, SIZEOF_LOCAL_HEADER);

@ -1,10 +1,12 @@
#
# libclamav features written in Rust
#
# Copyright (C) 2021 Cisco Systems, Inc. and/or its affiliates. All rights reserved
#
# libclamav rust static library
add_rust_library(TARGET clamav_rust WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
if (WIN32)
target_link_libraries(clamav_rust PUBLIC Userenv)
target_link_libraries(clamav_rust PUBLIC INTERFACE Userenv)
endif()
add_library(ClamAV::libclamav_rust ALIAS clamav_rust)

@ -1,5 +1,23 @@
/*
* libclamav features written in Rust
* libclamav features written in Rust
*
* Copyright (C) 2021 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
*
* Authors: Micah Snyder, Mickey Sola
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* 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., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
pub mod logging;

@ -1,14 +1,33 @@
/* rust logging module */
/*
* Rust logging module
*
* Copyright (C) 2021 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
*
* Authors: Mickey Sola
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* 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., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
use std::ffi::c_void;
use std::ffi::CString;
use std::os::raw::c_char;
extern crate log;
//use log::debug;
use self::log::LevelFilter;
use self::log::{Level, Metadata, Record};
use self::log::{LevelFilter};
extern "C" {
fn cli_warnmsg(str: *const c_char, ...) -> c_void;
@ -36,13 +55,13 @@ impl log::Log for ClamLogger {
Level::Error => unsafe {
cli_errmsg(ptr);
},
Level::Info => unsafe {
Level::Info => unsafe {
cli_infomsg_simple(ptr);
},
Level::Warn => unsafe {
cli_warnmsg(ptr);
},
_ => {},
_ => {}
}
}
}

Loading…
Cancel
Save