update software to version 4.7
Signed-off-by: JeanLeo <liujianliu.liu@huawei.com>
This commit is contained in:
parent
31380811a9
commit
12772dc0c9
@ -1,281 +0,0 @@
|
|||||||
diff -urN sed-4.3/sed/execute.c sed-4.3.new00/sed/execute.c
|
|
||||||
--- sed-4.3/sed/execute.c 2012-03-16 10:13:31.000000000 +0100
|
|
||||||
+++ sed-4.3.new00/sed/execute.c 2014-02-10 14:40:25.603629422 +0100
|
|
||||||
@@ -703,11 +703,13 @@
|
|
||||||
if (strcmp(in_place_extension, "*") != 0)
|
|
||||||
{
|
|
||||||
char *backup_file_name = get_backup_file_name(target_name);
|
|
||||||
- ck_rename (target_name, backup_file_name, input->out_file_name);
|
|
||||||
+ (copy_instead_of_rename?ck_fccopy:ck_rename)
|
|
||||||
+ (target_name, backup_file_name, input->out_file_name);
|
|
||||||
free (backup_file_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
- ck_rename (input->out_file_name, target_name, input->out_file_name);
|
|
||||||
+ (copy_instead_of_rename?ck_fcmove:ck_rename)
|
|
||||||
+ (input->out_file_name, target_name, input->out_file_name);
|
|
||||||
cancel_cleanup ();
|
|
||||||
free (input->out_file_name);
|
|
||||||
}
|
|
||||||
diff -urN sed-4.3/sed/sed.c sed-4.3.new00/sed/sed.c
|
|
||||||
--- sed-4.3/sed/sed.c 2012-03-16 10:13:31.000000000 +0100
|
|
||||||
+++ sed-4.3.new00/sed/sed.c 2014-02-10 17:37:19.381273509 +0100
|
|
||||||
@@ -56,6 +56,10 @@
|
|
||||||
/* How do we edit files in-place? (we don't if NULL) */
|
|
||||||
char *in_place_extension = NULL;
|
|
||||||
|
|
||||||
+ /* Do we use copy or rename when in in-place edit mode? (boolean
|
|
||||||
+ value, non-zero for copy, zero for rename).*/
|
|
||||||
+ int copy_instead_of_rename = 0;
|
|
||||||
+
|
|
||||||
/* The mode to use to read/write files, either "r"/"w" or "rb"/"wb". */
|
|
||||||
char const *read_mode = "r";
|
|
||||||
char const *write_mode = "w";
|
|
||||||
@@ -117,11 +121,16 @@
|
|
||||||
fprintf(out, _(" -i[SUFFIX], --in-place[=SUFFIX]\n\
|
|
||||||
edit files in place (makes backup if SUFFIX supplied)\n"));
|
|
||||||
-#if defined WIN32 || defined _WIN32 || defined __CYGWIN__ \
|
|
||||||
- || defined MSDOS || defined __EMX__
|
|
||||||
- fprintf(out, _(" -b, --binary\n\
|
|
||||||
- open files in binary mode (CR+LFs are not" \
|
|
||||||
- " processed specially)\n"));
|
|
||||||
+ fprintf(out, _(" -c, --copy\n\
|
|
||||||
+ use copy instead of rename when shuffling files in -i mode\n"));
|
|
||||||
+ fprintf(out, _(" -b, --binary\n"
|
|
||||||
+#if ! ( defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(MSDOS) || defined(__EMX__) )
|
|
||||||
+" does nothing; for compatibility with WIN32/CYGWIN/MSDOS/EMX (\n"
|
|
||||||
+#endif
|
|
||||||
+" open files in binary mode (CR+LFs are not treated specially)"
|
|
||||||
+#if ! ( defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(MSDOS) || defined(__EMX__) )
|
|
||||||
+ ")"
|
|
||||||
#endif
|
|
||||||
+ "\n"));
|
|
||||||
fprintf(out, _(" -l N, --line-length=N\n\
|
|
||||||
specify the desired line-wrap length for the `l' command\n"));
|
|
||||||
fprintf(out, _(" --posix\n\
|
|
||||||
@@ -138,8 +149,10 @@
|
|
||||||
the output buffers more often\n"));
|
|
||||||
fprintf(out, _(" -z, --null-data\n\
|
|
||||||
separate lines by NUL characters\n"));
|
|
||||||
- fprintf(out, _(" --help display this help and exit\n"));
|
|
||||||
- fprintf(out, _(" --version output version information and exit\n"));
|
|
||||||
+ fprintf(out, _(" --help\n\
|
|
||||||
+ display this help and exit\n"));
|
|
||||||
+ fprintf(out, _(" --version\n\
|
|
||||||
+ output version information and exit\n"));
|
|
||||||
fprintf(out, _("\n\
|
|
||||||
If no -e, --expression, -f, or --file option is given, then the first\n\
|
|
||||||
non-option argument is taken as the sed script to interpret. All\n\
|
|
||||||
@@ -158,9 +171,9 @@
|
|
||||||
main (int argc, char **argv)
|
|
||||||
{
|
|
||||||
#ifdef REG_PERL
|
|
||||||
-#define SHORTOPTS "bsnrzRuEe:f:l:i::V:"
|
|
||||||
+#define SHORTOPTS "bcsnrzRuEe:f:l:i::"
|
|
||||||
#else
|
|
||||||
-#define SHORTOPTS "bsnrzuEe:f:l:i::V:"
|
|
||||||
+#define SHORTOPTS "bcsnrzuEe:f:l:i::"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
enum { SANDBOX_OPTION = CHAR_MAX+1 };
|
|
||||||
@@ -172,6 +185,7 @@
|
|
||||||
{"expression", 1, NULL, 'e'},
|
|
||||||
{"file", 1, NULL, 'f'},
|
|
||||||
{"in-place", 2, NULL, 'i'},
|
|
||||||
+ {"copy", 0, NULL, 'c'},
|
|
||||||
{"line-length", 1, NULL, 'l'},
|
|
||||||
{"null-data", 0, NULL, 'z'},
|
|
||||||
{"zero-terminated", 0, NULL, 'z'},
|
|
||||||
@@ -246,6 +260,10 @@
|
|
||||||
follow_symlinks = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
+ case 'c':
|
|
||||||
+ copy_instead_of_rename = true;
|
|
||||||
+ break;
|
|
||||||
+
|
|
||||||
case 'i':
|
|
||||||
separate_files = true;
|
|
||||||
if (optarg == NULL)
|
|
||||||
@@ -272,9 +290,11 @@
|
|
||||||
posixicity = POSIXLY_BASIC;
|
|
||||||
break;
|
|
||||||
|
|
||||||
- case 'b':
|
|
||||||
+ case 'b':
|
|
||||||
+#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(MSDOS) || defined(__EMX__)
|
|
||||||
read_mode = "rb";
|
|
||||||
write_mode = "wb";
|
|
||||||
+#endif
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'E':
|
|
||||||
@@ -314,6 +334,12 @@
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
+ if (copy_instead_of_rename && in_place_extension == NULL)
|
|
||||||
+ {
|
|
||||||
+ fprintf (stderr, _("Error: -c used without -i.\n"));
|
|
||||||
+ usage(4);
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
if (!the_program)
|
|
||||||
{
|
|
||||||
if (optind < argc)
|
|
||||||
diff -urN sed-4.3/sed/sed.h sed-4.3.new00/sed/sed.h
|
|
||||||
--- sed-4.3/sed/sed.h 2012-07-25 12:33:09.000000000 +0200
|
|
||||||
+++ sed-4.3.new00/sed/sed.h 2014-02-10 14:40:25.602629419 +0100
|
|
||||||
@@ -230,6 +230,10 @@
|
|
||||||
/* How do we edit files in-place? (we don't if NULL) */
|
|
||||||
extern char *in_place_extension;
|
|
||||||
|
|
||||||
+/* Do we use copy or rename when in in-place edit mode? (boolean
|
|
||||||
+ value, non-zero for copy, zero for rename).*/
|
|
||||||
+extern int copy_instead_of_rename;
|
|
||||||
+
|
|
||||||
/* The mode to use to read and write files, either "rt"/"w" or "rb"/"wb". */
|
|
||||||
extern char const *read_mode;
|
|
||||||
extern char const *write_mode;
|
|
||||||
diff -urN sed-4.3/sed/utils.c sed-4.3.new00/sed/utils.c
|
|
||||||
--- sed-4.3/sed/utils.c 2012-03-16 10:13:31.000000000 +0100
|
|
||||||
+++ sed-4.3.new00/sed/utils.c 2014-02-10 14:40:25.603629422 +0100
|
|
||||||
@@ -27,6 +27,7 @@
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <limits.h>
|
|
||||||
+#include <fcntl.h>
|
|
||||||
|
|
||||||
#include "unlocked-io.h"
|
|
||||||
#include "utils.h"
|
|
||||||
@@ -363,31 +364,106 @@
|
|
||||||
#endif /* ENABLE_FOLLOW_SYMLINKS */
|
|
||||||
}
|
|
||||||
|
|
||||||
-/* Panic on failing rename */
|
|
||||||
+/* Panic on failing unlink */
|
|
||||||
void
|
|
||||||
-ck_rename (const char *from, const char *to, const char *unlink_if_fail)
|
|
||||||
+ck_unlink (const char *name)
|
|
||||||
{
|
|
||||||
- int rd = rename (from, to);
|
|
||||||
- if (rd != -1)
|
|
||||||
- return;
|
|
||||||
+ if (unlink (name) == -1)
|
|
||||||
+ panic (_("cannot remove %s: %s"), name, strerror (errno));
|
|
||||||
+}
|
|
||||||
|
|
||||||
- if (unlink_if_fail)
|
|
||||||
+/* Attempt to unlink denoted file if operation rd failed. */
|
|
||||||
+static int
|
|
||||||
+_unlink_if_fail (rd, unlink_if_fail)
|
|
||||||
+ int rd;
|
|
||||||
+ const char *unlink_if_fail;
|
|
||||||
+{
|
|
||||||
+ if (rd == -1 && unlink_if_fail)
|
|
||||||
{
|
|
||||||
int save_errno = errno;
|
|
||||||
+ ck_unlink (unlink_if_fail);
|
|
||||||
+ errno = save_errno;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ return rd != -1;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+/* Copy contents between files. */
|
|
||||||
+static int
|
|
||||||
+_copy (from, to)
|
|
||||||
+ const char *from, *to;
|
|
||||||
+{
|
|
||||||
+ static char buf[4096];
|
|
||||||
+
|
|
||||||
+ FILE *infile, *outfile;
|
|
||||||
+ int c, retval = 0;
|
|
||||||
errno = 0;
|
|
||||||
- unlink (unlink_if_fail);
|
|
||||||
|
|
||||||
- /* Failure to remove the temporary file is more severe,
|
|
||||||
- so trigger it first. */
|
|
||||||
- if (errno != 0)
|
|
||||||
- panic (_("cannot remove %s: %s"), unlink_if_fail, strerror (errno));
|
|
||||||
+ infile = fopen (from, "r");
|
|
||||||
+ if (infile == NULL)
|
|
||||||
+ return -1;
|
|
||||||
|
|
||||||
- errno = save_errno;
|
|
||||||
+ outfile = fopen (to, "w");
|
|
||||||
+ if (outfile == NULL)
|
|
||||||
+ {
|
|
||||||
+ fclose (infile);
|
|
||||||
+ return -1;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ while (1)
|
|
||||||
+ {
|
|
||||||
+ size_t bytes_in = fread (buf, 1, sizeof (buf), infile);
|
|
||||||
+ size_t bytes_out;
|
|
||||||
+ if (bytes_in == 0)
|
|
||||||
+ {
|
|
||||||
+ if (ferror (infile))
|
|
||||||
+ retval = -1;
|
|
||||||
+ break;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ bytes_out = fwrite (buf, 1, bytes_in, outfile);
|
|
||||||
+ if (bytes_out != bytes_in)
|
|
||||||
+ {
|
|
||||||
+ retval = -1;
|
|
||||||
+ break;
|
|
||||||
+ }
|
|
||||||
}
|
|
||||||
|
|
||||||
+ fclose (outfile);
|
|
||||||
+ fclose (infile);
|
|
||||||
+
|
|
||||||
+ return retval;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+/* Panic on failing rename */
|
|
||||||
+void
|
|
||||||
+ck_rename (from, to, unlink_if_fail)
|
|
||||||
+ const char *from, *to;
|
|
||||||
+ const char *unlink_if_fail;
|
|
||||||
+{
|
|
||||||
+ if (!_unlink_if_fail (rename (from, to), unlink_if_fail))
|
|
||||||
panic (_("cannot rename %s: %s"), from, strerror (errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
+/* Attempt to copy file contents between the files. */
|
|
||||||
+void
|
|
||||||
+ck_fccopy (from, to, unlink_if_fail)
|
|
||||||
+ const char *from, *to;
|
|
||||||
+ const char *unlink_if_fail;
|
|
||||||
+{
|
|
||||||
+ if (!_unlink_if_fail (_copy (from, to), unlink_if_fail))
|
|
||||||
+ panic (_("cannot copy %s to %s: %s"), from, to, strerror (errno));
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+/* Copy contents between files, and then unlink the source. */
|
|
||||||
+void
|
|
||||||
+ck_fcmove (from, to, unlink_if_fail)
|
|
||||||
+ const char *from, *to;
|
|
||||||
+ const char *unlink_if_fail;
|
|
||||||
+{
|
|
||||||
+ ck_fccopy (from, to, unlink_if_fail);
|
|
||||||
+ ck_unlink (from);
|
|
||||||
+}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
diff -urN sed-4.3/sed/utils.h sed-4.3.new00/sed/utils.h
|
|
||||||
--- sed-4.3/sed/utils.h 2012-03-16 10:13:31.000000000 +0100
|
|
||||||
+++ sed-4.3.new00/sed/utils.h 2014-02-10 14:40:25.603629422 +0100
|
|
||||||
@@ -33,6 +33,8 @@
|
|
||||||
FILE * ck_mkstemp (char **p_filename, const char *tmpdir, const char *base,
|
|
||||||
const char *mode) _GL_ARG_NONNULL ((1, 2, 3, 4));
|
|
||||||
void ck_rename (const char *from, const char *to, const char *unlink_if_fail);
|
|
||||||
+void ck_fccopy (const char *from, const char *to, const char *unlink_if_fail);
|
|
||||||
+void ck_fcmove (const char *from, const char *to, const char *unlink_if_fail);
|
|
||||||
|
|
||||||
void *ck_malloc (size_t size);
|
|
||||||
void *xmalloc (size_t size);
|
|
||||||
BIN
sed-4.5.tar.xz
BIN
sed-4.5.tar.xz
Binary file not shown.
BIN
sed-4.7.tar.xz
Normal file
BIN
sed-4.7.tar.xz
Normal file
Binary file not shown.
@ -1,31 +0,0 @@
|
|||||||
From 08675afe9af99002bc4770e5db00ce7a05db7575 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Assaf Gordon <assafgordon@gmail.com>
|
|
||||||
Date: Tue, 31 Jul 2018 01:42:46 -0600
|
|
||||||
Subject: [PATCH 21/61] sed: do not close stderr on exit
|
|
||||||
|
|
||||||
Not needed, and prevents leak-sanitizing from working.
|
|
||||||
|
|
||||||
* sed/utils.c (ck_fclose): Do not close stderr.
|
|
||||||
---
|
|
||||||
sed/utils.c | 5 +----
|
|
||||||
1 file changed, 1 insertion(+), 4 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/sed/utils.c b/sed/utils.c
|
|
||||||
index 5314ea4..329dec0 100644
|
|
||||||
--- a/sed/utils.c
|
|
||||||
+++ b/sed/utils.c
|
|
||||||
@@ -267,10 +267,7 @@ ck_fclose (FILE *stream)
|
|
||||||
last output operations might fail and it is important
|
|
||||||
to signal this as an error (perhaps to make). */
|
|
||||||
if (!stream)
|
|
||||||
- {
|
|
||||||
- do_ck_fclose (stdout);
|
|
||||||
- do_ck_fclose (stderr);
|
|
||||||
- }
|
|
||||||
+ do_ck_fclose (stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Close a single file. */
|
|
||||||
--
|
|
||||||
2.19.1
|
|
||||||
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
From 0144eeeb3d2412c6fad90fd7316dda1f6668d708 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Assaf Gordon <assafgordon@gmail.com>
|
|
||||||
Date: Fri, 20 Jul 2018 19:24:12 -0600
|
|
||||||
Subject: [PATCH 04/61] sed: do not flush output stream unless in unbuffered
|
|
||||||
mode
|
|
||||||
|
|
||||||
Previously sed would explicitly flush the output after
|
|
||||||
every output line, except if the output was stdout in unbuffered mode.
|
|
||||||
|
|
||||||
In practice this was equivalent to forcing line-buffering, and was
|
|
||||||
espcially was noticable with "sed -i" (where the output is a temporary
|
|
||||||
file).
|
|
||||||
|
|
||||||
With this change, explicit flushing only happens with "sed -u",
|
|
||||||
regardless of the type of output file, making "sed -i" much faster.
|
|
||||||
This change also affect other write commands such as 'w'/'W' and 's///w'.
|
|
||||||
|
|
||||||
Reported by Vidar Holen <vidar@vidarholen.net> in
|
|
||||||
https://lists.gnu.org/r/bug-sed/2018-07/msg00014.html .
|
|
||||||
|
|
||||||
* NEWS: Mention this.
|
|
||||||
* sed/execute.c (flush_output): Never flush output unless in unbuffered
|
|
||||||
mode, regardless of which file it is.
|
|
||||||
---
|
|
||||||
NEWS | 7 +++++++
|
|
||||||
sed/execute.c | 2 +-
|
|
||||||
2 files changed, 8 insertions(+), 1 deletion(-)
|
|
||||||
|
|
||||||
diff --git a/sed/execute.c b/sed/execute.c
|
|
||||||
index 7a4850f..1cc1d3f 100644
|
|
||||||
--- a/sed/execute.c
|
|
||||||
+++ b/sed/execute.c
|
|
||||||
@@ -415,7 +415,7 @@ output_missing_newline(struct output *outf)
|
|
||||||
static inline void
|
|
||||||
flush_output(FILE *fp)
|
|
||||||
{
|
|
||||||
- if (fp != stdout || unbuffered)
|
|
||||||
+ if (unbuffered)
|
|
||||||
ck_fflush(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
--
|
|
||||||
2.19.1
|
|
||||||
|
|
||||||
@ -1,88 +0,0 @@
|
|||||||
From 2cb09e14639bd0c6d55f796336ce4728607fd4b3 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Assaf Gordon <assafgordon@gmail.com>
|
|
||||||
Date: Fri, 27 Jul 2018 01:56:26 -0600
|
|
||||||
Subject: [PATCH 05/61] sed: fix extraneous NUL in s///n command
|
|
||||||
|
|
||||||
Under certain conditions sed would add an extraneous NUL:
|
|
||||||
|
|
||||||
$ echo 0 | sed -e 's/$/a/2' | od -tx1 -An
|
|
||||||
30 00 0a
|
|
||||||
|
|
||||||
This would happen when the regex is an empty (zero-length) match at the
|
|
||||||
end of the line (e.g. '$' and 'a*$') and the substitute number flag
|
|
||||||
('n' in s///n) is higher than the number of actual matches (multiple
|
|
||||||
EOL matches are possible with multiline match, e.g. 's/$/a/3m').
|
|
||||||
|
|
||||||
Details:
|
|
||||||
The comment at the top of 'execute.c:do_subst()' says:
|
|
||||||
|
|
||||||
/* The first part of the loop optimizes s/xxx// when xxx is at the
|
|
||||||
start, and s/xxx$// */
|
|
||||||
|
|
||||||
Which refers to lines 1051-3:
|
|
||||||
|
|
||||||
1051 /* Copy stuff to the left of this match into the output string. */
|
|
||||||
1052 if (start < offset)
|
|
||||||
1053 str_append(&s_accum, line.active + start, offset - start);
|
|
||||||
|
|
||||||
The above code appends text to 's_accum' but does *not* update 'start'.
|
|
||||||
|
|
||||||
Later on, if the s/// command includes 'n' flag, and if 'matched == 0'
|
|
||||||
(an empty match), this comparison will be incorrect:
|
|
||||||
|
|
||||||
1081 if (start < line.length)
|
|
||||||
1082 matched = 1;
|
|
||||||
|
|
||||||
Will in turn will set 'matched' to 1, and the 'str_append' call that
|
|
||||||
follows (line 1087) will append an additional character.
|
|
||||||
Because the empty match is EOL, the appended character is NUL.
|
|
||||||
|
|
||||||
More examples that trigger the bug:
|
|
||||||
|
|
||||||
echo 0 | sed -e 's/a*$/X/3'
|
|
||||||
printf "%s\n" 0 0 0 | sed -e 'N;N;s/a*$/X/4m'
|
|
||||||
|
|
||||||
Examples that do not trigger the bug:
|
|
||||||
|
|
||||||
# The 'a*' empty regex matches at the beginning of the line (in
|
|
||||||
# addition to the end of the line), and the optimization in line
|
|
||||||
# 1052 is skipped.
|
|
||||||
echo 0 | sed -e 's/a*/X/3'
|
|
||||||
|
|
||||||
# There are 3 EOLs in the pattern space, s///3 is not too large.
|
|
||||||
printf "%s\n" 0 0 0 | sed -e 'N;N;s/a*$/X/3m'
|
|
||||||
|
|
||||||
This was discovered while investigating bug#32271 reported by bugs@feusi.co
|
|
||||||
in https://lists.gnu.org/r/bug-sed/2018-07/msg00018.html .
|
|
||||||
|
|
||||||
* NEWS: Mention the fix.
|
|
||||||
* sed/execute.c (do_subst): Update 'start' as needed.
|
|
||||||
* testsuite/bug-32271-1.sh: New test.
|
|
||||||
* testsuite/local.mk (T): Add test.
|
|
||||||
---
|
|
||||||
NEWS | 3 +++
|
|
||||||
sed/execute.c | 5 ++++-
|
|
||||||
testsuite/bug32271-1.sh | 45 +++++++++++++++++++++++++++++++++++++++++
|
|
||||||
testsuite/local.mk | 1 +
|
|
||||||
4 files changed, 53 insertions(+), 1 deletion(-)
|
|
||||||
create mode 100755 testsuite/bug32271-1.sh
|
|
||||||
|
|
||||||
diff --git a/sed/execute.c b/sed/execute.c
|
|
||||||
index 1cc1d3f..c1d656a 100644
|
|
||||||
--- a/sed/execute.c
|
|
||||||
+++ b/sed/execute.c
|
|
||||||
@@ -1050,7 +1050,10 @@ do_subst(struct subst *sub)
|
|
||||||
|
|
||||||
/* Copy stuff to the left of this match into the output string. */
|
|
||||||
if (start < offset)
|
|
||||||
- str_append(&s_accum, line.active + start, offset - start);
|
|
||||||
+ {
|
|
||||||
+ str_append(&s_accum, line.active + start, offset - start);
|
|
||||||
+ start = offset;
|
|
||||||
+ }
|
|
||||||
|
|
||||||
/* If we're counting up to the Nth match, are we there yet?
|
|
||||||
And even if we are there, there is another case we have to
|
|
||||||
--
|
|
||||||
2.19.1
|
|
||||||
|
|
||||||
@ -1,46 +0,0 @@
|
|||||||
From c52a676e5e31f4f5c25d78f5dd4c17fab6585d8e Mon Sep 17 00:00:00 2001
|
|
||||||
From: Assaf Gordon <assafgordon@gmail.com>
|
|
||||||
Date: Sat, 7 Jul 2018 22:03:38 -0600
|
|
||||||
Subject: [PATCH 02/61] sed: fix heap buffer overflow from invalid references
|
|
||||||
|
|
||||||
Under certain conditions sed would access invalid memory based on
|
|
||||||
the requested back-reference (e.g. "s//\9/" would access the 9th element
|
|
||||||
in the regex registers without checking it is at least 9 element in
|
|
||||||
size).
|
|
||||||
|
|
||||||
The following examples would trigger valgrind errors:
|
|
||||||
seq 2 | valgrind sed -e '/^/s///p ; 2s//\9/'
|
|
||||||
seq 2 | valgrind sed --posix -e '/2/p ; 2s//\9/'
|
|
||||||
|
|
||||||
Reported by bugs@feusi.co in
|
|
||||||
https://lists.gnu.org/r/bug-sed/2018-07/msg00004.html .
|
|
||||||
|
|
||||||
* NEWS: Mention the bugfix.
|
|
||||||
* sed/execute.c (append_replacement): Check number of allocated regex
|
|
||||||
replacement registers before accessing the array.
|
|
||||||
* sed/testsuite/bug32082.sh: Test sed for this behaviour under valgrind.
|
|
||||||
* sed/testsuite/local.mk (T): Add new test.
|
|
||||||
---
|
|
||||||
NEWS | 5 +++
|
|
||||||
sed/execute.c | 2 +-
|
|
||||||
testsuite/bug32082.sh | 81 +++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
testsuite/local.mk | 1 +
|
|
||||||
4 files changed, 88 insertions(+), 1 deletion(-)
|
|
||||||
create mode 100755 testsuite/bug32082.sh
|
|
||||||
|
|
||||||
diff --git a/sed/execute.c b/sed/execute.c
|
|
||||||
index 2804c5e..7a4850f 100644
|
|
||||||
--- a/sed/execute.c
|
|
||||||
+++ b/sed/execute.c
|
|
||||||
@@ -987,7 +987,7 @@ static void append_replacement (struct line *buf, struct replacement *p,
|
|
||||||
curr_type &= ~REPL_MODIFIERS;
|
|
||||||
}
|
|
||||||
|
|
||||||
- if (0 <= i)
|
|
||||||
+ if (0 <= i && i < regs->num_regs)
|
|
||||||
{
|
|
||||||
if (regs->end[i] == regs->start[i] && p->repl_type & REPL_MODIFIERS)
|
|
||||||
/* Save this modifier, we shall apply it later.
|
|
||||||
--
|
|
||||||
2.19.1
|
|
||||||
|
|
||||||
@ -1,72 +0,0 @@
|
|||||||
From 007a417687970e0f5c88e181dc0cd07800fc0180 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Assaf Gordon <assafgordon@gmail.com>
|
|
||||||
Date: Fri, 27 Jul 2018 02:19:41 -0600
|
|
||||||
Subject: [PATCH 06/61] sed: fix heap buffer overflow from multiline EOL regex
|
|
||||||
optimization
|
|
||||||
|
|
||||||
sed would access invalid memory when matching EOF combined with
|
|
||||||
s///n flag:
|
|
||||||
|
|
||||||
$ yes 0 | fmt -w 40 | head -n2 | valgrind sed 'N;s/$//2m'
|
|
||||||
==13131== Conditional jump or move depends on uninitialised value(s)
|
|
||||||
==13131== at 0x4C3002B: memchr (vg_replace_strmem.c:883)
|
|
||||||
==13131== by 0x1120BD: match_regex (regexp.c:286)
|
|
||||||
==13131== by 0x110736: do_subst (execute.c:1101)
|
|
||||||
==13131== by 0x1115D3: execute_program (execute.c:1591)
|
|
||||||
==13131== by 0x111A4C: process_files (execute.c:1774)
|
|
||||||
==13131== by 0x112E1C: main (sed.c:405)
|
|
||||||
==13131==
|
|
||||||
==13131== Invalid read of size 1
|
|
||||||
==13131== at 0x4C30027: memchr (vg_replace_strmem.c:883)
|
|
||||||
==13131== by 0x1120BD: match_regex (regexp.c:286)
|
|
||||||
==13131== by 0x110736: do_subst (execute.c:1101)
|
|
||||||
==13131== by 0x1115D3: execute_program (execute.c:1591)
|
|
||||||
==13131== by 0x111A4C: process_files (execute.c:1774)
|
|
||||||
==13131== by 0x112E1C: main (sed.c:405)
|
|
||||||
==13131== Address 0x55ec765 is 0 bytes after a block of size 101 alloc'd
|
|
||||||
==13131== at 0x4C2DDCF: realloc (vg_replace_malloc.c:785)
|
|
||||||
==13131== by 0x113BA2: ck_realloc (utils.c:418)
|
|
||||||
==13131== by 0x10E682: resize_line (execute.c:154)
|
|
||||||
==13131== by 0x10E6F0: str_append (execute.c:165)
|
|
||||||
==13131== by 0x110779: do_subst (execute.c:1106)
|
|
||||||
==13131== by 0x1115D3: execute_program (execute.c:1591)
|
|
||||||
==13131== by 0x111A4C: process_files (execute.c:1774)
|
|
||||||
==13131== by 0x112E1C: main (sed.c:405)
|
|
||||||
==13131==
|
|
||||||
|
|
||||||
The ^/$ optimization code added in v4.2.2-161-g6dea75e called memchr()
|
|
||||||
using 'buflen', ignoring the value of 'buf_start_offset' (which, if not
|
|
||||||
zero, reduces the number of bytes available for the search).
|
|
||||||
|
|
||||||
Reported by bugs@feusi.co (bug#32271) in
|
|
||||||
https://lists.gnu.org/r/bug-sed/2018-07/msg00018.html .
|
|
||||||
|
|
||||||
* NEWS: Mention the fix.
|
|
||||||
* sed/regexp.c (match_regex): Use correct buffer length in memchr().
|
|
||||||
* testsuite/bug-32271-2.sh: Test using valgrind.
|
|
||||||
* testsuite/local.mk (T): Add new test.
|
|
||||||
---
|
|
||||||
NEWS | 3 ++
|
|
||||||
sed/regexp.c | 3 +-
|
|
||||||
testsuite/bug32271-2.sh | 75 +++++++++++++++++++++++++++++++++++++++++
|
|
||||||
testsuite/local.mk | 1 +
|
|
||||||
4 files changed, 81 insertions(+), 1 deletion(-)
|
|
||||||
create mode 100755 testsuite/bug32271-2.sh
|
|
||||||
|
|
||||||
diff --git a/sed/regexp.c b/sed/regexp.c
|
|
||||||
index f7c2851..567dd26 100644
|
|
||||||
--- a/sed/regexp.c
|
|
||||||
+++ b/sed/regexp.c
|
|
||||||
@@ -283,7 +283,8 @@ match_regex(struct regex *regex, char *buf, size_t buflen,
|
|
||||||
const char *p = NULL;
|
|
||||||
|
|
||||||
if (regex->flags & REG_NEWLINE)
|
|
||||||
- p = memchr (buf + buf_start_offset, buffer_delimiter, buflen);
|
|
||||||
+ p = memchr (buf + buf_start_offset, buffer_delimiter,
|
|
||||||
+ buflen - buf_start_offset);
|
|
||||||
|
|
||||||
offset = p ? p - buf : buflen;
|
|
||||||
}
|
|
||||||
--
|
|
||||||
2.19.1
|
|
||||||
|
|
||||||
@ -1,39 +0,0 @@
|
|||||||
From ba8e66de6de30fabc9e529882b5f408b188a296a Mon Sep 17 00:00:00 2001
|
|
||||||
From: Assaf Gordon <assafgordon@gmail.com>
|
|
||||||
Date: Tue, 31 Jul 2018 11:25:35 -0600
|
|
||||||
Subject: [PATCH 23/61] sed: fix memory leak
|
|
||||||
|
|
||||||
* sed/regexp.c (match_regex): Free the previously allocated regex struct
|
|
||||||
before re-building the regex during program execution.
|
|
||||||
---
|
|
||||||
sed/regexp.c | 14 +++++++++++++-
|
|
||||||
1 file changed, 13 insertions(+), 1 deletion(-)
|
|
||||||
|
|
||||||
diff --git a/sed/regexp.c b/sed/regexp.c
|
|
||||||
index 2801d6f..b3a4b41 100644
|
|
||||||
--- a/sed/regexp.c
|
|
||||||
+++ b/sed/regexp.c
|
|
||||||
@@ -269,7 +269,19 @@ match_regex (struct regex *regex, char *buf, size_t buflen,
|
|
||||||
return (ret == 0);
|
|
||||||
#else
|
|
||||||
if (regex->pattern.no_sub && regsize)
|
|
||||||
- compile_regex_1 (regex, regsize);
|
|
||||||
+ {
|
|
||||||
+ /* Re-compiling an existing regex, free the previously allocated
|
|
||||||
+ structures. */
|
|
||||||
+ if (regex->dfa)
|
|
||||||
+ {
|
|
||||||
+ dfafree (regex->dfa);
|
|
||||||
+ free (regex->dfa);
|
|
||||||
+ regex->dfa = NULL;
|
|
||||||
+ }
|
|
||||||
+ regfree (®ex->pattern);
|
|
||||||
+
|
|
||||||
+ compile_regex_1 (regex, regsize);
|
|
||||||
+ }
|
|
||||||
|
|
||||||
regex->pattern.regs_allocated = REGS_REALLOCATE;
|
|
||||||
|
|
||||||
--
|
|
||||||
2.19.1
|
|
||||||
|
|
||||||
@ -1,39 +0,0 @@
|
|||||||
From dae3abf2af80bf980792c32515e98704ed2ac3a6 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Jannick <thirdedition@gmx.net>
|
|
||||||
Date: Thu, 1 Nov 2018 18:24:50 +0100
|
|
||||||
Subject: [PATCH 42/61] sed: fix memory leakage under lint
|
|
||||||
|
|
||||||
The NULL-initialized char string in_place_extension is free'ed everytime
|
|
||||||
it is redefined (using xstrdup) and at program exit with any return code.
|
|
||||||
|
|
||||||
See: https://lists.gnu.org/r/sed-devel/2018-11/msg00005.html
|
|
||||||
|
|
||||||
* sed/sed.c (main, cleanup): Free 'in_place_extension' if running with
|
|
||||||
lint.
|
|
||||||
---
|
|
||||||
sed/sed.c | 2 ++
|
|
||||||
1 file changed, 2 insertions(+)
|
|
||||||
|
|
||||||
diff --git a/sed/sed.c b/sed/sed.c
|
|
||||||
index 5ff49c0..e814613 100644
|
|
||||||
--- a/sed/sed.c
|
|
||||||
+++ b/sed/sed.c
|
|
||||||
@@ -91,6 +91,7 @@ struct localeinfo localeinfo;
|
|
||||||
static void
|
|
||||||
cleanup (void)
|
|
||||||
{
|
|
||||||
+ IF_LINT (free (in_place_extension));
|
|
||||||
if (G_file_to_unlink)
|
|
||||||
unlink (G_file_to_unlink);
|
|
||||||
}
|
|
||||||
@@ -307,6 +307,7 @@
|
|
||||||
|
|
||||||
case 'i':
|
|
||||||
separate_files = true;
|
|
||||||
+ IF_LINT (free (in_place_extension));
|
|
||||||
if (optarg == NULL)
|
|
||||||
/* use no backups */
|
|
||||||
in_place_extension = ck_strdup ("*");
|
|
||||||
--
|
|
||||||
2.19.1
|
|
||||||
|
|
||||||
26
sed.spec
26
sed.spec
@ -1,22 +1,11 @@
|
|||||||
Name: sed
|
Name: sed
|
||||||
Version: 4.5
|
Version: 4.7
|
||||||
Release: 3
|
Release: 0
|
||||||
Summary: non-interactive command-line text editor
|
Summary: non-interactive command-line text editor
|
||||||
|
|
||||||
License: GPLv3+
|
License: GPLv3+
|
||||||
URL: https://www.gnu.org/software/sed/
|
URL: https://www.gnu.org/software/sed/
|
||||||
Source0: http://ftp.gnu.org/gnu/sed/%{name}-%{version}.tar.xz
|
Source0: http://ftp.gnu.org/gnu/sed/%{name}-%{version}.tar.xz
|
||||||
Source1: http://sed.sourceforge.net/sedfaq.txt
|
|
||||||
|
|
||||||
Patch0: sed-4.2.2-binary_copy_args.patch
|
|
||||||
|
|
||||||
Patch6000: sed-fix-heap-buffer-overflow-from-invalid-references.patch
|
|
||||||
Patch6001: sed-do-not-flush-output-stream-unless-in-unbuffered-.patch
|
|
||||||
Patch6002: sed-fix-extraneous-NUL-in-s-n-command.patch
|
|
||||||
Patch6003: sed-fix-heap-buffer-overflow-from-multiline-EOL-rege.patch
|
|
||||||
Patch6004: sed-do-not-close-stderr-on-exit.patch
|
|
||||||
Patch6005: sed-fix-memory-leak.patch
|
|
||||||
Patch6006: sed-fix-memory-leakage-under-lint.patch
|
|
||||||
|
|
||||||
BuildRequires: gzip automake autoconf gcc
|
BuildRequires: gzip automake autoconf gcc
|
||||||
BuildRequires: glibc-devel libselinux-devel libacl-devel perl-Getopt-Long
|
BuildRequires: glibc-devel libselinux-devel libacl-devel perl-Getopt-Long
|
||||||
@ -38,8 +27,6 @@ Man pages and other related documents for %{name}.
|
|||||||
|
|
||||||
%prep
|
%prep
|
||||||
%autosetup -n %{name}-%{version} -p1
|
%autosetup -n %{name}-%{version} -p1
|
||||||
chmod 644 %{SOURCE1}
|
|
||||||
cp -p %{SOURCE1} .
|
|
||||||
|
|
||||||
%build
|
%build
|
||||||
%configure --without-included-regex
|
%configure --without-included-regex
|
||||||
@ -47,7 +34,6 @@ make %{?_smp_mflags}
|
|||||||
|
|
||||||
%install
|
%install
|
||||||
%make_install
|
%make_install
|
||||||
gzip -9 sedfaq.txt
|
|
||||||
%find_lang %{name}
|
%find_lang %{name}
|
||||||
|
|
||||||
%files -f %{name}.lang
|
%files -f %{name}.lang
|
||||||
@ -55,11 +41,17 @@ gzip -9 sedfaq.txt
|
|||||||
%{_bindir}/sed
|
%{_bindir}/sed
|
||||||
|
|
||||||
%files help
|
%files help
|
||||||
%doc ABOUT-NLS AUTHORS BUGS ChangeLog* INSTALL NEWS README THANKS sedfaq.txt.gz
|
%doc ABOUT-NLS AUTHORS BUGS ChangeLog* INSTALL NEWS README THANKS
|
||||||
%{_infodir}/*.info.gz
|
%{_infodir}/*.info.gz
|
||||||
%exclude %{_infodir}/dir*
|
%exclude %{_infodir}/dir*
|
||||||
%{_mandir}/man1/*.1.gz
|
%{_mandir}/man1/*.1.gz
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Tue Jan 7 2020 JeanLeo<liujianliu.liu@huawei.com> - 4.7-0
|
||||||
|
- Type:bugfix
|
||||||
|
- ID:NA
|
||||||
|
- SUG:NA
|
||||||
|
- DESC:update software to version 4.7
|
||||||
|
|
||||||
* Fri Aug 23 2019 openEuler Buildteam <buildteam@openeuler.org> - 4.5-3
|
* Fri Aug 23 2019 openEuler Buildteam <buildteam@openeuler.org> - 4.5-3
|
||||||
- Package init
|
- Package init
|
||||||
|
|||||||
3964
sedfaq.txt
3964
sedfaq.txt
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user