opkg: Fix -Wformat-overflow warning
[oweals/opkg-lede.git] / libopkg / opkg_install.c
index e6f8a1b6276ede518a5c59b2f9347f1de8e5dd7a..27c9484cfb8189e42cbc073eaa14a67c71c3507a 100644 (file)
@@ -45,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,
@@ -57,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"
@@ -239,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;
        }
 
@@ -1250,6 +1254,8 @@ int opkg_install_pkg(pkg_t * pkg, int from_upgrade)
        char *file_sha256, *pkg_sha256;
        sigset_t newset, oldset;
        const char *local_filename;
+       long long int pkg_expected_size;
+       struct stat pkg_stat;
        time_t now;
 
        if (from_upgrade)
@@ -1361,6 +1367,30 @@ int opkg_install_pkg(pkg_t * pkg, int from_upgrade)
        }
 #endif
 
+       /* 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_md5(pkg);
        if (pkg_md5) {