diff mbox

[pacman-dev] libmakepkg/integrity: fix regression that broke --install

Message ID 20180305153638.5695-1-eschwartz@archlinux.org
State Superseded, archived
Headers show

Commit Message

Eli Schwartz March 5, 2018, 3:36 p.m. UTC
In commit c6b04c04653ba9933fe978829148312e412a9ea7 package signing was
moved out of fakeroot, and as part of this process, the global pkgname
variable was modified in order to extract the built package names.

However, if a debug package was not available and added to the list of
packages, the function was aborted early, before the pkgname array was
restored, thereby corrupting the later stages of makepkg and
specifically the install_package function which needs to know which
pkgnames to install.

Fix this by inlining the debug package signing inside the `if` check,
and as added security switch to using `for pkg in "${pkgname[@]}"` as is
done in many other parts of makepkg, since package signing does not
depend on the value of pkgname for anything.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
---
 .../libmakepkg/integrity/generate_signature.sh.in    | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

Comments

Eli Schwartz March 5, 2018, 3:41 p.m. UTC | #1
On 03/05/2018 10:36 AM, Eli Schwartz wrote:
> -	local pkgarch pkg_file
> +	local pkg pkgarch pkg_file
>  	local pkgname_backup=("${pkgname[@]}")
>  	local fullver=$(get_full_version)
>  
>  	msg "$(gettext "Signing package(s)...")"
>  
> -	for pkgname in ${pkgname_backup[@]}; do
> -		pkgarch=$(get_pkg_arch $pkgname)
> -		pkg_file="$PKGDEST/${pkgname}-${fullver}-${pkgarch}${PKGEXT}"
> +	for pkg in "${pkgname[@]}"; do
> +		pkgarch=$(get_pkg_arch $pkg)
> +		pkg_file="$PKGDEST/${pkg}-${fullver}-${pkgarch}${PKGEXT}"
>  
>  		create_signature "$pkg_file"
>  	done
>  
>  	# check if debug package needs a signature
>  	if ! check_option "debug" "y" || ! check_option "strip" "y"; then
BTW any reason we even need to do all this instead of, say, using
print_all_package_names

We could probably do that both here and in install_package, especially
if/when "makepkg --packagelist: just list the built package files we
will build" is accepted.

