opkg: Fix -Wformat-overflow warning
[project/opkg-lede.git] / libopkg / opkg_install.c
index 55c124b3797f4c0c9737d5fa33628e7b0ab3760d..27c9484cfb8189e42cbc073eaa14a67c71c3507a 100644 (file)
@@ -15,8 +15,6 @@
    General Public License for more details.
 */
 
-#include "config.h"
-
 #include <stdio.h>
 #include <time.h>
 #include <signal.h>
@@ -47,7 +45,7 @@ static int satisfy_dependencies_for(pkg_t * pkg)
        int i, err;
        pkg_vec_t *depends = pkg_vec_alloc();
        pkg_t *dep;
-       char **tmp, **unresolved = NULL;
+       char **tmp, **unresolved = NULL, *prev = NULL;
        int ndepends;
 
        ndepends = pkg_hash_fetch_unsatisfied_dependencies(pkg, depends,
@@ -59,12 +57,17 @@ static int satisfy_dependencies_for(pkg_t * pkg)
                         pkg->name);
                tmp = unresolved;
                while (*unresolved) {
-                       opkg_message(ERROR, "\t%s", *unresolved);
+                       if (!prev || strcmp(*unresolved, prev))
+                               opkg_message(ERROR, "\t%s\n", *unresolved);
+                       prev = *unresolved;
+                       unresolved++;
+               }
+               unresolved = tmp;
+               while (*unresolved) {
                        free(*unresolved);
                        unresolved++;
                }
                free(tmp);
