From patchwork Wed May 10 09:52:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 6846 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4QGVgM02t7z3wk1 for ; Wed, 10 May 2023 09:52:14 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4QGVgJ5GcZzv6; Wed, 10 May 2023 09:52:12 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4QGVgJ3fH1z2ylF; Wed, 10 May 2023 09:52:12 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4QGVgG4M4nz2xHt for ; Wed, 10 May 2023 09:52:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4QGVgF5KpRzkj; Wed, 10 May 2023 09:52:09 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1683712330; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=CVL9HRUqryhioogJi+ixC77p558snPHMAnDzGfZOMpA=; b=8HQyxIaqoSrHQxhy23fN7qQWiFxWqruzrq0ov+UOSuS3ZunPMq0Q1ItAHcOECNfHHig6dB 4PadX1BfZfVD5dAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1683712330; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=CVL9HRUqryhioogJi+ixC77p558snPHMAnDzGfZOMpA=; b=UtnUaflSQnz6UVu81b4hXnI9mtlL5fgqPmExoCGWzgnbOx3wpo6AQ3OZjStm3oW6ERqOq7 pX52YIGq+cOdctiZzP1E0PALQUiIwml1//UpmzgAWUs40yVAXXC9d3mElabjlQRwpATYBM cqH9zCVEg78pvbN6M4U1+8sKC+yoFNMioL1XbsfHZNHcxu0lYWg8ZSdnZ4TVP7aCGqL670 9BpOH/i83jnw75VfIw7+uljn9mHjr7YTkCbOUe6fVDkR6gUFEXa2ZSzbmR4hss5YKBFVcf VxJ275H5ghERILG36Aa+9iKdpm9l9znI0+hicCknF+z/sQ64xHaCG8/IAgcB4Q== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH] backup.cgi: Read and deliver the requested backup in pieces Date: Wed, 10 May 2023 11:52:03 +0200 Message-Id: <20230510095203.2567-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Read-in the requested backup file line by line and directly deliver this as stream to the client. This fixes the problem with very big backups on systems with very limited RAM, which resulted in an OOM kill of the CGI and delivery process. Fixes #13096. Signed-off-by: Stefan Schantl Reviewed-by: Michael Tremer --- html/cgi-bin/backup.cgi | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/html/cgi-bin/backup.cgi b/html/cgi-bin/backup.cgi index 1c01cb286..3888ccbff 100644 --- a/html/cgi-bin/backup.cgi +++ b/html/cgi-bin/backup.cgi @@ -366,6 +366,13 @@ sub deliver_file() { # Deliver content open(FILE, "<$file") or die "Unable to open $file: $!"; - print ; + + # Read the file line by line and send it + # to the client. + while () { + print $_; + } + + # Close file handle. close(FILE); }