From ea07a9e5d1a0855af138e6ec606e7c269ec9a921 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 15 Aug 2020 13:19:00 -0700 Subject: [PATCH] receiving: enforce $Girocco::Config::max_file_size512 When running receive-pack, enforce the new $Girocco::Config::max_file_size512 file size limit. Signed-off-by: Kyle J. McKay --- bin/git-http-backend-verify | 15 +++++++++++---- bin/git-shell-verify | 10 ++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/bin/git-http-backend-verify b/bin/git-http-backend-verify index cb0523d..c5379e3 100755 --- a/bin/git-http-backend-verify +++ b/bin/git-http-backend-verify @@ -377,6 +377,13 @@ if ! [ -f "$dir/.nofetch" ]; then exit 1 fi +# Set up the correct backend command depending on cfg_max_file_size512 +if [ "${cfg_max_file_size512:-0}" = "0" ]; then + GIT_HTTP_BACKEND='"$cfg_git_http_backend_bin"' +else + GIT_HTTP_BACKEND='"$cfg_basedir/bin/ulimit512" -i -f "$cfg_max_file_size512" -- "$cfg_git_http_backend_bin"' +fi + git_add_config 'receive.unpackLimit=1' # Note the git config documentation is wrong # transfer.unpackLimit, if set, overrides receive.unpackLimit @@ -421,9 +428,9 @@ if ! "$cfg_basedir/bin/can_user_push_http" "$projbare" "$authuser"; then PATH_INFO="/$proj/mob/$suffix" export PATH_INFO if [ -n "$GIT_HTTP_BACKEND_SHOW_ERRORS" ]; then - exec "$cfg_git_http_backend_bin" "$@" + eval 'exec '"$GIT_HTTP_BACKEND"' "$@"' else - exec "$cfg_git_http_backend_bin" "$@" 2>/dev/null + eval 'exec '"$GIT_HTTP_BACKEND"' "$@" 2>/dev/null' fi internalerr "exec failed: $cfg_git_http_backend_bin" exit 1 @@ -440,9 +447,9 @@ fi ! [ -e "$dir/.delaygc" ] || >"$dir/.allowgc" || : ) if [ -n "$GIT_HTTP_BACKEND_SHOW_ERRORS" ]; then - exec "$cfg_git_http_backend_bin" "$@" + eval 'exec '"$GIT_HTTP_BACKEND"' "$@"' else - exec "$cfg_git_http_backend_bin" "$@" 2>/dev/null + eval 'exec '"$GIT_HTTP_BACKEND"' "$@" 2>/dev/null' fi internalerr "exec failed: $cfg_git_http_backend_bin" exit 1 diff --git a/bin/git-shell-verify b/bin/git-shell-verify index b4cdd88..d85d16b 100755 --- a/bin/git-shell-verify +++ b/bin/git-shell-verify @@ -48,6 +48,7 @@ var_big_file_threshold=@big_file_threshold@ var_upload_window=@upload_pack_window@ cfg_fetch_stash_refs=@fetch_stash_refs@ cfg_suppress_git_ssh_logging=@suppress_git_ssh_logging@ +cfg_max_file_size512=@max_file_size512@ export XDG_CONFIG_HOME export HOME @@ -245,11 +246,16 @@ if [ "$type" = 'receive-pack' ] && ! [ -f "$dir/.nofetch" ]; then exit 3 fi +GIT_SHELL='git-shell' if [ "$type" = 'receive-pack' ]; then git_add_config 'receive.unpackLimit=1' # Note the git config documentation is wrong # transfer.unpackLimit, if set, overrides receive.unpackLimit git_add_config 'transfer.unpackLimit=1' + # set up the correct git-shell command if cfg_max_file_size512 > 0 + if [ "${cfg_max_file_size512:-0}" != "0" ]; then + GIT_SHELL='ulimit512 -i -f "$cfg_max_file_size512" -- git-shell' + fi fi if ! [ -x @perlbin@ ] && [ "$type" = 'receive-pack' ]; then @@ -268,7 +274,7 @@ if ! [ -x @perlbin@ ] && [ "$type" = 'receive-pack' ]; then ! [ -e "$dir/.delaygc" ] || >"$dir/.allowgc" || : ) logmsg "accepted $type $odir mob" - exec git-shell -c "git-receive-pack '$reporoot/$proj/mob'" + eval 'exec '"$GIT_SHELL"' -c "git-receive-pack '\''$reporoot/$proj/mob'\''"' exit 1 fi logmsg "denied $type $odir noperms" @@ -288,5 +294,5 @@ fi git_add_config "pack.window=$var_upload_window" logmsg "accepted $type $odir" -exec git-shell -c "git-$type '$dir'" +eval 'exec '"$GIT_SHELL"' -c "git-$type '\''$dir'\''"' exit 1 -- 2.11.4.GIT