-               opkg_message(ERROR, "\n");
                if (!conf->force_depends) {
                        opkg_msg(INFO,
                                 "This could mean that your package list is out of date or that the packages\n"
@@ -241,8 +244,7 @@ static int unpack_pkg_control_files(pkg_t * pkg)
 
        tmp_unpack_dir = mkdtemp(tmp_unpack_dir);
        if (tmp_unpack_dir == NULL) {
-               opkg_perror(ERROR, "Failed to create temporary directory '%s'",
-                           tmp_unpack_dir);
+               opkg_perror(ERROR, "Failed to create temporary directory");
                return -1;
        }
 
@@ -886,8 +888,6 @@ static int check_data_file_clashes_change(pkg_t * pkg, pkg_t * old_pkg)
        str_list_t *files_list;
        str_list_elt_t *iter, *niter;
 
-       char *root_filename = NULL;
-
        files_list = pkg_get_installed_files(pkg);
        if (files_list == NULL)
                return -1;
@@ -896,12 +896,7 @@ static int check_data_file_clashes_change(pkg_t * pkg, pkg_t * old_pkg)
             str_list_next(files_list, iter); iter;
             iter = niter, niter = str_list_next(files_list, niter)) {
                char *filename = (char *)iter->data;
-               if (root_filename) {
-                       free(root_filename);
-                       root_filename = NULL;
-               }
-               root_filename = root_filename_alloc(filename);
-               if (file_exists(root_filename) && (!file_is_dir(root_filename))) {
+               if (file_exists(filename) && (!file_is_dir(filename))) {
                        pkg_t *owner;
 
                        owner = file_hash_get_file_owner(filename);
@@ -928,10 +923,6 @@ static int check_data_file_clashes_change(pkg_t * pkg, pkg_t * old_pkg)
 
                }
        }
-       if (root_filename) {
-               free(root_filename);
-               root_filename = NULL;
-       }
        pkg_free_installed_files(pkg);
 
        return 0;
@@ -1092,13 +1083,6 @@ static int install_data_files(pkg_t * pkg)
                return err;
        }
 
-       /* The "Essential" control field may only be present in the control
-        * file and not in the Packages list. Ensure we capture it regardless.
-        *
-        * XXX: This should be fixed outside of opkg, in the Package list.
-        */
-       set_flags_from_control(pkg);
-
        opkg_msg(DEBUG, "Calling pkg_write_filelist.\n");
        err = pkg_write_filelist(pkg);
        if (err)
@@ -1151,15 +1135,12 @@ static int resolve_conffiles(pkg_t * pkg)
 
                if (file_exists(cf_backup)) {
                        /* Let's compute md5 to test if files are changed */
-#ifdef HAVE_MD5
                        if (cf->value && strlen(cf->value) > 33) {
                                chksum = file_sha256sum_alloc(cf_backup);
                        } else {
                                chksum = file_md5sum_alloc(cf_backup);
                        }
-#else
-                       chksum = file_sha256sum_alloc(cf_backup);
-#endif
+
                        if (chksum && cf->value
                            && strcmp(cf->value, chksum) != 0) {
                                if (conf->force_maintainer) {
@@ -1270,11 +1251,11 @@ int opkg_install_pkg(pkg_t * pkg, int from_upgrade)
        abstract_pkg_t *ab_pkg = NULL;
        int old_state_flag;
        char *file_md5, *pkg_md5;
-#ifdef HAVE_SHA256
        char *file_sha256, *pkg_sha256;
-#endif
        sigset_t newset, oldset;
        const char *local_filename;
+       long long int pkg_expected_size;
+       struct stat pkg_stat;
        time_t now;
 
        if (from_upgrade)
@@ -1285,7 +1266,7 @@ int opkg_install_pkg(pkg_t * pkg, int from_upgrade)
        if (!pkg_arch_supported(pkg)) {
                opkg_msg(ERROR,
                         "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
-                        pkg_get_string(pkg, PKG_ARCHITECTURE), pkg->name);
+                        pkg_get_architecture(pkg), pkg->name);
                return -1;
        }
        if (pkg->state_status == SS_INSTALLED && conf->nodeps == 0) {
@@ -1351,7 +1332,7 @@ int opkg_install_pkg(pkg_t * pkg, int from_upgrade)
        }
 
        /* check that the repository is valid */
-#if defined(HAVE_GPGME) || defined(HAVE_OPENSSL) || defined(HAVE_USIGN)
+#if defined(HAVE_USIGN)
        char *list_file_name, *sig_file_name, *lists_dir;
 
        /* check to ensure the package has come from a repository */
@@ -1386,9 +1367,32 @@ int opkg_install_pkg(pkg_t * pkg, int from_upgrade)
        }
 #endif
 
-#ifdef HAVE_MD5
+       /* Check file size */
+       err = lstat(local_filename, &pkg_stat);
+
+       if (err) {
+               opkg_msg(ERROR, "Failed to stat %s: %s\n",
+                        local_filename, strerror(errno));
+               return -1;
+       }
+
+       pkg_expected_size = pkg_get_int(pkg, PKG_SIZE);
+
+       if (pkg_expected_size > 0 && pkg_stat.st_size != pkg_expected_size) {
+               if (!conf->force_checksum) {
+                       opkg_msg(ERROR,
+                                "Package size mismatch: %s is %lld bytes, expecting %lld bytes\n",
+                                pkg->name, (long long int)pkg_stat.st_size, pkg_expected_size);
+                       return -1;
+               } else {
+                       opkg_msg(NOTICE,
+                                "Ignored %s size mismatch.\n",
+                                pkg->name);
+               }
+       }
+
        /* Check for md5 values */
-       pkg_md5 = pkg_get_string(pkg, PKG_MD5SUM);
+       pkg_md5 = pkg_get_md5(pkg);
        if (pkg_md5) {
                file_md5 = file_md5sum_alloc(local_filename);
                if (file_md5 && strcmp(file_md5, pkg_md5)) {
@@ -1407,11 +1411,9 @@ int opkg_install_pkg(pkg_t * pkg, int from_upgrade)
                if (file_md5)
                        free(file_md5);
        }
-#endif
 
-#ifdef HAVE_SHA256
        /* Check for sha256 value */
-       pkg_sha256 = pkg_get_string(pkg, PKG_SHA256SUM);
+       pkg_sha256 = pkg_get_sha256(pkg);
        if (pkg_sha256) {
                file_sha256 = file_sha256sum_alloc(local_filename);
                if (file_sha256 && strcmp(file_sha256, pkg_sha256)) {
@@ -1431,7 +1433,7 @@ int opkg_install_pkg(pkg_t * pkg, int from_upgrade)
                if (file_sha256)
                        free(file_sha256);
        }
-#endif
+
        if (conf->download_only) {
                if (conf->nodeps == 0) {
                        err = satisfy_dependencies_for(pkg);