commit 0c9138f5f0e82a8761667de414d94b8842858664 Author: George Vlahavas Date: Mon Jun 20 10:56:39 2022 +0300 Use a macro for the max doinst.sh size So that we don't have to hardcode the value in different places. Also remove the hardcoded size from the check in pkgdb.c which is triggered when removing a package. diff --git a/include/pkgdb.h b/include/pkgdb.h index 0320036..9ee2465 100644 --- a/include/pkgdb.h +++ b/include/pkgdb.h @@ -45,6 +45,10 @@ G_BEGIN_DECLS #define MAXPATHLEN 8192 /**< Maximum length of the path. */ #endif +#ifndef DOINSTSH_MAX_SIZE +#define DOINSTSH_MAX_SIZE 32*1024*1024 /**< Maximum doinst.sh size (32M - should be enough) */ +#endif + /** What to get when getting package from database. */ typedef enum { DB_GET_FULL, /**< get everything */ diff --git a/src/cmd-install.c b/src/cmd-install.c index cbf242d..ca8f0b9 100644 --- a/src/cmd-install.c +++ b/src/cmd-install.c @@ -183,7 +183,7 @@ gint cmd_install(const gchar* pkgfile, const struct cmd_options* opts, struct er } else if (!strcmp(sane_path, "install/doinst.sh")) { - if (tgz->f_size > 1024*1024*32) /* 32M is enough for all. :) now, really! */ + if (tgz->f_size > DOINSTSH_MAX_SIZE) { e_set(E_ERROR, "Installation script is too big. (%ld kB)", tgz->f_size / 1024); goto err3; diff --git a/src/cmd-upgrade.c b/src/cmd-upgrade.c index 1bd0ae9..b58d947 100644 --- a/src/cmd-upgrade.c +++ b/src/cmd-upgrade.c @@ -310,7 +310,7 @@ gint cmd_upgrade(const gchar* pkgfile, const struct cmd_options* opts, struct er } else if (!strcmp(sane_path, "install/doinst.sh")) { - if (tgz->f_size > 1024*1024*32) /* 32M is enough for all. :) now, really! */ + if (tgz->f_size > DOINSTSH_MAX_SIZE) { e_set(E_ERROR, "Installation script is too big. (%ld kB)", tgz->f_size / 1024); goto err3; diff --git a/src/pkgdb.c b/src/pkgdb.c index d8a5ffd..4ad7fcf 100644 --- a/src/pkgdb.c +++ b/src/pkgdb.c @@ -861,7 +861,7 @@ struct db_pkg* db_get_pkg(gchar* name, db_get_type type) fseek(fs, 0, SEEK_END); guint script_size = ftell(fs); - if (script_size > 4*1024*1024) + if (script_size > DOINSTSH_MAX_SIZE) { e_set(E_ERROR, "Script file is too big %s. (%u kB)", p->name, script_size / 1024); goto err_1;