rsync icon indicating copy to clipboard operation
rsync copied to clipboard

exclude: fix crashes with fortified strlcpy()

Open jirislaby opened this issue 1 year ago • 0 comments

Fortified (-D_FORTIFY_SOURCE=2 for gcc) builds make strlcpy() crash when its third parameter (size) is larger than the buffer:

  $ rsync -FFXHav '--filter=merge global-rsync-filter' Align-37-43/ xxx
  sending incremental file list
  *** buffer overflow detected ***: terminated

It's in the exclude code in setup_merge_file():

  strlcpy(y, save, MAXPATHLEN);

Note the y pointer was incremented, so it no longer points to memory with MAXPATHLEN "owned" bytes.

Fix it by remembering the number of copied bytes into the save buffer and use that instead of MAXPATHLEN which is clearly incorrect.

Fixes #511.

jirislaby avatar Aug 18 '23 06:08 jirislaby