1
Description: fix segmentation fault running tests
2
The patch fixes segmentation fault occurring on some systems,
3
especially SUSE Linux, due too internal opt.files[] array not
4
alwais ending with NULL. Insteed of just ending this array
5
with NULL, the code was modified to track the size of opt.files[].
7
Origin: upstream https://github.com/rhash/RHash/commit/bee2338cbf9323531a0998a118d94936d39289e2
8
Author: Aleksey Kravchenko <rhash.admin@gmail.com>
9
Bug-RHash: https://sourceforge.net/tracker/?func=detail&aid=3391587&group_id=205103&atid=992288
10
Forwarded: sent-to-upstream
11
Last-Update: 2011-08-23
14
diff --git a/parse_cmdline.c b/parse_cmdline.c
15
index e47edba..42d2835 100644
18
@@ -946,15 +946,15 @@ void read_options(int argc, char *argv[])
19
for(; p > path && IS_PATH_SEPARATOR_W(*p) && p[-1] != L':'; p--) *p = 0;
20
expand_wildcards(expanded_cnames, path);
22
- /* the following NULL marks the end of files */
23
- if(cmd_line.n_files) rsh_vector_add_ptr(expanded_cnames, NULL);
25
opt.cmd_vec = expanded_cnames;
26
opt.files = (char**)expanded_cnames->array;
27
+ opt.n_files = (int)expanded_cnames->size;
29
LocalFree(cmd_line.warg);
31
opt.files = cmd_line.files;
32
+ opt.n_files = cmd_line.n_files;
33
rsh_vector_add_ptr(opt.mem, opt.files);
36
diff --git a/parse_cmdline.h b/parse_cmdline.h
37
index 481c506..1c8f799 100644
40
@@ -78,7 +78,8 @@ struct options_t {
41
unsigned openssl_mask; /* mask which openssl hashes to use */
45
+ char** files; /* the files to process */
46
+ int n_files; /* the number of files */
47
struct vector_t *cmd_vec; /* vector for command line arguments */
48
struct vector_t *mem; /* heap variables that should be freed */
50
diff --git a/rhash_main.c b/rhash_main.c
51
index 33b4ebc..ab81abb 100644
54
@@ -145,24 +145,26 @@ static int load_printf_template(void)
56
static void print_sfv_file_header(void)
60
/* print SFV file header */
61
if(opt.fmt == FMT_SFV && opt.mode == 0) {
63
print_sfv_banner(rhash_data.out);
65
- for(f = opt.files; *f != NULL; f++) {
66
+ for(i = 0; i < opt.n_files; i++) {
67
+ char *path = opt.files[i];
68
if(opt.flags & OPT_RECURSIVE) {
69
struct rsh_stat_struct stat_buf;
70
- if(rsh_stat(*f, &stat_buf) < 0) {
71
+ if(rsh_stat(path, &stat_buf) < 0) {
72
continue; /* don't report error here, it'll be reported later */
74
/* if file is a directory, then walk it recursively */
75
if(S_ISDIR(stat_buf.st_mode)) {
76
- find_file(*f, find_file_callback, 0, opt.find_max_depth, (void*)1);
77
+ find_file(path, find_file_callback, 0, opt.find_max_depth, (void*)1);
81
- print_sfv_header_line(rhash_data.out, *f, *f);
82
+ print_sfv_header_line(rhash_data.out, path, path);
84
fflush(rhash_data.out);
86
@@ -175,39 +177,40 @@ static void process_files(void)
89
struct rsh_stat_struct stat_buf;
91
rhash_timer_start(&timer);
92
rhash_data.processed = 0;
94
/* process filenames */
95
- for (;*opt.files != NULL;opt.files++) {
96
+ for(i = 0; i < opt.n_files; i++) {
98
+ char* filepath = opt.files[i];
101
- if(!IS_DASH_STR(*opt.files) && rsh_stat(*opt.files, &stat_buf) < 0) {
102
- log_file_error(*opt.files);
103
+ if(!IS_DASH_STR(filepath) && rsh_stat(filepath, &stat_buf) < 0) {
104
+ log_file_error(filepath);
107
if(opt.flags & OPT_RECURSIVE) {
108
if(S_ISDIR(stat_buf.st_mode)) {
109
- find_file(*opt.files, find_file_callback, 0, opt.find_max_depth, NULL);
110
+ find_file(filepath, find_file_callback, 0, opt.find_max_depth, NULL);
116
if(S_ISDIR(stat_buf.st_mode)){
117
if(opt.flags & OPT_VERBOSE){
118
- log_msg("warning: %s: is a directory\n", *opt.files);
119
+ log_msg("warning: %s: is a directory\n", filepath);
125
if(opt.mode & (MODE_CHECK | MODE_CHECK_EMBEDDED)) {
126
- res = check_hash_file(*opt.files, 0);
127
+ res = check_hash_file(filepath, 0);
128
} else if(opt.mode & MODE_UPDATE) {
129
- res = update_hash_file(*opt.files);
130
+ res = update_hash_file(filepath);
132
- res = calculate_and_print_sums(rhash_data.out, *opt.files, *opt.files, &stat_buf);
133
+ res = calculate_and_print_sums(rhash_data.out, filepath, filepath, &stat_buf);
134
rhash_data.processed++;
136
if(res < 0) rhash_data.error_flag = 1;
137
@@ -264,7 +267,7 @@ int main(int argc, char *argv[])
141
- if (opt.files == NULL || *opt.files == NULL) {
142
+ if(opt.n_files == 0) {
144
log_msg("warning: no files/directories were specified at command line\n");