See? This patch is even useful for makepkg itself, why would we ever not
want it. :p
Allan McRae March 14, 2018, 5:34 a.m. UTC | #2
On 06/03/18 01:36, Eli Schwartz wrote:
> In commit c6b04c04653ba9933fe978829148312e412a9ea7 package signing was
> moved out of fakeroot, and as part of this process, the global pkgname
> variable was modified in order to extract the built package names.
> 
> However, if a debug package was not available and added to the list of
> packages, the function was aborted early, before the pkgname array was
> restored, thereby corrupting the later stages of makepkg and
> specifically the install_package function which needs to know which
> pkgnames to install.
> 
> Fix this by inlining the debug package signing inside the `if` check,
> and as added security switch to using `for pkg in "${pkgname[@]}"` as is
> done in many other parts of makepkg, since package signing does not
> depend on the value of pkgname for anything.
> 
> Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
> ---
>  .../libmakepkg/integrity/generate_signature.sh.in    | 20 ++++++++------------
>  1 file changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/scripts/libmakepkg/integrity/generate_signature.sh.in b/scripts/libmakepkg/integrity/generate_signature.sh.in
> index 8bb69984..c8b938ab 100644
> --- a/scripts/libmakepkg/integrity/generate_signature.sh.in
> +++ b/scripts/libmakepkg/integrity/generate_signature.sh.in
> @@ -50,28 +50,24 @@ create_package_signatures() {
>  	if [[ $SIGNPKG != 'y' ]]; then
>  		return 0
>  	fi
> -	local pkgarch pkg_file
> +	local pkg pkgarch pkg_file
>  	local pkgname_backup=("${pkgname[@]}")

This variable is no longer needed.

>  	local fullver=$(get_full_version)
>  
>  	msg "$(gettext "Signing package(s)...")"
>  
> -	for pkgname in ${pkgname_backup[@]}; do
> -		pkgarch=$(get_pkg_arch $pkgname)
> -		pkg_file="$PKGDEST/${pkgname}-${fullver}-${pkgarch}${PKGEXT}"
> +	for pkg in "${pkgname[@]}"; do
> +		pkgarch=$(get_pkg_arch $pkg)
> +		pkg_file="$PKGDEST/${pkg}-${fullver}-${pkgarch}${PKGEXT}"
>  
>  		create_signature "$pkg_file"
>  	done
>  
>  	# check if debug package needs a signature
>  	if ! check_option "debug" "y" || ! check_option "strip" "y"; then
> -		return
> +		pkg=$pkgbase-@DEBUGSUFFIX@
> +		pkgarch=$(get_pkg_arch)
> +		pkg_file="$PKGDEST/${pkg}-${fullver}-${pkgarch}${PKGEXT}"

We should check this file exists.   The create_signature function will
still fail when the package is not there, which can happen if there is
no binaries in the package. (e.g. arch=any packages).

> +		create_signature "$pkg_file"
>  	fi
> -
> -	pkgname=$pkgbase-@DEBUGSUFFIX@
> -	pkgarch=$(get_pkg_arch)
> -	pkg_file="$PKGDEST/${pkgname}-${fullver}-${pkgarch}${PKGEXT}"
> -	create_signature "$pkg_file"
> -
> -	pkgname=("${pkgname_backup[@]}")
>  }
>
Eli Schwartz March 15, 2018, 12:37 a.m. UTC | #3
On 03/14/2018 01:34 AM, Allan McRae wrote:
>>  	# check if debug package needs a signature
>>  	if ! check_option "debug" "y" || ! check_option "strip" "y"; then
>> -		return
>> +		pkg=$pkgbase-@DEBUGSUFFIX@
>> +		pkgarch=$(get_pkg_arch)
>> +		pkg_file="$PKGDEST/${pkg}-${fullver}-${pkgarch}${PKGEXT}"
> 
> We should check this file exists.   The create_signature function will
> still fail when the package is not there, which can happen if there is
> no binaries in the package. (e.g. arch=any packages).

True -- looks like this was broken for a while now (before
create_package_signatures this was actually run inside the debug
packaging run).
diff mbox

Patch

diff --git a/scripts/libmakepkg/integrity/generate_signature.sh.in b/scripts/libmakepkg/integrity/generate_signature.sh.in
index 8bb69984..c8b938ab 100644
--- a/scripts/libmakepkg/integrity/generate_signature.sh.in
+++ b/scripts/libmakepkg/integrity/generate_signature.sh.in
@@ -50,28 +50,24 @@  create_package_signatures() {
 	if [[ $SIGNPKG != 'y' ]]; then
 		return 0
 	fi
-	local pkgarch pkg_file
+	local pkg pkgarch pkg_file
 	local pkgname_backup=("${pkgname[@]}")
 	local fullver=$(get_full_version)
 
 	msg "$(gettext "Signing package(s)...")"
 
-	for pkgname in ${pkgname_backup[@]}; do
-		pkgarch=$(get_pkg_arch $pkgname)
-		pkg_file="$PKGDEST/${pkgname}-${fullver}-${pkgarch}${PKGEXT}"
+	for pkg in "${pkgname[@]}"; do
+		pkgarch=$(get_pkg_arch $pkg)
+		pkg_file="$PKGDEST/${pkg}-${fullver}-${pkgarch}${PKGEXT}"
 
 		create_signature "$pkg_file"
 	done
 
 	# check if debug package needs a signature
 	if ! check_option "debug" "y" || ! check_option "strip" "y"; then
-		return
+		pkg=$pkgbase-@DEBUGSUFFIX@
+		pkgarch=$(get_pkg_arch)
+		pkg_file="$PKGDEST/${pkg}-${fullver}-${pkgarch}${PKGEXT}"
+		create_signature "$pkg_file"
 	fi
-
-	pkgname=$pkgbase-@DEBUGSUFFIX@
-	pkgarch=$(get_pkg_arch)
-	pkg_file="$PKGDEST/${pkgname}-${fullver}-${pkgarch}${PKGEXT}"
-	create_signature "$pkg_file"
-
-	pkgname=("${pkgname_backup[@]}")
 }