[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
46/376: Fix use of sysread
From: |
Ludovic Courtès |
Subject: |
46/376: Fix use of sysread |
Date: |
Wed, 28 Jan 2015 22:03:57 +0000 |
civodul pushed a commit to tag 1.8
in repository guix.
commit 42d91b079c5d0b468663511e7b2a8e2f4048c475
Author: Eelco Dolstra <address@hidden>
Date: Thu Jul 10 21:14:34 2014 +0200
Fix use of sysread
---
perl/lib/Nix/CopyClosure.pm | 24 ++++++++++++++++++------
1 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/perl/lib/Nix/CopyClosure.pm b/perl/lib/Nix/CopyClosure.pm
index 779d743..8be4ead 100644
--- a/perl/lib/Nix/CopyClosure.pm
+++ b/perl/lib/Nix/CopyClosure.pm
@@ -7,11 +7,24 @@ use List::Util qw(sum);
use IPC::Open2;
+sub readN {
+ my ($bytes, $from) = @_;
+ my $res = "";
+ while ($bytes > 0) {
+ my $s;
+ my $n = sysread($from, $s, $bytes);
+ die "I/O error reading from remote side\n" if !defined $n;
+ die "got EOF while expecting $bytes bytes from remote side\n" if !$n;
+ $bytes -= $n;
+ $res .= $s;
+ }
+ return $res;
+}
+
+
sub readInt {
my ($from) = @_;
- my $resp;
- sysread($from, $resp, 8) == 8 or die "did not receive valid reply from
remote host\n";
- return unpack("L<x4", $resp);
+ return unpack("L<x4", readN(8, $from));
}
@@ -66,10 +79,9 @@ sub copyTo {
my $n = readInt($from);
while ($n--) {
my $len = readInt($from);
- my $s;
- sysread($from, $s, $len) == $len or die;
+ my $s = readN($len, $from);
$present{$s} = 1;
- sysread($from, $s, 8 - $len % 8) if $len % 8; # skip padding
+ readN(8 - $len % 8, $from) if $len % 8; # skip padding
}
my @missing = grep { !$present{$_} } @closure;
- 36/376: Fix compilation error on some versions of GCC, (continued)
- 36/376: Fix compilation error on some versions of GCC, Ludovic Courtès, 2015/01/28
- 37/376: Add a test for the SSH substituter, Ludovic Courtès, 2015/01/28
- 38/376: Fix security hole in ‘nix-store --serve’, Ludovic Courtès, 2015/01/28
- 35/376: Don't build on Ubuntu 10.10, Ludovic Courtès, 2015/01/28
- 34/376: Add builtin function ‘fromJSON’, Ludovic Courtès, 2015/01/28
- 41/376: nix-copy-closure: Restore compression and the progress viewer, Ludovic Courtès, 2015/01/28
- 40/376: Remove maybeVfork, Ludovic Courtès, 2015/01/28
- 39/376: nix-copy-closure: Fix race condition, Ludovic Courtès, 2015/01/28
- 23/376: findFile: Realise the context of the path attributes, Ludovic Courtès, 2015/01/28
- 44/376: nix-copy-closure: Fix --dry-run, Ludovic Courtès, 2015/01/28
- 46/376: Fix use of sysread,
Ludovic Courtès <=
- 45/376: nix-copy-closure -s: Do substitutions via ‘nix-store --serve’, Ludovic Courtès, 2015/01/28
- 48/376: Fix broken Pid constructor, Ludovic Courtès, 2015/01/28
- 42/376: Refactoring: Move all fork handling into a higher-order function, Ludovic Courtès, 2015/01/28
- 49/376: Allow $NIX_BUILD_HOOK to be relative to Nix libexec directory, Ludovic Courtès, 2015/01/28
- 52/376: Fix test, Ludovic Courtès, 2015/01/28
- 54/376: build-remote.pl: Don't keep a shell process around, Ludovic Courtès, 2015/01/28
- 55/376: build-remote.pl: Fix building multiple output derivations, Ludovic Courtès, 2015/01/28
- 47/376: Replace message "importing path <...>" with "exporting path <...>", Ludovic Courtès, 2015/01/28
- 58/376: Pass *_proxy vars to bootstrap fetchurl, Ludovic Courtès, 2015/01/28
- 51/376: build-remote.pl: Use ‘nix-store --serve’ on the remote side, Ludovic Courtès, 2015/01/28