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>
This commit is contained in:
parent
aaa42f23ef
commit
33a815d107
|
@ -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
|
||||
|
5
sed.spec
5
sed.spec
|
@ -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,9 @@ rm -rf ${RPM_BUILD_ROOT}
|
|||
%{_mandir}/man*/*
|
||||
|
||||
%changelog
|
||||
- avoid silent data loss when an input line is 2^31 bytes or longer
|
||||
Resolves: #720438
|
||||
|
||||
* Wed Feb 09 2011 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 4.2.1-6
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild
|
||||
|
||||
|
|
Loading…
Reference in New Issue