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:
John Humlick 2021-09-23 15:27:19 -07:00 committed by Micah Snyder
parent 1fbf6ae4f0
commit dda0a70d90
10 changed files with 1320 additions and 1090 deletions

View file

@ -3,3 +3,6 @@
members = [
"libclamav_rust",
]
[profile.dev.package."*"]
opt-level = 2

View file

@ -15,7 +15,6 @@ add_library( common STATIC )
target_sources( common
PRIVATE
cert_util.c
cdiff.c
actions.c
clamdcom.c
getopt.c
@ -27,7 +26,6 @@ target_sources( common
tar.c
PUBLIC
cert_util.h
cdiff.h
actions.h
clamdcom.h
fdpassing.h

File diff suppressed because it is too large Load diff

View file

@ -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

View file

@ -4,11 +4,14 @@ name = "clamav_rust"
version = "0.0.1"
edition = "2018"
[profile.dev.package."*"]
opt-level = 2
[dependencies]
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]
crate-type = ["staticlib"]

View file

@ -17,12 +17,14 @@ no_includes = false
after_includes = ""
[export]
include = []
include = ["cdiff_apply"]
exclude = [
"cli_dbgmsg",
"cli_errmsg",
"cli_infomsg_simple",
"cli_warnmsg",
"cli_versig2",
"cli_get_debug_flag",
]
# prefix = "CAPI_"
item_types = []

16
libclamav_rust/cdiff.h Normal file
View 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

File diff suppressed because it is too large Load diff

View file

@ -20,4 +20,5 @@
* MA 02110-1301, USA.
*/
pub mod cdiff;
pub mod logging;

View file

@ -77,6 +77,9 @@
#include "cdiff.h"
#include "tar.h"
// common rust
#include "cdiff.h"
#include "vba.h"
#define MAX_DEL_LOOKAHEAD 5000