Compare commits

...

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
1bc7aba047
!47 Fix CVE-2015-1197
From: @fly_fzc 
Reviewed-by: @ziyangc 
Signed-off-by: @ziyangc
2023-08-22 07:49:27 +00:00
fly_fzc
e277541de8 Fix CVE-2015-1197 2023-08-21 18:36:29 +08:00
openeuler-ci-bot
8c04206b57
!46 revert CVE-2015-1197 fix for --no-absolute-filenames
From: @zhangruifang2020 
Reviewed-by: @ziyangc 
Signed-off-by: @ziyangc
2023-07-26 02:49:52 +00:00
zhangruifang2020
843e09686f revert CVE-2015-1197 fix for --no-absolute-filenames 2023-07-26 10:09:10 +08:00
openeuler-ci-bot
51ece0d351
!45 update to 2.14
From: @zhangruifang2020 
Reviewed-by: @ziyangc 
Signed-off-by: @ziyangc
2023-07-21 06:48:48 +00:00
zhangruifang2020
459ab51a8c update to 2.14 2023-07-17 11:57:02 +08:00
openeuler-ci-bot
518213d394
!38 revert fix CVE-2015-1197 because it causes AT testcases problems
From: @fly_fzc 
Reviewed-by: @gaoruoshu 
Signed-off-by: @gaoruoshu
2023-06-20 01:16:57 +00:00
fly_fzc
a2a43267f5 revert fix CVE-2015-1197 because it causes AT testcases problems 2023-06-20 08:44:05 +08:00
openeuler-ci-bot
d6e41ec0c1
!31 Fix CVE-2015-1197
From: @fly_fzc 
Reviewed-by: @lvying6 
Signed-off-by: @lvying6
2023-05-30 12:34:32 +00:00
fly_fzc
8b4761c52d Fix CVE-2015-1197 2023-05-27 17:47:54 +08:00
16 changed files with 1158 additions and 807 deletions

View File

