3636static int
3737verify_binpkg (struct xbps_handle * xhp , xbps_dictionary_t pkgd )
3838{
39+ char binfile [PATH_MAX ];
3940 struct xbps_repo * repo ;
4041 const char * pkgver , * repoloc , * sha256 ;
41- char * binfile ;
42+ ssize_t l ;
4243 int rv = 0 ;
4344
4445 xbps_dictionary_get_cstring_nocopy (pkgd , "repository" , & repoloc );
4546 xbps_dictionary_get_cstring_nocopy (pkgd , "pkgver" , & pkgver );
4647
47- binfile = xbps_repository_pkg_path (xhp , pkgd );
48- if (binfile == NULL ) {
49- return ENOMEM ;
50- }
48+ l = xbps_pkg_path (xhp , binfile , sizeof ( binfile ) , pkgd );
49+ if (l < 0 )
50+ return - l ;
51+
5152 /*
5253 * For pkgs in local repos check the sha256 hash.
5354 * For pkgs in remote repos check the RSA signature.
@@ -56,25 +57,23 @@ verify_binpkg(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
5657 rv = errno ;
5758 xbps_dbg_printf ("%s: failed to get repository "
5859 "%s: %s\n" , pkgver , repoloc , strerror (errno ));
59- goto out ;
60+ return rv ;
6061 }
6162 if (repo -> is_remote ) {
6263 /* remote repo */
6364 xbps_set_cb_state (xhp , XBPS_STATE_VERIFY , 0 , pkgver ,
6465 "%s: verifying RSA signature..." , pkgver );
6566
6667 if (!xbps_verify_file_signature (repo , binfile )) {
67- char * sigfile ;
6868 rv = EPERM ;
6969 xbps_set_cb_state (xhp , XBPS_STATE_VERIFY_FAIL , rv , pkgver ,
7070 "%s: the RSA signature is not valid!" , pkgver );
7171 xbps_set_cb_state (xhp , XBPS_STATE_VERIFY_FAIL , rv , pkgver ,
7272 "%s: removed pkg archive and its signature." , pkgver );
7373 (void )remove (binfile );
74- sigfile = xbps_xasprintf ("%s.sig2" , binfile );
75- (void )remove (sigfile );
76- free (sigfile );
77- goto out ;
74+ if (xbps_strlcat (binfile , ".sig2" , sizeof (binfile )) < sizeof (binfile ))
75+ (void )remove (binfile );
76+ return rv ;
7877 }
7978 } else {
8079 /* local repo */
@@ -84,13 +83,12 @@ verify_binpkg(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
8483 if ((rv = xbps_file_sha256_check (binfile , sha256 )) != 0 ) {
8584 xbps_set_cb_state (xhp , XBPS_STATE_VERIFY_FAIL , rv , pkgver ,
8685 "%s: SHA256 hash is not valid: %s" , pkgver , strerror (rv ));
87- goto out ;
86+ return rv ;
8887 }
8988
9089 }
91- out :
92- free (binfile );
93- return rv ;
90+
91+ return 0 ;
9492}
9593
9694static int
0 commit comments