Update to 4.2.2

This commit is contained in:
Martin Briza 2013-01-04 15:46:21 +01:00
parent 64095c9b0c
commit 8f4c3b3f85
8 changed files with 13 additions and 569 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
sed-4.2.1.tar.bz2
/sed-4.2.2.tar.bz2

View File

@ -1,273 +0,0 @@
diff --git a/doc/sed.1 b/doc/sed.1
index 42a0a28..bb235c8 100644
--- a/doc/sed.1
+++ b/doc/sed.1
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.28.
-.TH SED "1" "June 2009" "sed version 4.2.1" "User Commands"
+.TH SED "1" "February 2010" "sed version 4.2.1" "User Commands"
.SH NAME
sed \- stream editor for filtering and transforming text
.SH SYNOPSIS
@@ -40,6 +40,10 @@ follow symlinks when processing in place
.IP
edit files in place (makes backup if extension supplied)
.HP
+\fB\-c\fR, \fB\-\-copy\fR
+.IP
+use copy instead of rename when shuffling files in \fB\-i\fR mode
+.HP
\fB\-l\fR N, \fB\-\-line\-length\fR=\fIN\fR
.IP
specify the desired line-wrap length for the `l' command
diff --git a/sed/execute.c b/sed/execute.c
index af8c4d2..c05b418 100644
--- a/sed/execute.c
+++ b/sed/execute.c
@@ -822,11 +822,13 @@ closedown(input)
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);
free (input->out_file_name);
}
else
diff --git a/sed/sed.c b/sed/sed.c
index 723958d..1fbb279 100644
--- a/sed/sed.c
+++ b/sed/sed.c
@@ -75,6 +75,10 @@ bool follow_symlinks = false;
/* 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 files, either "rt" or "rb". */
char *read_mode = "rt";
@@ -135,6 +139,8 @@ Usage: %s [OPTION]... {script-only-if-no-other-script} [input-file]...\n\
#endif
fprintf(out, _(" -i[SUFFIX], --in-place[=SUFFIX]\n\
edit files in place (makes backup if extension supplied)\n"));
+ fprintf(out, _(" -c, --copy\n\
+ use copy instead of rename when shuffling files in -i mode\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"));
@@ -174,9 +180,9 @@ main(argc, argv)
char **argv;
{
#ifdef REG_PERL
-#define SHORTOPTS "bsnrRuEe:f:l:i::V:"
+#define SHORTOPTS "bcsnrRuEe:f:l:i::V:"
#else
-#define SHORTOPTS "bsnruEe:f:l:i::V:"
+#define SHORTOPTS "bcsnruEe:f:l:i::V:"
#endif
static struct option longopts[] = {
@@ -188,6 +194,7 @@ main(argc, argv)
{"expression", 1, NULL, 'e'},
{"file", 1, NULL, 'f'},
{"in-place", 2, NULL, 'i'},
+ {"copy", 0, NULL, 'c'},
{"line-length", 1, NULL, 'l'},
{"quiet", 0, NULL, 'n'},
{"posix", 0, NULL, 'p'},
@@ -254,6 +261,10 @@ main(argc, argv)
case 'F':
follow_symlinks = true;
+ break;
+
+ case 'c':
+ copy_instead_of_rename = true;
break;
case 'i':
@@ -334,6 +345,12 @@ to the extent permitted by law.\n\
}
}
+ 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 --git a/sed/sed.h b/sed/sed.h
index 6b4101d..d4d9aa9 100644
--- a/sed/sed.h
+++ b/sed/sed.h
@@ -233,6 +233,10 @@ extern countT lcmd_out_line_len;
/* 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 files, either "rt" or "rb". */
extern char *read_mode;
diff --git a/sed/utils.c b/sed/utils.c
index 241ef1d..ebe6030 100644
--- a/sed/utils.c
+++ b/sed/utils.c
@@ -39,6 +39,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <limits.h>
+#include <fcntl.h>
#include "utils.h"
#include "pathmax.h"
@@ -408,33 +409,109 @@ follow_symlink(const char *fname)
return fname;
#endif /* ENABLE_FOLLOW_SYMLINKS */
}
+
-/* Panic on failing rename */
+/* Panic on failing unlink */
void
-ck_rename (from, to, unlink_if_fail)
- const char *from, *to;
- const char *unlink_if_fail;
+ck_unlink (name)
+ 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 --git a/sed/utils.h b/sed/utils.h
index d3f431d..b915596 100644
--- a/sed/utils.h
+++ b/sed/utils.h
@@ -32,6 +32,8 @@ const char *follow_symlink P_((const char *path));
size_t ck_getline P_((char **text, size_t *buflen, FILE *stream));
FILE * ck_mkstemp P_((char **p_filename, char *tmpdir, char *base));
void ck_rename P_((const char *from, const char *to, const char *unlink_if_fail));
+void ck_fccopy P_((const char *from, const char *to, const char *unlink_if_fail));
+void ck_fcmove P_((const char *from, const char *to, const char *unlink_if_fail));
VOID *ck_malloc P_((size_t size));
VOID *xmalloc P_((size_t size));

View File

@ -1,58 +0,0 @@
From 695e76c32320a6cf641bc91c077ded01c6da0315 Mon Sep 17 00:00:00 2001
From: "Vojtech Vitek (V-Teq)" <vvitek@redhat.com>
Date: Tue, 12 Jul 2011 15:37:12 +0200
Subject: [PATCH] avoid silent data loss when an input line is 2^31 bytes or
longer
If one line in a file has length (including newline) of 2^31, then
applying sed -i to that file truncates it to size 0. I first
noticed it like this: Create a file with line of length 2^31-1
$ perl -le 'print "v"x(2**31-1)' > k
Then prepend a byte to that line:
$ sed -i 's/^/v/' k
Surprise! The file is empty.
* sed/utils.c (ck_getline): Declare "result" to be of type ssize_t,
rather than int, to match the return type of getline.
Upstream 81ce070727b225a1e23e5a48f775811c8a9e7366
by Jim Meyering <meyering@redhat.com>
---
NEWS | 4 ++++
sed/utils.c | 4 ++--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/NEWS b/NEWS
index cd755d2..91d7c15 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+Patches from Sed 4.2.2
+
+* don't misbehave (truncate input) for lines of length 2^31 and longer
+
Sed 4.2.1
* fix parsing of s/[[[[[[[[[]//
diff --git a/sed/utils.c b/sed/utils.c
index 82b53a6..c416d59 100644
--- a/sed/utils.c
+++ b/sed/utils.c
@@ -1,5 +1,5 @@
/* Functions from hack's utils library.
- Copyright (C) 1989, 1990, 1991, 1998, 1999, 2003, 2008, 2009
+ Copyright (C) 1989, 1990, 1991, 1998, 1999, 2003, 2008, 2009, 2011
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
@@ -269,7 +269,7 @@ ck_getline(text, buflen, stream)
size_t *buflen;
FILE *stream;
{
- int result;
+ ssize_t result;
if (!ferror (stream))
result = getline (text, buflen, stream);
--
1.7.5.4

View File

@ -1,25 +0,0 @@
--- sed-4.2.1/sed/sed.c 2009-06-03 21:10:51.000000000 +0200
+++ sed-4.2.1_copy/sed/sed.c 2009-06-30 14:12:28.000000000 +0200
@@ -174,11 +174,11 @@ main(argc, argv)
char **argv;
{
#ifdef REG_PERL
-#define SHORTOPTS "bsnrRuEe:f:l:i::V:"
+#define SHORTOPTS "cbsnrRuEe:f:l:i::V:"
#else
-#define SHORTOPTS "bsnruEe:f:l:i::V:"
+#define SHORTOPTS "cbsnruEe:f:l:i::V:"
#endif
-
+/* -c --copy is just a dummy param to keep backward compatibility */
static struct option longopts[] = {
{"binary", 0, NULL, 'b'},
{"regexp-extended", 0, NULL, 'r'},
@@ -196,6 +196,7 @@ main(argc, argv)
{"unbuffered", 0, NULL, 'u'},
{"version", 0, NULL, 'v'},
{"help", 0, NULL, 'h'},
+ {"copy", 0, NULL, 'c'},
#ifdef ENABLE_FOLLOW_SYMLINKS
{"follow-symlinks", 0, NULL, 'F'},
#endif

View File

@ -1,152 +0,0 @@
Backported upstream commit 0f968ceb7bc1a65773979ef419872ce43677c790
Original by Paolo Bonzini <bonzini@gnu.org> - 2012-04-13
Modified by Martin Briza (original patch didn't apply clearly)
* sed/compile.c (convert_number): Remove default_char argument,
expect buf to point to it. Remove maxdigits argument and compute
it on the fly.
(normalize_text): Unify calls to convert_number under the convert
label. For TEXT_REPLACEMENT add a backslash to the output if
convert_number returns ch == '&'.
--
diff -rpu sed-4.2.1/sed/compile.c sed-4.2.1-modified/sed/compile.c
--- sed-4.2.1/sed/compile.c 2009-06-17 14:54:43.000000000 +0200
+++ sed-4.2.1-modified/sed/compile.c 2012-06-12 16:46:19.310301149 +0200
@@ -300,20 +300,19 @@ add_then_next(b, ch)
return inchar();
}
-static char * convert_number P_((char *, char *, const char *, int, int, int));
+static char * convert_number P_((char *, char *, const char *, int));
static char *
-convert_number(result, buf, bufend, base, maxdigits, default_char)
+convert_number(result, buf, bufend, base)
char *result;
char *buf;
const char *bufend;
int base;
- int maxdigits;
- int default_char;
{
int n = 0;
+ int max = 1;
char *p;
- for (p=buf; p < bufend && maxdigits-- > 0; ++p)
+ for (p=buf+1; p < bufend && max <= 255; ++p, max *= base)
{
int d = -1;
switch (*p)
@@ -339,8 +338,8 @@ convert_number(result, buf, bufend, base
break;
n = n * base + d;
}
- if (p == buf)
- *result = default_char;
+ if (p == buf+1)
+ *result = *buf;
else
*result = n;
return p;
@@ -1417,6 +1416,8 @@ normalize_text(buf, len, buftype)
const char *bufend = buf + len;
char *p = buf;
char *q = buf;
+ char ch;
+ int base;
/* This variable prevents normalizing text within bracket
subexpressions when conforming to POSIX. If 0, we
@@ -1464,14 +1465,12 @@ normalize_text(buf, len, buftype)
case 'v': *q++ = '\v'; p++; continue;
case 'd': /* decimal byte */
- p = convert_number(q, p+1, bufend, 10, 3, 'd');
- q++;
- continue;
+ base = 10;
+ goto convert;
case 'x': /* hexadecimal byte */
- p = convert_number(q, p+1, bufend, 16, 2, 'x');
- q++;
- continue;
+ base = 16;
+ goto convert;
#ifdef REG_PERL
case '0': case '1': case '2': case '3':
@@ -1480,8 +1479,8 @@ normalize_text(buf, len, buftype)
&& p+1 < bufend
&& p[1] >= '0' && p[1] <= '9')
{
- p = convert_number(q, p, bufend, 8, 3, *p);
- q++;
+ base = 8;
+ goto convert;
}
else
{
@@ -1495,8 +1494,8 @@ normalize_text(buf, len, buftype)
case 'o': /* octal byte */
if (!(extended_regexp_flags & REG_PERL))
{
- p = convert_number(q, p+1, bufend, 8, 3, 'o');
- q++;
+ base = 8;
+ goto convert;
}
else
{
@@ -1508,10 +1507,16 @@ normalize_text(buf, len, buftype)
continue;
#else
case 'o': /* octal byte */
- p = convert_number(q, p+1, bufend, 8, 3, 'o');
- q++;
- continue;
+ base = 8;
#endif
+convert:
+ p = convert_number(&ch, p, bufend, base);
+
+ /* for an ampersand in a replacement, pass the \ up one level */
+ if (buftype == TEXT_REPLACEMENT && ch == '&')
+ *q++ = '\\';
+ *q++ = ch;
+ continue;
case 'c':
if (++p < bufend)
diff -rpu sed-4.2.1/testsuite/Makefile.am sed-4.2.1-modified/testsuite/Makefile.am
--- sed-4.2.1/testsuite/Makefile.am 2009-06-25 20:55:35.000000000 +0200
+++ sed-4.2.1-modified/testsuite/Makefile.am 2012-06-12 16:45:56.875331158 +0200
@@ -24,7 +24,7 @@ SEDTESTS += \
fasts uniq manis khadafy linecnt eval distrib 8to7 y-bracket \
y-newline allsub cv-vars classes middle bsd stdin flipcase \
insens subwrite writeout readin insert utf8-1 utf8-2 utf8-3 utf8-4 \
- badenc inplace-hold brackets \
+ badenc inplace-hold brackets amp-escape\
help version file quiet \
factor binary3 binary2 binary dc
@@ -39,6 +39,7 @@ EXTRA_DIST = \
8bit.good 8bit.inp 8bit.sed \
8to7.good 8to7.inp 8to7.sed \
allsub.good allsub.inp allsub.sed \
+ amp-escape.good amp-escape.inp amp-escape.sed \
appquit.good appquit.inp appquit.sed \
binary.good binary.inp binary.sed binary2.sed binary3.sed \
bkslashes.good bkslashes.inp bkslashes.sed \
diff -rpu sed-4.2.1/testsuite/Makefile.tests sed-4.2.1-modified/testsuite/Makefile.tests
--- sed-4.2.1/testsuite/Makefile.tests 2009-06-25 20:55:35.000000000 +0200
+++ sed-4.2.1-modified/testsuite/Makefile.tests 2012-06-12 16:46:17.195303978 +0200
@@ -21,7 +21,7 @@ SKIP = :>$@.skip; exit 77
enable sep inclib 8bit 8to7 newjis xabcx dollar noeol bkslashes \
numsub head madding mac-mf empty xbxcx xbxcx3 recall recall2 xemacs \
appquit fasts uniq manis linecnt khadafy allsub flipcase space modulo \
-y-bracket y-newline insert brackets::
+y-bracket y-newline insert brackets amp-escape::
$(SEDENV) $(SED) -f $(srcdir)/$@.sed \
< $(srcdir)/$@.inp | $(TR) -d \\r > $@.out
$(CMP) $(srcdir)/$@.good $@.out

View File

@ -1,50 +0,0 @@
diff --git a/ChangeLog b/ChangeLog
index 06956a7..30d9fca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-10-14 Yuri G. Kudryashov <urkud.urkud@gmail.com> (tiny change)
+
+ * testsuite/Makefile.tests: Override LC_ALL, not LANG.
+
2009-06-27 Paolo Bonzini <bonzini@gnu.org>
* configure.ac: Bump version.
diff --git a/testsuite/Makefile.tests b/testsuite/Makefile.tests
index 1f04290..c0910dc 100644
--- a/testsuite/Makefile.tests
+++ b/testsuite/Makefile.tests
@@ -34,16 +34,16 @@ y-bracket y-newline insert brackets::
@$(RM) $@.out
badenc::
- LANG=ru_RU.UTF-8 $(TIME) $(SED) -nf $(srcdir)/$@.sed \
+ LC_ALL=ru_RU.UTF-8 $(TIME) $(SED) -nf $(srcdir)/$@.sed \
< $(srcdir)/$@.inp | $(TR) -d \\r > $@.out
$(CMP) $(srcdir)/$@.good $@.out
- LANG=it_IT.UTF-8 $(TIME) $(SED) -nf $(srcdir)/$@.sed \
+ LC_ALL=it_IT.UTF-8 $(TIME) $(SED) -nf $(srcdir)/$@.sed \
< $(srcdir)/$@.inp | $(TR) -d \\r > $@.out
$(CMP) $(srcdir)/$@.good $@.out
- LANG=en_US.UTF-8 $(TIME) $(SED) -nf $(srcdir)/$@.sed \
+ LC_ALL=en_US.UTF-8 $(TIME) $(SED) -nf $(srcdir)/$@.sed \
< $(srcdir)/$@.inp | $(TR) -d \\r > $@.out
$(CMP) $(srcdir)/$@.good $@.out
- LANG=en_GB.UTF-8 $(TIME) $(SED) -nf $(srcdir)/$@.sed \
+ LC_ALL=en_GB.UTF-8 $(TIME) $(SED) -nf $(srcdir)/$@.sed \
< $(srcdir)/$@.inp | $(TR) -d \\r > $@.out
$(CMP) $(srcdir)/$@.good $@.out
@$(RM) $@.out
@@ -51,10 +51,10 @@ badenc::
# Try with ru_RU.UTF-8. If it is presumably not installed, see if the current
# locale is UTF-8 and run it in the current locale.
utf8-1 utf8-2 utf8-3 utf8-4::
- echo "LANG=ru_RU.UTF-8" \
+ echo "LC_ALL=ru_RU.UTF-8" \
"$(TIME) $(SED) -f $(srcdir)/$@.sed" \
"< $(srcdir)/$@.inp | $(TR) -d \\r > $@.out"; \
- LANG=ru_RU.UTF-8 \
+ LC_ALL=ru_RU.UTF-8 \
$(TIME) $(SED) -f $(srcdir)/$@.sed \
< $(srcdir)/$@.inp | $(TR) -d \\r > $@.out; \
$(CMP) $(srcdir)/$@.good $@.out && exit 0; \

View File

@ -5,17 +5,14 @@
Summary: A GNU stream text editor
Name: sed
Version: 4.2.1
Release: 10%{?dist}
Version: 4.2.2
Release: 1%{?dist}
License: GPLv3+
Group: Applications/Text
URL: http://sed.sourceforge.net/
Source0: ftp://ftp.gnu.org/pub/gnu/sed/sed-%{version}.tar.bz2
Source1: http://sed.sourceforge.net/sedfaq.txt
Patch0: sed-4.2.1-copy.patch
Patch1: sed-4.2.1-makecheck.patch
Patch2: sed-4.2.1-data-loss.patch
Patch3: sed-4.2.1-fix-0x26-on-RHS.patch
Patch0: sed-4.2.2-copy.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: glibc-devel, libselinux-devel
Requires(post): /sbin/install-info
@ -33,10 +30,7 @@ specified in a script file or from the command line.
%prep
%setup -q
%patch0 -p1
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch0 -p1 -b .copy
%build
%configure --without-included-regex
@ -77,6 +71,13 @@ rm -rf ${RPM_BUILD_ROOT}
%{_mandir}/man*/*
%changelog
* Fri Jan 04 2013 Martin Briza <mbriza@redhat.com> - 4.2.2-1
- New release
- Dropping included patches: sed-4.2.1-data-loss.patch sed-4.2.1-fix-0x26-on-RHS.patch sed-4.2.1-makecheck.patch
- Dropping unused patch sed-4.2.1-dummyparam.diff
- Regenerated sed-4.2.{1,2}-copy.patch
- Minor change to patching (creating backup files)
* Tue Jul 10 2012 Martin Briza <mbriza@redhat.com> - 4.2.1-10
- Fixed the readded -c option
Resolves: #832855

View File

@ -1 +1 @@
7d310fbd76e01a01115075c1fd3f455a sed-4.2.1.tar.bz2
7ffe1c7cdc3233e1e0c4b502df253974 sed-4.2.2.tar.bz2