@ -18,23 +18,24 @@ The format of metadata for the xattr type is:
<xattr name>\0<xattr value>
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
---
doc/cpio.texi | 3 ++
src/copyout.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
src/dstring.c | 26 +++++++++--
src/copyout.c | 138 +++++++++++++++++++++++++++++++++++++++++++++++-
src/dstring.c | 26 +++++++--
src/dstring.h | 1 +
src/extern.h | 4 +-
src/global.c | 2 +
src/initramfs.h | 21 +++++++++
src/main.c | 22 +++++++++
8 files changed, 211 insertions(+), 8 deletions(-)
src/extern.h | 2 +
src/global.c | 4 ++
src/initramfs.h | 21 ++++++++
src/main.c | 22 ++++++++
8 files changed, 212 insertions(+), 5 deletions(-)
create mode 100644 src/initramfs.h
diff --git a/doc/cpio.texi b/doc/cpio.texi
index 31a15fa..03d9585 100644
index bef7ba5..ea73a92 100644
--- a/doc/cpio.texi
+++ b/doc/cpio.texi
@@ -276,6 +276,9 @@ Set the I/O block size to the given @var{number} of bytes.
@@ -279,6 +279,9 @@ Set the I/O block size to the given @var{number} of bytes.
@item -D @var{dir}
@itemx --directory=@var{dir}
Change to directory @var{dir}
@ -45,10 +46,10 @@ index 31a15fa..03d9585 100644
Treat the archive file as local, even if its name contains colons.
@item -F [[@var{user}@@]@var{host}:]@var{archive-file}
diff --git a/src/copyout.c b/src/copyout.c
index 421d36d..4cd60a3 100644
index 6e82f4c..8ae1a48 100644
--- a/src/copyout.c
+++ b/src/copyout.c
@@ -22,6 +22,7 @@
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -56,7 +57,7 @@ index 421d36d..4cd60a3 100644
#include "filetypes.h"
#include "cpiohdr.h"
#include "dstring.h"
@@ -589,6 +590,94 @@ assign_string (char **pvar, char *value)
@@ -586,6 +587,94 @@ assign_string (char **pvar, char *value)
*pvar = p;
}
@ -151,7 +152,7 @@ index 421d36d..4cd60a3 100644
/* Read a list of file names from the standard input
and write a cpio collection on the standard output.
The format of the header depends on the compatibility (-c) flag. */
@@ -604,6 +693,8 @@ process_copy_out (void)
@@ -601,6 +690,8 @@ process_copy_out (void)
int in_file_des; /* Source file descriptor. */
int out_file_des; /* Output file descriptor. */
char *orig_file_name = NULL;
@ -160,9 +161,9 @@ index 421d36d..4cd60a3 100644
/* Initialize the copy out. */
file_hdr.c_magic = 070707;
@@ -635,9 +726,37 @@ process_copy_out (void)
prepare_append (out_file_des);
}
@@ -632,9 +723,37 @@ process_copy_out (void)
else
change_dir ();
+ /* Create a temporary file to store file metadata */
+ if (metadata_type != TYPE_NONE) {
@ -199,25 +200,23 @@ index 421d36d..4cd60a3 100644
/* Check for blank line. */
if (input_name.ds_string[0] == 0)
{
@@ -662,8 +781,15 @@ process_copy_out (void)
ds_append (&input_name, '/');
@@ -660,7 +779,14 @@ process_copy_out (void)
}
}
-
- assign_string (&orig_file_name, input_name.ds_string);
+
+ if (old_metadata) {
+ assign_string (&orig_file_name, template);
+ ds_sgetstr (METADATA_FILENAME, &input_name, name_end);
+ file_hdr.c_mode |= 0x10000;
+ if (old_metadata) {
+ assign_string (&orig_file_name, template);
+ ds_sgetstr (METADATA_FILENAME, &input_name, name_end);
+ file_hdr.c_mode |= 0x10000;
+ } else {
+ assign_string (&orig_file_name, input_name.ds_string);
+ assign_string (&orig_file_name, input_name.ds_string);
+ }
+
cpio_safer_name_suffix (input_name.ds_string, false,
!no_abs_paths_flag, true);
cpio_set_c_name (&file_hdr, input_name.ds_string);
@@ -695,6 +821,7 @@ process_copy_out (void)
@@ -692,6 +818,7 @@ process_copy_out (void)
else
{
add_link_defer (&file_hdr);
@ -225,7 +224,7 @@ index 421d36d..4cd60a3 100644
break;
}
}
@@ -831,6 +958,8 @@ process_copy_out (void)
@@ -830,6 +957,8 @@ process_copy_out (void)
fprintf (stderr, "%s\n", orig_file_name);
if (dot_flag)
fputc ('.', stderr);
@ -234,7 +233,7 @@ index 421d36d..4cd60a3 100644
}
}
@@ -871,6 +1000,11 @@ process_copy_out (void)
@@ -870,4 +999,9 @@ process_copy_out (void)
}
cpio_file_stat_free (&file_hdr);
ds_free (&input_name);
@ -244,13 +243,11 @@ index 421d36d..4cd60a3 100644
+ unlink(template);
+ }
}
diff --git a/src/dstring.c b/src/dstring.c
index 0f597cc..07e827f 100644
index b425121..f5d8ab5 100644
--- a/src/dstring.c
+++ b/src/dstring.c
@@ -74,8 +74,8 @@ ds_reset (dynamic_string *s, size_t len)
@@ -73,8 +73,8 @@ ds_reset (dynamic_string *s, size_t len)
Return NULL if end of file is detected. Otherwise,
Return a pointer to the null-terminated string in S. */
@ -261,7 +258,7 @@ index 0f597cc..07e827f 100644
{
int next_ch;
@@ -83,10 +83,18 @@ ds_fgetstr (FILE *f, dynamic_string *s, char eos)
@@ -82,10 +82,18 @@ ds_fgetstr (FILE *f, dynamic_string *s, char eos)
s->ds_idx = 0;
/* Read the input string. */
@ -281,20 +278,20 @@ index 0f597cc..07e827f 100644
}
ds_resize (s, 0);
s->ds_string[s->ds_idx] = '\0';
@@ -121,6 +129,12 @@ ds_concat (dynamic_string *s, char const *str)
@@ -119,6 +127,12 @@ ds_concat (dynamic_string *s, char const *str)
s->ds_string[s->ds_idx] = 0;
}
char *
+char *
+ds_fgetstr (FILE *f, dynamic_string *s, char eos)
+{
+ return ds_fgetstr_common (f, NULL, s, eos);
+}
+
+char *
char *
ds_fgets (FILE *f, dynamic_string *s)
{
return ds_fgetstr (f, s, '\n');
@@ -132,6 +146,12 @@ ds_fgetname (FILE *f, dynamic_string *s)
@@ -131,6 +145,12 @@ ds_fgetname (FILE *f, dynamic_string *s)
return ds_fgetstr (f, s, '\0');
}
@ -308,10 +305,10 @@ index 0f597cc..07e827f 100644
int
ds_endswith (dynamic_string *s, int c)
diff --git a/src/dstring.h b/src/dstring.h
index f5b04ef..50c877d 100644
index ac540be..d934d1d 100644
--- a/src/dstring.h
+++ b/src/dstring.h
@@ -41,6 +41,7 @@ void ds_reset (dynamic_string *s, size_t len);
@@ -40,6 +40,7 @@ void ds_reset (dynamic_string *s, size_t len);
char *ds_fgetname (FILE *f, dynamic_string *s);
char *ds_fgets (FILE *f, dynamic_string *s);
char *ds_fgetstr (FILE *f, dynamic_string *s, char eos);
@ -320,37 +317,38 @@ index f5b04ef..50c877d 100644
void ds_concat (dynamic_string *s, char const *str);
diff --git a/src/extern.h b/src/extern.h
index 11ac6bf..f295fcf 100644
index 6afbdd2..49369ab 100644
--- a/src/extern.h
+++ b/src/extern.h
@@ -19,6 +19,7 @@
@@ -18,6 +18,7 @@
#include "paxlib.h"
#include "quotearg.h"
+#include "initramfs.h"
#include "quote.h"
#include "inttostr.h"
enum archive_format
@@ -99,7 +100,8 @@ extern char output_is_seekable;
@@ -100,6 +101,7 @@ extern char output_is_seekable;
extern int (*xstat) ();
extern void (*copy_function) ();
extern char *change_directory_option;
-
+extern enum metadata_types metadata_type;
+
/* copyin.c */
void warn_junk_bytes (long bytes_skipped);
#define STRINGIFY_BIGINT(i, b) umaxtostr (i, b)
enum { UINTMAX_STRSIZE_BOUND = INT_BUFSIZE_BOUND (intmax_t) };
diff --git a/src/global.c b/src/global.c
index acf92bc..d45e19b 100644
index 7c4bca8..bbd84fe 100644
--- a/src/global.c
+++ b/src/global.c
@@ -196,3 +196,5 @@ char *change_directory_option;
@@ -194,4 +194,8 @@ char *change_directory_option;
int renumber_inodes_option;
int ignore_devno_option;
+
+/* include file metadata into the image */
+enum metadata_types metadata_type = TYPE_NONE;
+
int ignore_dirnlink_option;
diff --git a/src/initramfs.h b/src/initramfs.h
new file mode 100644
index 0000000..88abae7
@ -379,19 +377,19 @@ index 0000000..88abae7
+
+#endif /*_LINUX_INITRAMFS_H*/
diff --git a/src/main.c b/src/main.c
index 6f90055..e343286 100644
index f9b4d85..8d5988e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -199,6 +199,8 @@ static struct argp_option options[] = {
@@ -202,6 +202,8 @@ static struct argp_option options[] = {
{"device-independent", DEVICE_INDEPENDENT_OPTION, NULL, 0,
N_("Create device-independent (reproducible) archives") },
{"reproducible", 0, NULL, OPTION_ALIAS },
+ {"file-metadata", 'e', N_("TYPE"), 0,
+ N_("Include file metadata"), GRID+1 },
#undef GRID
/* ********** */
@@ -292,6 +294,22 @@ warn_control (char *arg)
@@ -295,6 +297,22 @@ warn_control (char *arg)
return 1;
}
@ -414,7 +412,7 @@ index 6f90055..e343286 100644
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
@@ -354,6 +372,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
@@ -357,6 +375,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
copy_matching_files = false;
break;
@ -426,5 +424,5 @@ index 6f90055..e343286 100644
pattern_file_name = arg;
break;
--
1.8.3.1
2.27.0

View File

@ -1,462 +0,0 @@
From dd96882877721703e19272fe25034560b794061b Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Sat, 7 Aug 2021 12:52:21 +0300
Subject: [PATCH 11/13] Rewrite dynamic string support.
* src/dstring.c (ds_init): Take a single argument.
(ds_free): New function.
(ds_resize): Take a single argument. Use x2nrealloc to expand
the storage.
(ds_reset,ds_append,ds_concat,ds_endswith): New function.
(ds_fgetstr): Rewrite. In particular, this fixes integer overflow.
* src/dstring.h (dynamic_string): Keep both the allocated length
(ds_size) and index of the next free byte in the string (ds_idx).
(ds_init,ds_resize): Change signature.
(ds_len): New macro.
(ds_free,ds_reset,ds_append,ds_concat,ds_endswith): New protos.
* src/copyin.c: Use new ds_ functions.
* src/copyout.c: Likewise.
* src/copypass.c: Likewise.
* src/util.c: Likewise.
---
src/copyin.c | 40 +++++++++++++-------------
src/copyout.c | 16 ++++-------
src/copypass.c | 34 +++++++++++------------
src/dstring.c | 88 ++++++++++++++++++++++++++++++++++++++++++----------------
src/dstring.h | 31 ++++++++++-----------
src/util.c | 6 ++--
6 files changed, 123 insertions(+), 92 deletions(-)
diff --git a/src/copyin.c b/src/copyin.c
index bf3b0a8..c7f4b49 100644
--- a/src/copyin.c
+++ b/src/copyin.c
@@ -55,11 +55,12 @@ query_rename(struct cpio_file_stat* file_hdr, FILE *tty_in, FILE *tty_out,
char *str_res; /* Result for string function. */
static dynamic_string new_name; /* New file name for rename option. */
static int initialized_new_name = false;
+
if (!initialized_new_name)
- {
- ds_init (&new_name, 128);
- initialized_new_name = true;
- }
+ {
+ ds_init (&new_name);
+ initialized_new_name = true;
+ }
if (rename_flag)
{
@@ -778,39 +779,41 @@ long_format (struct cpio_file_stat *file_hdr, char const *link_name)
already in `save_patterns' (from the command line) are preserved. */
static void
-read_pattern_file ()
+read_pattern_file (void)
{
- int max_new_patterns;
- char **new_save_patterns;
- int new_num_patterns;
+ char **new_save_patterns = NULL;
+ size_t max_new_patterns;
+ size_t new_num_patterns;
int i;
- dynamic_string pattern_name;
+ dynamic_string pattern_name = DYNAMIC_STRING_INITIALIZER;
FILE *pattern_fp;
if (num_patterns < 0)
num_patterns = 0;
- max_new_patterns = 1 + num_patterns;
- new_save_patterns = (char **) xmalloc (max_new_patterns * sizeof (char *));
new_num_patterns = num_patterns;
- ds_init (&pattern_name, 128);
+ max_new_patterns = num_patterns;
+ new_save_patterns = xcalloc (max_new_patterns, sizeof (new_save_patterns[0]));
pattern_fp = fopen (pattern_file_name, "r");
if (pattern_fp == NULL)
+ {
open_error (pattern_file_name);
+ ds_free (&pattern_name);
+ }
else
{
while (ds_fgetstr (pattern_fp, &pattern_name, '\n') != NULL)
{
- if (new_num_patterns >= max_new_patterns)
- {
- max_new_patterns += 1;
- new_save_patterns = (char **)
- xrealloc ((char *) new_save_patterns,
- max_new_patterns * sizeof (char *));
- }
+ if (new_num_patterns == max_new_patterns)
+ new_save_patterns = x2nrealloc (new_save_patterns,
+ &max_new_patterns,
+ sizeof (new_save_patterns[0]));
new_save_patterns[new_num_patterns] = xstrdup (pattern_name.ds_string);
++new_num_patterns;
}
+
+ ds_free (&pattern_name);
+
if (ferror (pattern_fp) || fclose (pattern_fp) == EOF)
close_error (pattern_file_name);
}
@@ -1198,7 +1201,7 @@ swab_array (char *ptr, int count)
in the file system. */
void
-process_copy_in ()
+process_copy_in (void)
{
char done = false; /* True if trailer reached. */
FILE *tty_in = NULL; /* Interactive file for rename option. */
diff --git a/src/copyout.c b/src/copyout.c
index 4b7336b..421d36d 100644
--- a/src/copyout.c
+++ b/src/copyout.c
@@ -594,9 +594,10 @@ assign_string (char **pvar, char *value)
The format of the header depends on the compatibility (-c) flag. */
void
-process_copy_out ()
+process_copy_out (void)
{
- dynamic_string input_name; /* Name of file read from stdin. */
+ dynamic_string input_name = DYNAMIC_STRING_INITIALIZER;
+ /* Name of file read from stdin. */
struct stat file_stat; /* Stat record for file. */
struct cpio_file_stat file_hdr = CPIO_FILE_STAT_INITIALIZER;
/* Output header information. */
@@ -605,7 +606,6 @@ process_copy_out ()
char *orig_file_name = NULL;
/* Initialize the copy out. */
- ds_init (&input_name, 128);
file_hdr.c_magic = 070707;
/* Check whether the output file might be a tape. */
@@ -657,14 +657,9 @@ process_copy_out ()
{
if (file_hdr.c_mode & CP_IFDIR)
{
- int len = strlen (input_name.ds_string);
/* Make sure the name ends with a slash */
- if (input_name.ds_string[len-1] != '/')
- {
- ds_resize (&input_name, len + 2);
- input_name.ds_string[len] = '/';
- input_name.ds_string[len+1] = 0;
- }
+ if (!ds_endswith (&input_name, '/'))
+ ds_append (&input_name, '/');
}
}
@@ -875,6 +870,7 @@ process_copy_out ()
(unsigned long) blocks), (unsigned long) blocks);
}
cpio_file_stat_free (&file_hdr);
+ ds_free (&input_name);
}
diff --git a/src/copypass.c b/src/copypass.c
index dc13b5b..62f31c6 100644
--- a/src/copypass.c
+++ b/src/copypass.c
@@ -48,10 +48,12 @@ set_copypass_perms (int fd, const char *name, struct stat *st)
If `link_flag', link instead of copying. */
void
-process_copy_pass ()
+process_copy_pass (void)
{
- dynamic_string input_name; /* Name of file from stdin. */
- dynamic_string output_name; /* Name of new file. */
+ dynamic_string input_name = DYNAMIC_STRING_INITIALIZER;
+ /* Name of file from stdin. */
+ dynamic_string output_name = DYNAMIC_STRING_INITIALIZER;
+ /* Name of new file. */
size_t dirname_len; /* Length of `directory_name'. */
int res; /* Result of functions. */
char *slash; /* For moving past slashes in input name. */
@@ -65,25 +67,18 @@ process_copy_pass ()
created files */
/* Initialize the copy pass. */
- ds_init (&input_name, 128);
dirname_len = strlen (directory_name);
if (change_directory_option && !ISSLASH (directory_name[0]))
{
char *pwd = xgetcwd ();
-
- dirname_len += strlen (pwd) + 1;
- ds_init (&output_name, dirname_len + 2);
- strcpy (output_name.ds_string, pwd);
- strcat (output_name.ds_string, "/");
- strcat (output_name.ds_string, directory_name);
+
+ ds_concat (&output_name, pwd);
+ ds_append (&output_name, '/');
}
- else
- {
- ds_init (&output_name, dirname_len + 2);
- strcpy (output_name.ds_string, directory_name);
- }
- output_name.ds_string[dirname_len] = '/';
+ ds_concat (&output_name, directory_name);
+ ds_append (&output_name, '/');
+ dirname_len = ds_len (&output_name);
output_is_seekable = true;
change_dir ();
@@ -116,8 +111,8 @@ process_copy_pass ()
/* Make the name of the new file. */
for (slash = input_name.ds_string; *slash == '/'; ++slash)
;
- ds_resize (&output_name, dirname_len + strlen (slash) + 2);
- strcpy (output_name.ds_string + dirname_len + 1, slash);
+ ds_reset (&output_name, dirname_len);
+ ds_concat (&output_name, slash);
existing_dir = false;
if (lstat (output_name.ds_string, &out_file_stat) == 0)
@@ -333,6 +328,9 @@ process_copy_pass ()
(unsigned long) blocks),
(unsigned long) blocks);
}
+
+ ds_free (&input_name);
+ ds_free (&output_name);
}
/* Try and create a hard link from FILE_NAME to another file
diff --git a/src/dstring.c b/src/dstring.c
index e9c063f..358f356 100644
--- a/src/dstring.c
+++ b/src/dstring.c
@@ -20,8 +20,8 @@
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
-
#include <stdio.h>
+#include <stdlib.h>
#if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
#include <string.h>
#else
@@ -33,24 +33,41 @@
/* Initialiaze dynamic string STRING with space for SIZE characters. */
void
-ds_init (dynamic_string *string, int size)
+ds_init (dynamic_string *string)
+{
+ memset (string, 0, sizeof *string);
+}
+
+/* Free the dynamic string storage. */
+
+void
+ds_free (dynamic_string *string)
{
- string->ds_length = size;
- string->ds_string = (char *) xmalloc (size);
+ free (string->ds_string);
}
-/* Expand dynamic string STRING, if necessary, to hold SIZE characters. */
+/* Expand dynamic string STRING, if necessary. */
void
-ds_resize (dynamic_string *string, int size)
+ds_resize (dynamic_string *string)
{
- if (size > string->ds_length)
+ if (string->ds_idx == string->ds_size)
{
- string->ds_length = size;
- string->ds_string = (char *) xrealloc ((char *) string->ds_string, size);
+ string->ds_string = x2nrealloc (string->ds_string, &string->ds_size,
+ 1);
}
}
+/* Reset the index of the dynamic string S to LEN. */
+
+void
+ds_reset (dynamic_string *s, size_t len)
+{
+ while (len > s->ds_size)
+ ds_resize (s);
+ s->ds_idx = len;
+}
+
/* Dynamic string S gets a string terminated by the EOS character
(which is removed) from file F. S will increase
in size during the function if the string from F is longer than
@@ -61,34 +78,50 @@ ds_resize (dynamic_string *string, int size)
char *
ds_fgetstr (FILE *f, dynamic_string *s, char eos)
{
- int insize; /* Amount needed for line. */
- int strsize; /* Amount allocated for S. */
int next_ch;
/* Initialize. */
- insize = 0;
- strsize = s->ds_length;
+ s->ds_idx = 0;
/* Read the input string. */
- next_ch = getc (f);
- while (next_ch != eos && next_ch != EOF)
+ while ((next_ch = getc (f)) != eos && next_ch != EOF)
{
- if (insize >= strsize - 1)
- {
- ds_resize (s, strsize * 2 + 2);
- strsize = s->ds_length;
- }
- s->ds_string[insize++] = next_ch;
- next_ch = getc (f);
+ ds_resize (s);
+ s->ds_string[s->ds_idx++] = next_ch;
}
- s->ds_string[insize++] = '\0';
+ ds_resize (s);
+ s->ds_string[s->ds_idx] = '\0';
- if (insize == 1 && next_ch == EOF)
+ if (s->ds_idx == 0 && next_ch == EOF)
return NULL;
else
return s->ds_string;
}
+void
+ds_append (dynamic_string *s, int c)
+{
+ ds_resize (s);
+ s->ds_string[s->ds_idx] = c;
+ if (c)
+ {
+ s->ds_idx++;
+ ds_resize (s);
+ s->ds_string[s->ds_idx] = 0;
+ }
+}
+
+void
+ds_concat (dynamic_string *s, char const *str)
+{
+ size_t len = strlen (str);
+ while (len + 1 > s->ds_size)
+ ds_resize (s);
+ memcpy (s->ds_string + s->ds_idx, str, len);
+ s->ds_idx += len;
+ s->ds_string[s->ds_idx] = 0;
+}
+
char *
ds_fgets (FILE *f, dynamic_string *s)
{
@@ -100,3 +133,10 @@ ds_fgetname (FILE *f, dynamic_string *s)
{
return ds_fgetstr (f, s, '\0');
}
+
+/* Return true if the dynamic string S ends with character C. */
+int
+ds_endswith (dynamic_string *s, int c)
+{
+ return (s->ds_idx > 0 && s->ds_string[s->ds_idx - 1] == c);
+}
diff --git a/src/dstring.h b/src/dstring.h
index b5135fe..f5b04ef 100644
--- a/src/dstring.h
+++ b/src/dstring.h
@@ -17,10 +17,6 @@
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA. */
-#ifndef NULL
-#define NULL 0
-#endif
-
/* A dynamic string consists of record that records the size of an
allocated string and the pointer to that string. The actual string
is a normal zero byte terminated string that can be used with the
@@ -30,22 +26,25 @@
typedef struct
{
- int ds_length; /* Actual amount of storage allocated. */
- char *ds_string; /* String. */
+ size_t ds_size; /* Actual amount of storage allocated. */
+ size_t ds_idx; /* Index of the next free byte in the string. */
+ char *ds_string; /* String storage. */
} dynamic_string;
+#define DYNAMIC_STRING_INITIALIZER { 0, 0, NULL }
-/* Macros that look similar to the original string functions.
- WARNING: These macros work only on pointers to dynamic string records.
- If used with a real record, an "&" must be used to get the pointer. */
-#define ds_strlen(s) strlen ((s)->ds_string)
-#define ds_strcmp(s1, s2) strcmp ((s1)->ds_string, (s2)->ds_string)
-#define ds_strncmp(s1, s2, n) strncmp ((s1)->ds_string, (s2)->ds_string, n)
-#define ds_index(s, c) index ((s)->ds_string, c)
-#define ds_rindex(s, c) rindex ((s)->ds_string, c)
+void ds_init (dynamic_string *string);
+void ds_free (dynamic_string *string);
+void ds_reset (dynamic_string *s, size_t len);
-void ds_init (dynamic_string *string, int size);
-void ds_resize (dynamic_string *string, int size);
+/* All functions below guarantee that s->ds_string[s->ds_idx] == '\0' */
char *ds_fgetname (FILE *f, dynamic_string *s);
char *ds_fgets (FILE *f, dynamic_string *s);
char *ds_fgetstr (FILE *f, dynamic_string *s, char eos);
+void ds_append (dynamic_string *s, int c);
+void ds_concat (dynamic_string *s, char const *str);
+
+#define ds_len(s) ((s)->ds_idx)
+
+int ds_endswith (dynamic_string *s, int c);
+
diff --git a/src/util.c b/src/util.c
index 4421b20..6d6bbaa 100644
--- a/src/util.c
+++ b/src/util.c
@@ -846,11 +846,9 @@ get_next_reel (int tape_des)
FILE *tty_out; /* File for interacting with user. */
int old_tape_des;
char *next_archive_name;
- dynamic_string new_name;
+ dynamic_string new_name = DYNAMIC_STRING_INITIALIZER;
char *str_res;
- ds_init (&new_name, 128);
-
/* Open files for interactive communication. */
tty_in = fopen (TTY_NAME, "r");
if (tty_in == NULL)
@@ -925,7 +923,7 @@ get_next_reel (int tape_des)
error (PAXEXIT_FAILURE, 0, _("internal error: tape descriptor changed from %d to %d"),
old_tape_des, tape_des);
- free (new_name.ds_string);
+ ds_free (&new_name);
fclose (tty_in);
fclose (tty_out);
}
--
1.8.3.1

