mirror of
https://github.com/Cisco-Talos/clamav.git
synced 2025-10-19 10:23:17 +00:00
cdiff: Replace cdiff-apply feature with Rust implementation
Apply both .cdiff and .script CVD patches. Note: A script is a non-compressed and unsigned file containing cdiff commands. There is no header or footer that should be processed. This Rust-based implementation of the cdiff-apply feature includes equivalent features as found in the C-based implementation: - cdiff file signature validation against sha256 of the file contents - Gz decoding of file contents - File open command - File close command - Signature add command - Line delete command - Xchg command - Move command - Unlink command This Rust implementation adds cdiff-apply unit tests to verify correct functionality.
This commit is contained in:
parent
1fbf6ae4f0
commit
dda0a70d90
10 changed files with 1320 additions and 1090 deletions
|
@ -3,3 +3,6 @@
|
||||||
members = [
|
members = [
|
||||||
"libclamav_rust",
|
"libclamav_rust",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
opt-level = 2
|
||||||
|
|
|
@ -15,7 +15,6 @@ add_library( common STATIC )
|
||||||
target_sources( common
|
target_sources( common
|
||||||
PRIVATE
|
PRIVATE
|
||||||
cert_util.c
|
cert_util.c
|
||||||
cdiff.c
|
|
||||||
actions.c
|
actions.c
|
||||||
clamdcom.c
|
clamdcom.c
|
||||||
getopt.c
|
getopt.c
|
||||||
|
@ -27,7 +26,6 @@ target_sources( common
|
||||||
tar.c
|
tar.c
|
||||||
PUBLIC
|
PUBLIC
|
||||||
cert_util.h
|
cert_util.h
|
||||||
cdiff.h
|
|
||||||
actions.h
|
actions.h
|
||||||
clamdcom.h
|
clamdcom.h
|
||||||
fdpassing.h
|
fdpassing.h
|
||||||
|
|
1058
common/cdiff.c
1058
common/cdiff.c
File diff suppressed because it is too large
Load diff
|
@ -1,26 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2006 Sensory Networks, Inc.
|
|
||||||
* (C) 2007 Tomasz Kojm <tkojm@clamav.net>
|
|
||||||
* Written by Tomasz Kojm
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __CDIFF_H
|
|
||||||
#define __CDIFF_H
|
|
||||||
|
|
||||||
int cdiff_apply(int fd, unsigned short mode);
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -4,11 +4,14 @@ name = "clamav_rust"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[profile.dev.package."*"]
|
|
||||||
opt-level = 2
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = {version = "*", features = ["std"]}
|
log = {version = "*", features = ["std"]}
|
||||||
|
openssl-sys = "0.9"
|
||||||
|
openssl = "0.10"
|
||||||
|
hex = "0.4.2"
|
||||||
|
flate2 = "1.0.3"
|
||||||
|
thiserror = "1.0.26"
|
||||||
|
tempfile = "3.2.0"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["staticlib"]
|
crate-type = ["staticlib"]
|
||||||
|
|
|
@ -17,12 +17,14 @@ no_includes = false
|
||||||
after_includes = ""
|
after_includes = ""
|
||||||
|
|
||||||
[export]
|
[export]
|
||||||
include = []
|
include = ["cdiff_apply"]
|
||||||
exclude = [
|
exclude = [
|
||||||
"cli_dbgmsg",
|
"cli_dbgmsg",
|
||||||
"cli_errmsg",
|
"cli_errmsg",
|
||||||
"cli_infomsg_simple",
|
"cli_infomsg_simple",
|
||||||
"cli_warnmsg",
|
"cli_warnmsg",
|
||||||
|
"cli_versig2",
|
||||||
|
"cli_get_debug_flag",
|
||||||
]
|
]
|
||||||
# prefix = "CAPI_"
|
# prefix = "CAPI_"
|
||||||
item_types = []
|
item_types = []
|
||||||
|
|
16
libclamav_rust/cdiff.h
Normal file
16
libclamav_rust/cdiff.h
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/* Copyright (C) 2021 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */
|
||||||
|
|
||||||
|
#ifndef __RDIFF_H
|
||||||
|
#define __RDIFF_H
|
||||||
|
|
||||||
|
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
int32_t cdiff_apply(int32_t file_descriptor, uint16_t mode);
|
||||||
|
|
||||||
|
#endif /* __RDIFF_H */
|
1288
libclamav_rust/src/cdiff.rs
Normal file
1288
libclamav_rust/src/cdiff.rs
Normal file
File diff suppressed because it is too large
Load diff
|
@ -20,4 +20,5 @@
|
||||||
* MA 02110-1301, USA.
|
* MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
pub mod cdiff;
|
||||||
pub mod logging;
|
pub mod logging;
|
||||||
|
|
|
@ -77,6 +77,9 @@
|
||||||
#include "cdiff.h"
|
#include "cdiff.h"
|
||||||
#include "tar.h"
|
#include "tar.h"
|
||||||
|
|
||||||
|
// common rust
|
||||||
|
#include "cdiff.h"
|
||||||
|
|
||||||
#include "vba.h"
|
#include "vba.h"
|
||||||
|
|
||||||
#define MAX_DEL_LOOKAHEAD 5000
|
#define MAX_DEL_LOOKAHEAD 5000
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue