Skip to content

Commit 9a36044

Browse files
committed
add rsync patch
1 parent cf61cf5 commit 9a36044

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

src/default.nix

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
, mkShellNoCC
1717
}:
1818
let
19+
# TODO: add this to nixpkgs
20+
rsync' = rsync.overrideAttrs (old: {
21+
# https://github.com/WayneD/rsync/issues/511#issuecomment-1774612577
22+
patches = [ ./rsync-fortified-strlcpy-fix.patch ];
23+
});
1924
runtimeDeps = [
2025
gitMinimal # for git flakes
2126
# pinned because nix-copy-closure hangs if ControlPath provided for SSH: https://github.com/NixOS/nix/issues/8480
@@ -26,6 +31,7 @@ let
2631
gawk
2732
findutils
2833
gnused # needed by ssh-copy-id
34+
rsync' # used to upload extra-files
2935
];
3036
in
3137
stdenv.mkDerivation {
@@ -41,12 +47,12 @@ stdenv.mkDerivation {
4147
#
4248
# We also prefer system rsync to prevent crashes between rsync and ssh.
4349
wrapProgram $out/bin/nixos-anywhere \
44-
--prefix PATH : ${lib.makeBinPath runtimeDeps} --suffix PATH : ${lib.makeBinPath [ openssh rsync ]}
50+
--prefix PATH : ${lib.makeBinPath runtimeDeps} --suffix PATH : ${lib.makeBinPath [ openssh ]}
4551
'';
4652

4753
# Dependencies for our devshell
4854
passthru.devShell = mkShellNoCC {
49-
packages = runtimeDeps ++ [ openssh rsync terraform-docs ];
55+
packages = runtimeDeps ++ [ openssh terraform-docs ];
5056
};
5157

5258
meta = with lib; {

src/rsync-fortified-strlcpy-fix.patch

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
From 1f83963f59960150e8c46112daa8411324c1f209 Mon Sep 17 00:00:00 2001
2+
From: Jiri Slaby <jslaby@suse.cz>
3+
Date: Fri, 18 Aug 2023 08:26:20 +0200
4+
Subject: [PATCH] exclude: fix crashes with fortified strlcpy()
5+
6+
Fortified (-D_FORTIFY_SOURCE=2 for gcc) builds make strlcpy() crash when
7+
its third parameter (size) is larger than the buffer:
8+
$ rsync -FFXHav '--filter=merge global-rsync-filter' Align-37-43/ xxx
9+
sending incremental file list
10+
*** buffer overflow detected ***: terminated
11+
12+
It's in the exclude code in setup_merge_file():
13+
strlcpy(y, save, MAXPATHLEN);
14+
15+
Note the 'y' pointer was incremented, so it no longer points to memory
16+
with MAXPATHLEN "owned" bytes.
17+
18+
Fix it by remembering the number of copied bytes into the 'save' buffer
19+
and use that instead of MAXPATHLEN which is clearly incorrect.
20+
21+
Fixes #511.
22+
---
23+
exclude.c | 5 +++--
24+
1 file changed, 3 insertions(+), 2 deletions(-)
25+
26+
diff --git a/exclude.c b/exclude.c
27+
index ffe55b167..1a5de3b9e 100644
28+
--- a/exclude.c
29+
+++ b/exclude.c
30+
@@ -720,7 +720,8 @@ static BOOL setup_merge_file(int mergelist_num, filter_rule *ex,
31+
parent_dirscan = True;
32+
while (*y) {
33+
char save[MAXPATHLEN];
34+
- strlcpy(save, y, MAXPATHLEN);
35+
+ /* copylen is strlen(y) which is < MAXPATHLEN. +1 for \0 */
36+
+ size_t copylen = strlcpy(save, y, MAXPATHLEN) + 1;
37+
*y = '\0';
38+
dirbuf_len = y - dirbuf;
39+
strlcpy(x, ex->pattern, MAXPATHLEN - (x - buf));
40+
@@ -734,7 +735,7 @@ static BOOL setup_merge_file(int mergelist_num, filter_rule *ex,
41+
lp->head = NULL;
42+
}
43+
lp->tail = NULL;
44+
- strlcpy(y, save, MAXPATHLEN);
45+
+ strlcpy(y, save, copylen);
46+
while ((*x++ = *y++) != '/') {}
47+
}
48+
parent_dirscan = False;
49+

0 commit comments

Comments
 (0)