View File

@ -1,36 +0,0 @@
From dfc801c44a93bed7b3951905b188823d6a0432c8 Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Wed, 11 Aug 2021 18:10:38 +0300
Subject: [PATCH 12/13] Fix previous commit
* src/dstring.c (ds_reset,ds_concat): Don't call ds_resize in a
loop.
---
src/dstring.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/dstring.c b/src/dstring.c
index 692d3e7..b7e0bb5 100644
--- a/src/dstring.c
+++ b/src/dstring.c
@@ -64,7 +64,7 @@ void
ds_reset (dynamic_string *s, size_t len)
{
while (len > s->ds_size)
- ds_resize (s);
+ s->ds_string = x2nrealloc (s->ds_string, &s->ds_size, 1);
s->ds_idx = len;
}
@@ -116,7 +116,7 @@ ds_concat (dynamic_string *s, char const *str)
{
size_t len = strlen (str);
while (len + 1 > s->ds_size)
- ds_resize (s);
+ s->ds_string = x2nrealloc (s->ds_string, &s->ds_size, 1);
memcpy (s->ds_string + s->ds_idx, str, len);
s->ds_idx += len;
s->ds_string[s->ds_idx] = 0;
--
1.8.3.1

View File

@ -1,78 +0,0 @@
From 236684f6deb3178043fe72a8e2faca538fa2aae1 Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Wed, 18 Aug 2021 09:41:39 +0300
Subject: [PATCH 13/13] Fix dynamic string reallocations
* src/dstring.c (ds_resize): Take additional argument: number of
bytes to leave available after ds_idx. All uses changed.
---
src/dstring.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/src/dstring.c b/src/dstring.c
index b7e0bb5..fd4e030 100644
--- a/src/dstring.c
+++ b/src/dstring.c
@@ -49,9 +49,9 @@ ds_free (dynamic_string *string)
/* Expand dynamic string STRING, if necessary. */
void
-ds_resize (dynamic_string *string)
+ds_resize (dynamic_string *string, size_t len)
{
- if (string->ds_idx == string->ds_size)
+ while (len + string->ds_idx >= string->ds_size)
{
string->ds_string = x2nrealloc (string->ds_string, &string->ds_size,
1);
@@ -63,8 +63,7 @@ ds_resize (dynamic_string *string)
void
ds_reset (dynamic_string *s, size_t len)
{
- while (len > s->ds_size)
- s->ds_string = x2nrealloc (s->ds_string, &s->ds_size, 1);
+ ds_resize (s, len);
s->ds_idx = len;
}
@@ -86,10 +85,10 @@ ds_fgetstr (FILE *f, dynamic_string *s, char eos)
/* Read the input string. */
while ((next_ch = getc (f)) != eos && next_ch != EOF)
{
- ds_resize (s);
+ ds_resize (s, 0);
s->ds_string[s->ds_idx++] = next_ch;
}
- ds_resize (s);
+ ds_resize (s, 0);
s->ds_string[s->ds_idx] = '\0';
if (s->ds_idx == 0 && next_ch == EOF)
@@ -101,12 +100,12 @@ ds_fgetstr (FILE *f, dynamic_string *s, char eos)
void
ds_append (dynamic_string *s, int c)
{
- ds_resize (s);
+ ds_resize (s, 0);
s->ds_string[s->ds_idx] = c;
if (c)
{
s->ds_idx++;
- ds_resize (s);
+ ds_resize (s, 0);
s->ds_string[s->ds_idx] = 0;
}
}
@@ -115,8 +114,7 @@ void
ds_concat (dynamic_string *s, char const *str)
{
size_t len = strlen (str);
- while (len + 1 > s->ds_size)
- s->ds_string = x2nrealloc (s->ds_string, &s->ds_size, 1);
+ ds_resize (s, len);
memcpy (s->ds_string + s->ds_idx, str, len);
s->ds_idx += len;
s->ds_string[s->ds_idx] = 0;
--
1.8.3.1

View File

@ -0,0 +1,34 @@
From 2cf05f5a1826dd127d5c9063cc8cc7667746be38 Mon Sep 17 00:00:00 2001
From: Ziyang Chen <chenziyang4@huawei.com>
Date: Mon, 10 Jul 2023 20:19:27 +0800
Subject: [PATCH] Do not set exit code to 2 when failing to create symlink
---
src/copyin.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/copyin.c b/src/copyin.c
index 2e72356..2b6b361 100644
--- a/src/copyin.c
+++ b/src/copyin.c
@@ -736,7 +736,7 @@ replace_symlink_placeholders (void)
res = UMASKED_SYMLINK (dl->source, dl->target, dl->mode);
}
if (res < 0)
- symlink_error (dl->source, dl->target);
+ error (0, errno, _("%s: Cannot create symlink to %s"), quotearg_colon (dl->target), quote_n (1, dl->source));
else
{
if (!no_chown_flag)
@@ -789,7 +789,7 @@ copyin_link (struct cpio_file_stat *file_hdr, int in_file_des)
res = UMASKED_SYMLINK (link_name, file_hdr->c_name, file_hdr->c_mode);
}
if (res < 0)
- symlink_error (link_name, file_hdr->c_name);
+ error (0, errno, _("%s: Cannot create symlink to %s"), quotearg_colon (file_hdr->c_name), quote_n (1, link_name));
else if (!no_chown_flag)
{
uid_t uid = set_owner_flag ? set_owner : file_hdr->c_uid;
--
2.27.0

View File

@ -1,27 +0,0 @@
From 641d3f489cf6238bb916368d4ba0d9325a235afb Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Mon, 20 Jan 2020 07:45:39 +0200
Subject: [PATCH] Minor fix * src/global.c: Remove superfluous declaration of
program_name
---
src/global.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/global.c b/src/global.c
index fb3abe9..acf92bc 100644
--- a/src/global.c
+++ b/src/global.c
@@ -184,9 +184,6 @@ unsigned int warn_option = 0;
/* Extract to standard output? */
bool to_stdout_option = false;
-/* The name this program was run with. */
-char *program_name;
-
/* A pointer to either lstat or stat, depending on whether
dereferencing of symlinks is done for input files. */
int (*xstat) ();
--
1.8.3.1

View File

@ -0,0 +1,31 @@
From e3cc782c610729de7622a274e532817c18262a9d Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Thu, 18 May 2023 09:00:12 +0300
Subject: [PATCH] Fix operation of --no-absolute-filenames --make-directories
* src/copyin.c (symlink_placeholder): Try to create leading
directories if unable to create placeholder.
---
src/copyin.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/copyin.c b/src/copyin.c
index 1e4921f..08df12c 100644
--- a/src/copyin.c
+++ b/src/copyin.c
@@ -668,6 +668,12 @@ symlink_placeholder (char *oldpath, char *newpath, struct cpio_file_stat *file_s
struct delayed_link *p;
size_t newlen = strlen (newpath);
+ if (fd < 0 && create_dir_flag)
+ {
+ create_all_directories (newpath);
+ fd = open (newpath, O_WRONLY | O_CREAT | O_EXCL, 0);
+ }
+
if (fd < 0)
{
open_error (newpath);
--
2.27.0

View File

@ -0,0 +1,981 @@
From a3eb338a40750ecfd73de7054d44e69008866621 Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Wed, 17 May 2023 18:59:58 +0300
Subject: [PATCH] Restore access and modification times of symlinks in copy-in
and copy-pass modes.
* src/copyin.c: Update calls to set_file_times.
(copyin_link,replace_symlink_placeholders): Call set_file_times if needed.
* src/copyout.c: Update calls to set_file_times.
* src/copypass.c (process_copy_pass): Update calls to set_file_times.
Call set_file_times to restore times of extracted symlinks.
* src/extern.h (set_file_times): Take additional argument.
* src/util.c
(set_file_times): Take additional argument. Use fdutimensat to do the
job.
* tests/linktime.at: New file.
* tests/linktime01.at: New file.
* tests/Makefile.am: Add new files.
* tests/testsuite.at: Include new tests.
---
src/copyin.c | 24 ++++++++++++-----
src/copyout.c | 4 +--
src/copypass.c | 11 ++++++--
src/extern.h | 2 +-
src/util.c | 7 ++---
tests/Makefile.am | 4 ++-
tests/linktime.at | 63 +++++++++++++++++++++++++++++++++++++++++++++
tests/linktime01.at | 51 ++++++++++++++++++++++++++++++++++++
tests/testsuite.at | 3 +++
11 files changed, 155 insertions(+), 18 deletions(-)
create mode 100644 tests/linktime.at
create mode 100644 tests/linktime01.at
diff --git a/gnu/Makefile.am b/gnu/Makefile.am
index d63397e..a208b30 100644
--- a/gnu/Makefile.am
+++ b/gnu/Makefile.am
@@ -42,6 +42,7 @@
# configmake \
# dirname \
# error \
+# fdutimensat \
# fileblocks \
# fnmatch-gnu \
# fseeko \
@@ -71,7 +72,6 @@
# strtoumax \
# timespec \
# unlocked-io \
-# utimens \
# utimensat \
# version-etc-fsf \
# xalloc \
@@ -683,6 +683,14 @@ EXTRA_DIST += dirent-private.h
## end gnulib module fdopendir
+## begin gnulib module fdutimensat
+
+libgnu_a_SOURCES += fdutimensat.c
+
+EXTRA_DIST += utimens.h
+
+## end gnulib module fdutimensat
+
## begin gnulib module fileblocks
if GL_COND_OBJ_FILEBLOCKS
@@ -863,6 +871,14 @@ libgnu_a_SOURCES += full-write.h full-write.c
## end gnulib module full-write
+## begin gnulib module futimens
+
+if GL_COND_OBJ_FUTIMENS
+libgnu_a_SOURCES += futimens.c
+endif
+
+## end gnulib module futimens
+
## begin gnulib module gen-header
# In 'sed', replace the pattern space with a "DO NOT EDIT" comment.
diff --git a/src/copyin.c b/src/copyin.c
index f2babb7..29ac764 100644
--- a/src/copyin.c
+++ b/src/copyin.c
@@ -344,7 +344,7 @@ create_defered_links_to_skipped (struct cpio_file_stat *file_hdr,
empty links that are still on the deferments list. */
static void
-create_final_defers ()
+create_final_defers (void)
{
struct deferment *d;
int link_res;
@@ -619,7 +619,7 @@ copyin_device (struct cpio_file_stat* file_hdr)
chmod_error_details (file_hdr->c_name, file_hdr->c_mode);
if (retain_time_flag)
set_file_times (-1, file_hdr->c_name, file_hdr->c_mtime,
- file_hdr->c_mtime);
+ file_hdr->c_mtime, 0);
}
struct delayed_link
@@ -737,12 +737,18 @@ replace_symlink_placeholders (void)
}
if (res < 0)
symlink_error (dl->source, dl->target);
- else if (!no_chown_flag)
+ else
{
- uid_t uid = set_owner_flag ? set_owner : dl->uid;
- gid_t gid = set_group_flag ? set_group : dl->gid;
- if (lchown (dl->target, uid, gid) < 0 && errno != EPERM)
- chown_error_details (dl->target, uid, gid);
+ if (!no_chown_flag)
+ {
+ uid_t uid = set_owner_flag ? set_owner : dl->uid;
+ gid_t gid = set_group_flag ? set_group : dl->gid;
+ if (lchown (dl->target, uid, gid) < 0 && errno != EPERM)
+ chown_error_details (dl->target, uid, gid);
+ }
+ if (retain_time_flag)
+ set_file_times (-1, dl->target, dl->mtime, dl->mtime,
+ AT_SYMLINK_NOFOLLOW);
}
}
}
@@ -797,6 +803,10 @@ copyin_link (struct cpio_file_stat *file_hdr, int in_file_des)
if (lchown (file_hdr->c_name, uid, gid) < 0 && errno != EPERM)
chown_error_details (file_hdr->c_name, uid, gid);
}
+
+ if (retain_time_flag)
+ set_file_times (-1, file_hdr->c_name, file_hdr->c_mtime,
+ file_hdr->c_mtime, AT_SYMLINK_NOFOLLOW);
}
free (link_name);
}
diff --git a/src/copyout.c b/src/copyout.c
index 6e82f4c..8fae895 100644
--- a/src/copyout.c
+++ b/src/copyout.c
@@ -227,7 +227,7 @@ writeout_defered_file (struct cpio_file_stat *header, int out_file_des)
if (reset_time_flag)
set_file_times (in_file_des, file_hdr.c_name, file_hdr.c_mtime,
- file_hdr.c_mtime);
+ file_hdr.c_mtime, 0);
if (close (in_file_des) < 0)
close_error (header->c_name);
}
@@ -725,7 +725,7 @@ process_copy_out (void)
if (reset_time_flag)
set_file_times (in_file_des,
orig_file_name,
- file_stat.st_atime, file_stat.st_mtime);
+ file_stat.st_atime, file_stat.st_mtime, 0);
if (close (in_file_des) < 0)
close_error (orig_file_name);
break;
diff --git a/src/copypass.c b/src/copypass.c
index a8280ae..09ffebb 100644
--- a/src/copypass.c
+++ b/src/copypass.c
@@ -193,11 +193,13 @@ process_copy_pass (void)
set_file_times (in_file_des,
input_name.ds_string,
in_file_stat.st_atime,
- in_file_stat.st_mtime);
+ in_file_stat.st_mtime,
+ 0);
set_file_times (out_file_des,
output_name.ds_string,
in_file_stat.st_atime,
- in_file_stat.st_mtime);
+ in_file_stat.st_mtime,
+ 0);
}
if (close (in_file_des) < 0)
@@ -300,6 +302,11 @@ process_copy_pass (void)
&& errno != EPERM)
chown_error_details (output_name.ds_string, uid, gid);
}
+
+ if (retain_time_flag)
+ set_file_times (-1, output_name.ds_string,
+ in_file_stat.st_atime, in_file_stat.st_mtime,
+ AT_SYMLINK_NOFOLLOW);
free (link_name);
}
#endif
diff --git a/src/extern.h b/src/extern.h
index 6afbdd2..d7c31b4 100644
--- a/src/extern.h
+++ b/src/extern.h
@@ -204,7 +204,7 @@ void write_nuls_to_file (off_t num_bytes, int out_des,
void set_perms (int fd, struct cpio_file_stat *header);
void set_file_times (int fd, const char *name, unsigned long atime,
- unsigned long mtime);
+ unsigned long mtime, int atflag);
void stat_to_cpio (struct cpio_file_stat *hdr, struct stat *st);
void cpio_to_stat (struct stat *st, struct cpio_file_stat *hdr);
void cpio_safer_name_suffix (char *name, bool link_target,
diff --git a/src/util.c b/src/util.c
index 7415e10..bc1ffb8 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1235,12 +1235,13 @@ set_perms (int fd, struct cpio_file_stat *header)
if (fchmod_or_chmod (fd, header->c_name, header->c_mode) < 0)
chmod_error_details (header->c_name, header->c_mode);
if (retain_time_flag)
- set_file_times (fd, header->c_name, header->c_mtime, header->c_mtime);
+ set_file_times (fd, header->c_name, header->c_mtime, header->c_mtime, 0);
}
void
set_file_times (int fd,
- const char *name, unsigned long atime, unsigned long mtime)
+ const char *name, unsigned long atime, unsigned long mtime,
+ int atflag)
{
struct timespec ts[2];
@@ -1251,7 +1252,7 @@ set_file_times (int fd,
/* Silently ignore EROFS because reading the file won't have upset its
timestamp if it's on a read-only filesystem. */
- if (fdutimens (fd, name, ts) < 0 && errno != EROFS)
+ if (fdutimensat (fd, AT_FDCWD, name, ts, atflag) < 0 && errno != EROFS)
utime_error (name);
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 52503c9..28e259e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -57,7 +57,9 @@ TESTSUITE_AT = \
version.at\
big-block-size.at\
CVE-2015-1197.at\
- CVE-2019-14866.at
+ CVE-2019-14866.at\
+ linktime.at\
+ linktime01.at
TESTSUITE = $(srcdir)/testsuite
diff --git a/tests/testsuite.at b/tests/testsuite.at
index c58cbb7..4dd2afc 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -45,3 +45,6 @@ m4_include([big-block-size.at])
m4_include([CVE-2015-1197.at])
m4_include([CVE-2019-14866.at])
+
+m4_include([linktime.at])
+m4_include([linktime01.at])
diff --git a/m4/futimens.m4 b/m4/futimens.m4
new file mode 100644
index 0000000..dc0b21b
--- /dev/null
+++ b/m4/futimens.m4
@@ -0,0 +1,69 @@
+# serial 11
+# See if we need to provide futimens replacement.
+
+dnl Copyright (C) 2009-2023 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# Written by Eric Blake.
+
+AC_DEFUN([gl_FUNC_FUTIMENS],
+[
+ AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+ gl_CHECK_FUNCS_ANDROID([futimens], [[#include <sys/stat.h>]])
+ if test $ac_cv_func_futimens = no; then
+ HAVE_FUTIMENS=0
+ case "$gl_cv_onwards_func_futimens" in
+ future*) REPLACE_FUTIMENS=1 ;;
+ esac
+ else
+ AC_CACHE_CHECK([whether futimens works],
+ [gl_cv_func_futimens_works],
+ [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+]GL_MDA_DEFINES],
+ [[struct timespec ts[2];
+ int fd = creat ("conftest.file", 0600);
+ struct stat st;
+ if (fd < 0) return 1;
+ ts[0].tv_sec = 1;
+ ts[0].tv_nsec = UTIME_OMIT;
+ ts[1].tv_sec = 1;
+ ts[1].tv_nsec = UTIME_NOW;
+ errno = 0;
+ if (futimens (AT_FDCWD, NULL) == 0) return 2;
+ if (errno != EBADF) return 3;
+ if (futimens (fd, ts)) return 4;
+ sleep (1);
+ ts[0].tv_nsec = UTIME_NOW;
+ ts[1].tv_nsec = UTIME_OMIT;
+ if (futimens (fd, ts)) return 5;
+ if (fstat (fd, &st)) return 6;
+ if (st.st_ctime < st.st_atime) return 7;
+ ]])],
+ [gl_cv_func_futimens_works=yes],
+ [gl_cv_func_futimens_works=no],
+ [case "$host_os" in
+ # Guess no on glibc systems.
+ *-gnu* | gnu*) gl_cv_func_futimens_works="guessing no" ;;
+ # Guess no on musl systems.
+ *-musl*) gl_cv_func_futimens_works="guessing no" ;;
+ # Guess yes otherwise.
+ *) gl_cv_func_futimens_works="guessing yes" ;;
+ esac
+ ])
+ rm -f conftest.file])
+ case "$gl_cv_func_futimens_works" in
+ *yes) ;;
+ *)
+ REPLACE_FUTIMENS=1
+ ;;
+ esac
+ fi
+])
diff --git a/tests/linktime.at b/tests/linktime.at
new file mode 100644
index 0000000..bcee241
--- /dev/null
+++ b/tests/linktime.at
@@ -0,0 +1,63 @@
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
+# Copyright (C) 2023 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+
+# 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, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([restoring symlink times])
+AT_KEYWORDS([linktime copyin copypass])
+
+AT_DATA([filelist],[file
+symlink
+])
+
+AT_DATA([filelist_rev],[symlink
+file
+])
+
+AT_CHECK(
+[mkdir dir
+cd dir
+genfile --file file
+ln -s file symlink || AT_SKIP_TEST
+genfile -th --date '2 days ago' symlink || AT_SKIP_TEST
+cd ..
+])
+
+AT_CHECK(
+[time_orig=$(genfile -h -Smtime dir/symlink)
+rm -f file symlink
+cpio -D dir --quiet -o < filelist > arc.cpio
+cpio -m --quiet -i < arc.cpio
+time=$(genfile -h -Smtime symlink)
+test "$time" -eq "$time_orig"
+])
+
+AT_CHECK(
+[time_orig=$(genfile -h -Smtime dir/symlink)
+rm -f file symlink
+cpio -D dir --quiet -o < filelist_rev > arc.cpio
+cpio -m --quiet -i < arc.cpio
+time=$(genfile -h -Smtime symlink)
+test "$time" -eq "$time_orig"
+])
+
+AT_CHECK(
+[time_orig=$(genfile -h -Smtime dir/symlink)
+rm -f file symlink
+cpio -D dir -m --quiet -p . < filelist
+time=$(genfile -h -Smtime symlink)
+test "$time" -eq "$time_orig"
+])
+
+AT_CLEANUP
diff --git a/tests/linktime01.at b/tests/linktime01.at
new file mode 100644
index 0000000..9caa58f
--- /dev/null
+++ b/tests/linktime01.at
@@ -0,0 +1,51 @@
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
+# Copyright (C) 2023 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+
+# 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, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([restoring delayed symlink times])
+AT_KEYWORDS([linktime copyin])
+
+AT_CHECK(
+[mkdir dir
+genfile --file dir/file1
+ln -s dir dirlink || AT_SKIP_TEST
+genfile -th --date '2 days ago' dirlink || AT_SKIP_TEST
+])
+
+AT_DATA([filelist],
+[dir
+dir/file1
+dirlink
+])
+
+AT_CHECK(
+[time_orig=$(genfile -h -Smtime dirlink)
+cpio --quiet -o < filelist > arc.cpio
+mkdir extr
+cpio -D extr --quiet --no-absolute-filenames -m -i < arc.cpio
+find extr | sort
+time=$(genfile -h -Smtime extr/dirlink)
+test "$time" -eq "$time_orig"
+],
+[0],
+[extr
+extr/dir
+extr/dir/file1
+extr/dirlink
+])
+
+AT_CLEANUP
+
+
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4
index ad10592..fa0c93e 100644
--- a/m4/gnulib-comp.m4
+++ b/m4/gnulib-comp.m4
@@ -98,6 +98,7 @@ AC_DEFUN([gl_EARLY],
# Code from module fd-hook:
# Code from module fd-safer-flag:
# Code from module fdopendir:
+ # Code from module fdutimensat:
# Code from module fileblocks:
# Code from module filename:
# Code from module filenamecat-lgpl:
@@ -114,6 +115,7 @@ AC_DEFUN([gl_EARLY],
# Code from module fstat:
# Code from module fstatat:
# Code from module full-write:
+ # Code from module futimens:
# Code from module gen-header:
# Code from module getcwd:
# Code from module getcwd-lgpl:
@@ -411,6 +413,7 @@ AC_DEFUN([gl_INIT],
[test $HAVE_FDOPENDIR = 0 || test $REPLACE_FDOPENDIR = 1])
gl_DIRENT_MODULE_INDICATOR([fdopendir])
gl_MODULE_INDICATOR([fdopendir])
+ gl_MODULE_INDICATOR([fdutimensat])
gl_FILEBLOCKS
gl_CONDITIONAL([GL_COND_OBJ_FILEBLOCKS],
[test $ac_cv_member_struct_stat_st_blocks = no])
@@ -475,6 +478,10 @@ AC_DEFUN([gl_INIT],
gl_CONDITIONAL([GL_COND_OBJ_FSTATAT],
[test $HAVE_FSTATAT = 0 || test $REPLACE_FSTATAT = 1])
gl_SYS_STAT_MODULE_INDICATOR([fstatat])
+ gl_FUNC_FUTIMENS
+ gl_CONDITIONAL([GL_COND_OBJ_FUTIMENS],
+ [test $HAVE_FUTIMENS = 0 || test $REPLACE_FUTIMENS = 1])
+ gl_SYS_STAT_MODULE_INDICATOR([futimens])
gl_FUNC_GETCWD
gl_CONDITIONAL([GL_COND_OBJ_GETCWD], [test $REPLACE_GETCWD = 1])
AM_COND_IF([GL_COND_OBJ_GETCWD], [
@@ -1278,6 +1285,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/fd-safer-flag.c
lib/fd-safer.c
lib/fdopendir.c
+ lib/fdutimensat.c
lib/fileblocks.c
lib/filename.h
lib/filenamecat-lgpl.c
@@ -1298,6 +1306,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/fstatat.c
lib/full-write.c
lib/full-write.h
+ lib/futimens.c
lib/getcwd-lgpl.c
lib/getcwd.c
lib/getdelim.c
@@ -1556,6 +1565,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/fseeko.m4
m4/fstat.m4
m4/fstatat.m4
+ m4/futimens.m4
m4/getcwd-abort-bug.m4
m4/getcwd-path-max.m4
m4/getcwd.m4
diff --git a/aclocal.m4 b/aclocal.m4
index ce55bc1..d5bd65f 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1241,6 +1241,7 @@ m4_include([m4/fseek.m4])
m4_include([m4/fseeko.m4])
m4_include([m4/fstat.m4])
m4_include([m4/fstatat.m4])
+m4_include([m4/futimens.m4])
m4_include([m4/getcwd-abort-bug.m4])
m4_include([m4/getcwd-path-max.m4])
m4_include([m4/getcwd.m4])
diff --git a/gnu/fdutimensat.c b/gnu/fdutimensat.c
new file mode 100644
index 0000000..5b801e0
--- /dev/null
+++ b/gnu/fdutimensat.c
@@ -0,0 +1,57 @@
+/* Set file access and modification times.
+
+ Copyright (C) 2009-2023 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation, either version 3 of the License, or any
+ later version.
+
+ 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, see <https://www.gnu.org/licenses/>. */
+
+/* Written by Eric Blake. */
+
+/* derived from a function in utimens.c */
+
+#include <config.h>
+
+#include "utimens.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+/* Set the access and modification timestamps of FD (a.k.a. FILE) to be
+ TIMESPEC[0] and TIMESPEC[1], respectively; relative to directory DIR.
+ FD must be either negative -- in which case it is ignored --
+ or a file descriptor that is open on FILE.
+ If FD is nonnegative, then FILE can be NULL, which means
+ use just futimes (or equivalent) instead of utimes (or equivalent),
+ and fail if on an old system without futimes (or equivalent).
+ If TIMESPEC is null, set the timestamps to the current time.
+ ATFLAG is passed to utimensat if FD is negative or futimens was
+ unsupported, which can allow operation on FILE as a symlink.
+ Return 0 on success, -1 (setting errno) on failure. */
+
+int
+fdutimensat (int fd, int dir, char const *file, struct timespec const ts[2],
+ int atflag)
+{
+ int result = 1;
+ if (0 <= fd)
+ result = futimens (fd, ts);
+ if (file && (fd < 0 || (result == -1 && errno == ENOSYS)))
+ result = utimensat (dir, file, ts, atflag);
+ if (result == 1)
+ {
+ errno = EBADF;
+ result = -1;
+ }
+ return result;
+}
diff --git a/gnu/futimens.c b/gnu/futimens.c
new file mode 100644
index 0000000..5bb3049
--- /dev/null
+++ b/gnu/futimens.c
@@ -0,0 +1,37 @@
+/* Set the access and modification time of an open fd.
+ Copyright (C) 2009-2023 Free Software Foundation, Inc.
+
+ This file is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This file 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 Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+/* written by Eric Blake */
+
+#include <config.h>
+
+#include <sys/stat.h>
+
+#include "utimens.h"
+
+/* Set the access and modification timestamps of FD to be
+ TIMESPEC[0] and TIMESPEC[1], respectively.
+ Fail with ENOSYS on systems without futimes (or equivalent).
+ If TIMESPEC is null, set the timestamps to the current time.
+ Return 0 on success, -1 (setting errno) on failure. */
+int
+futimens (int fd, struct timespec const times[2])
+{
+ /* fdutimens also works around bugs in native futimens, when running
+ with glibc compiled against newer headers but on a Linux kernel
+ older than 2.6.32. */
+ return fdutimens (fd, NULL, times);
+}
diff --git a/tests/genfile.c b/tests/genfile.c
index be4a2d3..0074c5c 100644
--- a/tests/genfile.c
+++ b/tests/genfile.c
@@ -77,7 +77,8 @@ enum genfile_mode
mode_generate,
mode_sparse,
mode_stat,
- mode_exec
+ mode_exec,
+ mode_set_times
};
enum genfile_mode mode = mode_generate;
@@ -106,6 +107,9 @@ int verbose;
/* Quiet mode */
int quiet;
+/* Don't dereference symlinks (for --stat) */
+int no_dereference_option;
+
const char *argp_program_version = "genfile (" PACKAGE ") " VERSION;
const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">";
static char doc[] = N_("genfile manipulates data files for GNU paxutils test suite.\n"
@@ -155,6 +159,14 @@ static struct argp_option options[] = {
N_("Print contents of struct stat for each given file. Default FORMAT is: ")
DEFAULT_STAT_FORMAT,
GRP+1 },
+ {"no-dereference", 'h', NULL, 0,
+ N_("stat symbolic links instead of referenced files"),
+ GRP+1 },
+
+ {"set-times", 't', NULL, 0,
+ N_("Set access and modification times of the files to the time supplied"
+ " by --date option"),
+ GRP+1 },
#undef GRP
#define GRP 20
@@ -348,6 +360,14 @@ parse_opt (int key, char *arg, struct argp_state *state)
stat_format = arg;
break;
+ case 't':
+ mode = mode_set_times;
+ break;
+
+ case 'h':
+ no_dereference_option = 1;
+ break;
+
case 'r':
mode = mode_exec;
checkpoint_granularity = arg ? arg : "1";
@@ -647,7 +667,7 @@ print_stat (const char *name)
char *fmt, *p;
struct stat st;
- if (stat (name, &st))
+ if ((no_dereference_option ? lstat : stat) (name, &st))
{
error (0, errno, _("stat(%s) failed"), name);
return;
@@ -725,6 +745,17 @@ print_stat (const char *name)
free (fmt);
}
+void
+set_times (char const *name)
+{
+ struct timespec ts[2];
+
+ ts[0] = ts[1] = touch_time;
+ if (utimensat (AT_FDCWD, name, ts, no_dereference_option ? AT_SYMLINK_NOFOLLOW : 0) != 0)
+ {
+ error (EXIT_FAILURE, errno, _("cannot set time on `%s'"), name);
+ }
+}
/* Exec Mode */
@@ -740,7 +771,7 @@ exec_checkpoint (struct action *p)
struct timespec ts[2];
ts[0] = ts[1] = p->ts;
- if (utimensat (AT_FDCWD, p->name, ts, 0) != 0)
+ if (utimensat (AT_FDCWD, p->name, ts, no_dereference_option ? AT_SYMLINK_NOFOLLOW : 0) != 0)
{
error (0, errno, _("cannot set time on `%s'"), p->name);
break;
@@ -987,6 +1018,14 @@ main (int argc, char **argv)
print_stat (*argv++);
break;
+ case mode_set_times:
+ if (argc == 0)
+ error (EXIT_USAGE, 0, _("--set-times requires file names"));
+
+ while (argc--)
+ set_times (*argv++);
+ break;
+
case mode_sparse:
generate_sparse_file (argc, argv);
verify_file (file_name);
diff --git a/tests/testsuite b/tests/testsuite
index 10531d1..442ab00 100755
--- a/tests/testsuite
+++ b/tests/testsuite
@@ -625,6 +625,8 @@ at_help_all="1;version.at:19;cpio version;;
13;big-block-size.at:17;big block size;block integer overflow;
14;CVE-2015-1197.at:17;CVE-2015-1197 (--no-absolute-filenames for symlinks);;
15;CVE-2019-14866.at:17;CVE-2019-14866 (tar header size overflow);;
+16;linktime.at:17;restoring symlink times;linktime copyin copypass;
+17;linktime01.at:17;restoring delayed symlink times;linktime copyin;
"
# List of the all the test groups.
at_groups_all=`printf "%s\n" "$at_help_all" | sed 's/;.*//'`
@@ -638,7 +640,7 @@ at_fn_validate_ranges ()
for at_grp
do
eval at_value=\$$at_grp
- if test $at_value -lt 1 || test $at_value -gt 15; then
+ if test $at_value -lt 1 || test $at_value -gt 17; then
printf "%s\n" "invalid test group: $at_value" >&2
exit 1
fi
@@ -2940,3 +2942,209 @@ $at_traceon; }
) 5>&1 2>&1 7>&- | eval $at_tee_pipe
read at_status <"$at_status_file"
#AT_STOP_15
+#AT_START_16
+at_fn_group_banner 16 'linktime.at:17' \
+ "restoring symlink times" " "
+at_xfail=no
+(
+ printf "%s\n" "16. $at_setup_line: testing $at_desc ..."
+ $at_traceon
+
+
+
+cat >filelist <<'_ATEOF'
+file
+symlink
+_ATEOF
+
+
+cat >filelist_rev <<'_ATEOF'
+symlink
+file
+_ATEOF
+
+
+{ set +x
+printf "%s\n" "$at_srcdir/linktime.at:28: mkdir dir
+cd dir
+genfile --file file
+ln -s file symlink || exit 77
+genfile -th --date '2 days ago' symlink || exit 77
+cd ..
+"
+at_fn_check_prepare_notrace 'an embedded newline' "linktime.at:28"
+( $at_check_trace; mkdir dir
+cd dir
+genfile --file file
+ln -s file symlink || exit 77
+genfile -th --date '2 days ago' symlink || exit 77
+cd ..
+
+) >>"$at_stdout" 2>>"$at_stderr" 5>&-
+at_status=$? at_failed=false
+$at_check_filter
+at_fn_diff_devnull "$at_stderr" || at_failed=:
+at_fn_diff_devnull "$at_stdout" || at_failed=:
+at_fn_check_status 0 $at_status "$at_srcdir/linktime.at:28"
+$at_failed && at_fn_log_failure
+$at_traceon; }
+
+
+{ set +x
+printf "%s\n" "$at_srcdir/linktime.at:37: time_orig=\$(genfile -h -Smtime dir/symlink)
+rm -f file symlink
+cpio -D dir --quiet -o < filelist > arc.cpio
+cpio -m --quiet -i < arc.cpio
+time=\$(genfile -h -Smtime symlink)
+test \"\$time\" -eq \"\$time_orig\"
+"
+at_fn_check_prepare_notrace 'a $(...) command substitution' "linktime.at:37"
+( $at_check_trace; time_orig=$(genfile -h -Smtime dir/symlink)
+rm -f file symlink
+cpio -D dir --quiet -o < filelist > arc.cpio
+cpio -m --quiet -i < arc.cpio
+time=$(genfile -h -Smtime symlink)
+test "$time" -eq "$time_orig"
+
+) >>"$at_stdout" 2>>"$at_stderr" 5>&-
+at_status=$? at_failed=false
+$at_check_filter
+at_fn_diff_devnull "$at_stderr" || at_failed=:
+at_fn_diff_devnull "$at_stdout" || at_failed=:
+at_fn_check_status 0 $at_status "$at_srcdir/linktime.at:37"
+$at_failed && at_fn_log_failure
+$at_traceon; }
+
+
+{ set +x
+printf "%s\n" "$at_srcdir/linktime.at:46: time_orig=\$(genfile -h -Smtime dir/symlink)
+rm -f file symlink
+cpio -D dir --quiet -o < filelist_rev > arc.cpio
+cpio -m --quiet -i < arc.cpio
+time=\$(genfile -h -Smtime symlink)
+test \"\$time\" -eq \"\$time_orig\"
+"
+at_fn_check_prepare_notrace 'a $(...) command substitution' "linktime.at:46"
+( $at_check_trace; time_orig=$(genfile -h -Smtime dir/symlink)
+rm -f file symlink
+cpio -D dir --quiet -o < filelist_rev > arc.cpio
+cpio -m --quiet -i < arc.cpio
+time=$(genfile -h -Smtime symlink)
+test "$time" -eq "$time_orig"
+
+) >>"$at_stdout" 2>>"$at_stderr" 5>&-
+at_status=$? at_failed=false
+$at_check_filter
+at_fn_diff_devnull "$at_stderr" || at_failed=:
+at_fn_diff_devnull "$at_stdout" || at_failed=:
+at_fn_check_status 0 $at_status "$at_srcdir/linktime.at:46"
+$at_failed && at_fn_log_failure
+$at_traceon; }
+
+
+{ set +x
+printf "%s\n" "$at_srcdir/linktime.at:55: time_orig=\$(genfile -h -Smtime dir/symlink)
+rm -f file symlink
+cpio -D dir -m --quiet -p . < filelist
+time=\$(genfile -h -Smtime symlink)
+test \"\$time\" -eq \"\$time_orig\"
+"
+at_fn_check_prepare_notrace 'a $(...) command substitution' "linktime.at:55"
+( $at_check_trace; time_orig=$(genfile -h -Smtime dir/symlink)
+rm -f file symlink
+cpio -D dir -m --quiet -p . < filelist
+time=$(genfile -h -Smtime symlink)
+test "$time" -eq "$time_orig"
+
+) >>"$at_stdout" 2>>"$at_stderr" 5>&-
+at_status=$? at_failed=false
+$at_check_filter
+at_fn_diff_devnull "$at_stderr" || at_failed=:
+at_fn_diff_devnull "$at_stdout" || at_failed=:
+at_fn_check_status 0 $at_status "$at_srcdir/linktime.at:55"
+$at_failed && at_fn_log_failure
+$at_traceon; }
+
+
+ set +x
+ $at_times_p && times >"$at_times_file"
+) 5>&1 2>&1 7>&- | eval $at_tee_pipe
+read at_status <"$at_status_file"
+#AT_STOP_16
+#AT_START_17
+at_fn_group_banner 17 'linktime01.at:17' \
+ "restoring delayed symlink times" " "
+at_xfail=no
+(
+ printf "%s\n" "17. $at_setup_line: testing $at_desc ..."
+ $at_traceon
+
+
+
+{ set +x
+printf "%s\n" "$at_srcdir/linktime01.at:20: mkdir dir
+genfile --file dir/file1
+ln -s dir dirlink || exit 77
+genfile -th --date '2 days ago' dirlink || exit 77
+"
+at_fn_check_prepare_notrace 'an embedded newline' "linktime01.at:20"
+( $at_check_trace; mkdir dir
+genfile --file dir/file1
+ln -s dir dirlink || exit 77
+genfile -th --date '2 days ago' dirlink || exit 77
+
+) >>"$at_stdout" 2>>"$at_stderr" 5>&-
+at_status=$? at_failed=false
+$at_check_filter
+at_fn_diff_devnull "$at_stderr" || at_failed=:
+at_fn_diff_devnull "$at_stdout" || at_failed=:
+at_fn_check_status 0 $at_status "$at_srcdir/linktime01.at:20"
+$at_failed && at_fn_log_failure
+$at_traceon; }
+
+
+cat >filelist <<'_ATEOF'
+dir
+dir/file1
+dirlink
+_ATEOF
+
+
+{ set +x
+printf "%s\n" "$at_srcdir/linktime01.at:33: time_orig=\$(genfile -h -Smtime dirlink)
+cpio --quiet -o < filelist > arc.cpio
+mkdir extr
+cpio -D extr --quiet --no-absolute-filenames -m -i < arc.cpio
+find extr | sort
+time=\$(genfile -h -Smtime extr/dirlink)
+test \"\$time\" -eq \"\$time_orig\"
+"
+at_fn_check_prepare_notrace 'a $(...) command substitution' "linktime01.at:33"
+( $at_check_trace; time_orig=$(genfile -h -Smtime dirlink)
+cpio --quiet -o < filelist > arc.cpio
+mkdir extr
+cpio -D extr --quiet --no-absolute-filenames -m -i < arc.cpio
+find extr | sort
+time=$(genfile -h -Smtime extr/dirlink)
+test "$time" -eq "$time_orig"
+
+) >>"$at_stdout" 2>>"$at_stderr" 5>&-
+at_status=$? at_failed=false
+$at_check_filter
+at_fn_diff_devnull "$at_stderr" || at_failed=:
+echo >>"$at_stdout"; printf "%s\n" "extr
+extr/dir
+extr/dir/file1
+extr/dirlink
+" | \
+ $at_diff - "$at_stdout" || at_failed=:
+at_fn_check_status 0 $at_status "$at_srcdir/linktime01.at:33"
+$at_failed && at_fn_log_failure
+$at_traceon; }
+
+
+ set +x
+ $at_times_p && times >"$at_times_file"
+) 5>&1 2>&1 7>&- | eval $at_tee_pipe
+read at_status <"$at_status_file"
+#AT_STOP_17

View File

@ -4,43 +4,34 @@ Subject: [PATCH 5/7] fix segfault with nonexisting file with patternnames
(#567022)
diff --git a/src/copyin.c b/src/copyin.c
index 12bd27c..183b5b5 100644
index 5d88a23..f2babb7 100644
--- a/src/copyin.c
+++ b/src/copyin.c
@@ -870,21 +870,24 @@ read_pattern_file ()
@@ -948,21 +948,24 @@ read_pattern_file (void)
pattern_fp = fopen (pattern_file_name, "r");
if (pattern_fp == NULL)
- open_fatal (pattern_file_name);
- while (ds_fgetstr (pattern_fp, &pattern_name, '\n') != NULL)
- {
- if (new_num_patterns >= max_new_patterns)
- {
- max_new_patterns += 1;
- new_save_patterns = (char **)
- xrealloc ((char *) new_save_patterns,
- max_new_patterns * sizeof (char *));
- }
- new_save_patterns[new_num_patterns] = xstrdup (pattern_name.ds_string);
- ++new_num_patterns;
- }
- if (ferror (pattern_fp) || fclose (pattern_fp) == EOF)
- close_error (pattern_file_name);
+ open_error (pattern_file_name);
+ else
+ {
+ while (ds_fgetstr (pattern_fp, &pattern_name, '\n') != NULL)
+ {
+ if (new_num_patterns >= max_new_patterns)
+ {
+ max_new_patterns += 1;
+ new_save_patterns = (char **)
+ xrealloc ((char *) new_save_patterns,
+ max_new_patterns * sizeof (char *));
+ }
+ new_save_patterns[new_num_patterns] = xstrdup (pattern_name.ds_string);
+ ++new_num_patterns;
+ }
{
if (new_num_patterns == max_new_patterns)
- new_save_patterns = x2nrealloc (new_save_patterns,
+ new_save_patterns = x2nrealloc (new_save_patterns,
&max_new_patterns,
sizeof (new_save_patterns[0]));
new_save_patterns[new_num_patterns] = xstrdup (pattern_name.ds_string);
++new_num_patterns;
}
- ds_free (&pattern_name);
+ ds_free (&pattern_name);
- if (ferror (pattern_fp) || fclose (pattern_fp) == EOF)
- close_error (pattern_file_name);
+ if (ferror (pattern_fp) || fclose (pattern_fp) == EOF)
+ close_error (pattern_file_name);
+ }

View File

@ -3,10 +3,10 @@ Date: Mon, 14 Sep 2015 09:37:15 +0200
Subject: [PATCH 3/7] Support major/minor device numbers over 127 (bz#450109)
diff --git a/src/copyin.c b/src/copyin.c
index b29f348..1142d6a 100644
index 2e72356..5d88a23 100644
--- a/src/copyin.c
+++ b/src/copyin.c
@@ -1123,15 +1123,15 @@ read_in_binary (struct cpio_file_stat *file_hdr,
@@ -1287,15 +1287,15 @@ read_in_binary (struct cpio_file_stat *file_hdr,
swab_array ((char *) short_hdr, 13);
}
@ -24,5 +24,5 @@ index b29f348..1142d6a 100644
+ file_hdr->c_rdev_maj = major ((unsigned short)short_hdr->c_rdev);
+ file_hdr->c_rdev_min = minor ((unsigned short)short_hdr->c_rdev);
file_hdr->c_mtime = (unsigned long) short_hdr->c_mtimes[0] << 16
| short_hdr->c_mtimes[1];
| short_hdr->c_mtimes[1];
file_hdr->c_filesize = (unsigned long) short_hdr->c_filesizes[0] << 16

View File

@ -32,7 +32,7 @@ index b45c731..fd8454d 100755
@@ -2885,7 +2885,6 @@ fi
at_status=$? at_failed=false
$at_check_filter
echo >>"$at_stderr"; $as_echo "cpio: file: value size 17179869184 out of allowed range 0..8589934591
echo >>"$at_stderr"; printf "%s\n" "cpio: file: value size 17179869184 out of allowed range 0..8589934591
-2 blocks
" | \
$at_diff - "$at_stderr" || at_failed=:

Binary file not shown.

BIN
cpio-2.14.tar.bz2 Normal file

Binary file not shown.

View File

@ -56,7 +56,7 @@ index a13861f..a875a13 100644
{NULL, 'c', NULL, 0,
- N_("Use the old portable (ASCII) archive format"), GRID+1 },
+ N_("Identical to \"-H newc\", use the new (SVR4) portable format. If you wish the old portable (ASCII) archive format, use \"-H odc\" instead."), GRID+1 },
{"dot", 'V', NULL, 0,
{"dot", 'V', NULL, 0,
N_("Print a \".\" for each file processed"), GRID+1 },
{"io-size", 'C', N_("NUMBER"), 0,
@@ -329,6 +329,7 @@ parse_opt (int key, char *arg, struct argp_state *state)

View File

@ -1,6 +1,6 @@
Name: cpio
Version: 2.13
Release: 7
Version: 2.14
Release: 3
Summary: A GNU archiving program
License: GPLv3+
@ -14,11 +14,9 @@ Patch3: cpio-2.9.90-defaultremoteshell.patch
Patch4: cpio-2.10-patternnamesigsegv.patch
Patch5: cpio-2.10-longnames-split.patch
Patch6: cpio-2.11-crc-fips-nit.patch
Patch7: revert-CVE-2015-1197.patch
Patch8: backport-cpio-2.13-mutiple-definition.patch
Patch9: backport-0001-CVE-2021-38185-Rewrite-dynamic-string-support.patch
Patch10: backport-0002-CVE-2021-38185-Fix-previous-commit.patch
Patch11: backport-0003-CVE-2021-38185-Fix-dynamic-string-reallocations.patch
Patch7: backport-restore-access-and-modification-times-of-symlinks.patch
Patch8: backport-fix-operation-of-no-absolute-filenames-make-director.patch
Patch9: backport-Do-not-set-exit-code-to-2-when-failing-to-create-symlink.patch
Patch9000: add-option-to-add-metadata-in-copy-out-mode.patch
Patch9001: Fix-use-after-free-and-return-appropriate-error.patch
@ -64,6 +62,36 @@ make check
%{_datadir}/man/man1/%{name}.1.gz
%changelog
* Mon Aug 21 2023 fuanan <fuanan3@h-partners.com> - 2.14-3
- Type:CVE
- ID:CVE-2015-1197
- SUG:NA
- DESC:Fix CVE-2015-1197
* Wed Jul 26 2023 zhangruifang <zhangruifang1@h-partners.com> - 2.14-2
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:revert CVE-2015-1197 fix for --no-absolute-filenames
* Mon Jul 17 2023 zhangruifang <zhangruifang1@h-partners.com> - 2.14-1
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:update to 2.14
* Tue Jun 20 2023 fuanan <fuanan3@h-partners.com> - 2.13-9
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:revert fix CVE-2015-1197 because it causes AT testcases problems
* Sat May 27 2023 fuanan <fuanan3@h-partners.com> - 2.13-8
- Type:CVE
- ID:CVE-2015-1197
- SUG:NA
- DESC:Fix CVE-2015-1197
* Thu Oct 27 2022 dongyuzhen <dongyuzhen@h-partners.com> - 2.13-7
- Type:bugfix
- ID:NA

View File

@ -1,109 +0,0 @@
From 250cae97153b438f5644e5d96814a7f5cb8c80e5 Mon Sep 17 00:00:00 2001
From: Liquor <lirui130@huawei.com>
Date: Thu, 26 Nov 2020 19:13:13 +0800
Subject: [PATCH] revert "CVE-2015-1197"
reason:https://lists.gnu.org/archive/html/bug-cpio/2019-11/msg00016.html
---
src/copyin.c | 5 ++---
tests/CVE-2015-1197.at | 43 ------------------------------------------
tests/Makefile.am | 1 -
tests/testsuite.at | 1 -
4 files changed, 2 insertions(+), 48 deletions(-)
delete mode 100644 tests/CVE-2015-1197.at
diff --git a/src/copyin.c b/src/copyin.c
index de31636..bf3b0a8 100644
--- a/src/copyin.c
+++ b/src/copyin.c
@@ -645,14 +645,13 @@ copyin_link (struct cpio_file_stat *file_hdr, int in_file_des)
link_name = xstrdup (file_hdr->c_tar_linkname);
}
- cpio_safer_name_suffix (link_name, true, !no_abs_paths_flag, false);
-
res = UMASKED_SYMLINK (link_name, file_hdr->c_name,
file_hdr->c_mode);
if (res < 0 && create_dir_flag)
{
create_all_directories (file_hdr->c_name);
- res = UMASKED_SYMLINK (link_name, file_hdr->c_name, file_hdr->c_mode);
+ res = UMASKED_SYMLINK (link_name, file_hdr->c_name,
+ file_hdr->c_mode);
}
if (res < 0)
{
diff --git a/tests/CVE-2015-1197.at b/tests/CVE-2015-1197.at
deleted file mode 100644
index 6079af7..0000000
--- a/tests/CVE-2015-1197.at
+++ /dev/null
@@ -1,43 +0,0 @@
-# Process this file with autom4te to create testsuite. -*- Autotest -*-
-# Copyright (C) 2009-2019 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3, or (at your option)
-# any later version.
-#
-# 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, see <http://www.gnu.org/licenses/>.
-
-AT_SETUP([CVE-2015-1197 (--no-absolute-filenames for symlinks)])
-AT_CHECK([
-tempdir=$(pwd)/tmp
-mkdir $tempdir
-touch $tempdir/file
-ln -s $tempdir dir
-AT_DATA([filelist],
-[dir
-dir/file
-])
-ln -s /tmp dir
-touch /tmp/file
-cpio -o < filelist > test.cpio
-rm dir /tmp/file
-cpio --no-absolute-filenames -iv < test.cpio
-],
-[2],
-[],
-[1 block
-cpio: Removing leading `/' from hard link targets
-dir
-cpio: dir/file: Cannot open: No such file or directory
-dir/file
-1 block
-])
-AT_CLEANUP
-
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 65bf470..a71c057 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -56,7 +56,6 @@ TESTSUITE_AT = \
symlink-to-stdout.at\
version.at\
big-block-size.at\
- CVE-2015-1197.at\
CVE-2019-14866.at
TESTSUITE = $(srcdir)/testsuite
diff --git a/tests/testsuite.at b/tests/testsuite.at
index aa56bb9..58ed1d2 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -44,5 +44,4 @@ m4_include([setstat04.at])
m4_include([setstat05.at])
m4_include([big-block-size.at])
-m4_include([CVE-2015-1197.at])
m4_include([CVE-2019-14866.at])
--
2.27.0