Compare commits

...

2 Commits
master ... f14

Author SHA1 Message Date
Vojtech Vitek (V-Teq) 06799d1827 Release sed-4.2.1-6 2011-07-12 16:20:28 +02:00
Vojtech Vitek (V-Teq) d9860895ac 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>

Conflicts:

	sed.spec
2011-07-12 16:19:45 +02:00
2 changed files with 65 additions and 1 deletions

58
sed-4.2.1-data-loss.patch Normal file
View File

@ -0,0 +1,58 @@
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

@ -6,7 +6,7 @@
Summary: A GNU stream text editor
Name: sed
Version: 4.2.1
Release: 5%{?dist}
Release: 6%{?dist}
License: GPLv3+
Group: Applications/Text
URL: http://sed.sourceforge.net/
@ -14,6 +14,7 @@ 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
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: glibc-devel, libselinux-devel
Requires(post): /sbin/install-info
@ -30,6 +31,7 @@ specified in a script file or from the command line.
%setup -q
%patch0 -p1
%patch1 -p1
%patch2 -p1
%build
%configure --without-included-regex
@ -70,6 +72,10 @@ rm -rf ${RPM_BUILD_ROOT}
%{_mandir}/man*/*
%changelog
* Tue Jul 12 2011 Vojtech Vitek (V-Teq) <vvitek@redhat.com> - 4.2.1-6
- avoid silent data loss when an input line is 2^31 bytes or longer
Resolves: #720438
* Wed Mar 17 2010 Jan Görig <jgorig@redhat.com> 4.2.1-5
- fixed make check on non UTF-8 locale - upstream patch rhbz#550731
- readded -c option (thanks Paolo Bonzini) rhbz#566455