xbps-pkgdb: check for empty strings passed to getpkg{name,version}.
--HG-- extra : convert_revision : adc73449ed57cd4628fbba91c91372d05db4e594
This commit is contained in:
parent
6f8647f5c8
commit
a2e9f7de29
1 changed files with 35 additions and 24 deletions
|
@ -48,35 +48,40 @@ write_plist_file(prop_dictionary_t dict, const char *file)
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
printf("usage: xbps-pkgdb [options] [action] [args]\n\n"
|
printf("usage: xbps-pkgdb [options] [action] [args]\n"
|
||||||
|
"\n"
|
||||||
" Available actions:\n"
|
" Available actions:\n"
|
||||||
" register, sanitize-plist, unregister, version\n"
|
" getpkgname, getpkgversion, register, sanitize-plist\n"
|
||||||
|
" unregister, version\n"
|
||||||
|
"\n"
|
||||||
" Action arguments:\n"
|
" Action arguments:\n"
|
||||||
|
" getpkgname\t\t<string>\n"
|
||||||
|
" getpkgversion\t<string>\n"
|
||||||
" register\t\t<pkgname> <version> <shortdesc>\n"
|
" register\t\t<pkgname> <version> <shortdesc>\n"
|
||||||
" sanitize-plist\t<plist>\n"
|
" sanitize-plist\t<plist>\n"
|
||||||
" unregister\t\t<pkgname> <version>\n"
|
" unregister\t\t<pkgname> <version>\n"
|
||||||
" version\t\t<pkgname>\n"
|
" version\t\t<pkgname>\n"
|
||||||
" getpkgversion\t<string>\n"
|
"\n"
|
||||||
" getpkgname\t\t<string>\n"
|
|
||||||
" Options shared by all actions:\n"
|
" Options shared by all actions:\n"
|
||||||
" -r\t\t\t<rootdir>\n"
|
" -r\t\t\t<rootdir>\n"
|
||||||
"\n"
|
"\n"
|
||||||
" Examples:\n"
|
" Examples:\n"
|
||||||
|
" $ xbps-pkgdb getpkgname foo-2.0\n"
|
||||||
|
" $ xbps-pkgdb getpkgversion foo-2.0\n"
|
||||||
" $ xbps-pkgdb register pkgname 2.0 \"A short description\"\n"
|
" $ xbps-pkgdb register pkgname 2.0 \"A short description\"\n"
|
||||||
" $ xbps-pkgdb sanitize-plist /blah/foo.plist\n"
|
" $ xbps-pkgdb sanitize-plist /blah/foo.plist\n"
|
||||||
" $ xbps-pkgdb unregister pkgname 2.0\n"
|
" $ xbps-pkgdb unregister pkgname 2.0\n"
|
||||||
" $ xbps-pkgdb version pkgname\n"
|
" $ xbps-pkgdb version pkgname\n");
|
||||||
" $ xbps-pkgdb getpkgversion foo-2.0\n"
|
|
||||||
" $ xbps-pkgdb getpkgname foo-2.0\n");
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
prop_dictionary_t dbdict = NULL, pkgdict;
|
prop_dictionary_t dict;
|
||||||
const char *version;
|
const char *version;
|
||||||
char *dbfile, *pkgname, *in_chroot_env, *root = NULL;
|
char *plist, *pkgname, *in_chroot_env, *root = NULL;
|
||||||
bool in_chroot = false;
|
bool in_chroot = false;
|
||||||
int c, rv = 0;
|
int c, rv = 0;
|
||||||
|
|
||||||
|
@ -101,8 +106,8 @@ main(int argc, char **argv)
|
||||||
if (argc < 1)
|
if (argc < 1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
dbfile = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
|
plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
|
||||||
if (dbfile == NULL) {
|
if (plist == NULL) {
|
||||||
printf("=> ERROR: couldn't find regpkdb file (%s)\n",
|
printf("=> ERROR: couldn't find regpkdb file (%s)\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -136,7 +141,7 @@ main(int argc, char **argv)
|
||||||
if (argc != 3)
|
if (argc != 3)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
if (!xbps_remove_pkg_dict_from_file(argv[1], dbfile)) {
|
if (!xbps_remove_pkg_dict_from_file(argv[1], plist)) {
|
||||||
if (errno == ENODEV)
|
if (errno == ENODEV)
|
||||||
printf("=> ERROR: %s not registered "
|
printf("=> ERROR: %s not registered "
|
||||||
"in database.\n", argv[1]);
|
"in database.\n", argv[1]);
|
||||||
|
@ -155,39 +160,41 @@ main(int argc, char **argv)
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
dbdict = prop_dictionary_internalize_from_file(dbfile);
|
dict = xbps_find_pkg_from_plist(plist, argv[1]);
|
||||||
if (dbdict == NULL)
|
if (dict == NULL)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
pkgdict = xbps_find_pkg_in_dict(dbdict, "packages", argv[1]);
|
if (!prop_dictionary_get_cstring_nocopy(dict, "version",
|
||||||
if (pkgdict == NULL)
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
|
|
||||||
if (!prop_dictionary_get_cstring_nocopy(pkgdict, "version",
|
|
||||||
&version))
|
&version))
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
printf("%s\n", version);
|
printf("%s\n", version);
|
||||||
|
prop_object_release(dict);
|
||||||
|
|
||||||
} else if (strcasecmp(argv[0], "sanitize-plist") == 0) {
|
} else if (strcasecmp(argv[0], "sanitize-plist") == 0) {
|
||||||
/* Sanitize a plist file (indent the file properly) */
|
/* Sanitize a plist file (properly indent the file) */
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
dbdict = prop_dictionary_internalize_from_file(argv[1]);
|
dict = prop_dictionary_internalize_from_file(argv[1]);
|
||||||
if (dbdict == NULL) {
|
if (dict == NULL) {
|
||||||
printf("=> ERROR: couldn't sanitize %s plist file "
|
printf("=> ERROR: couldn't sanitize %s plist file "
|
||||||
"(%s)\n", argv[1], strerror(errno));
|
"(%s)\n", argv[1], strerror(errno));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
write_plist_file(dbdict, argv[1]);
|
write_plist_file(dict, argv[1]);
|
||||||
|
|
||||||
} else if (strcasecmp(argv[0], "getpkgversion") == 0) {
|
} else if (strcasecmp(argv[0], "getpkgversion") == 0) {
|
||||||
/* Returns the version of a pkg string */
|
/* Returns the version of a pkg string */
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
printf("%s\n", xbps_get_pkg_version(argv[1]));
|
version = xbps_get_pkg_version(argv[1]);
|
||||||
|
if (version == NULL) {
|
||||||
|
printf("Invalid string, expected <string>-<version>\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
printf("%s\n", version);
|
||||||
|
|
||||||
} else if (strcasecmp(argv[0], "getpkgname") == 0) {
|
} else if (strcasecmp(argv[0], "getpkgname") == 0) {
|
||||||
/* Returns the name of a pkg string */
|
/* Returns the name of a pkg string */
|
||||||
|
@ -195,6 +202,10 @@ main(int argc, char **argv)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
pkgname = xbps_get_pkg_name(argv[1]);
|
pkgname = xbps_get_pkg_name(argv[1]);
|
||||||
|
if (pkgname == NULL) {
|
||||||
|
printf("Invalid string, expected <string>-<version>\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
printf("%s\n", pkgname);
|
printf("%s\n", pkgname);
|
||||||
free(pkgname);
|
free(pkgname);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue