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
|
@ -48,35 +48,40 @@ write_plist_file(prop_dictionary_t dict, const char *file)
|
|||
static void
|
||||
usage(void)
|
||||
{
|
||||
printf("usage: xbps-pkgdb [options] [action] [args]\n\n"
|
||||
printf("usage: xbps-pkgdb [options] [action] [args]\n"
|
||||
"\n"
|
||||
" Available actions:\n"
|
||||
" register, sanitize-plist, unregister, version\n"
|
||||
" getpkgname, getpkgversion, register, sanitize-plist\n"
|
||||
" unregister, version\n"
|
||||
"\n"
|
||||
" Action arguments:\n"
|
||||
" getpkgname\t\t<string>\n"
|
||||
" getpkgversion\t<string>\n"
|
||||
" register\t\t<pkgname> <version> <shortdesc>\n"
|
||||
" sanitize-plist\t<plist>\n"
|
||||
" unregister\t\t<pkgname> <version>\n"
|
||||
" version\t\t<pkgname>\n"
|
||||
" getpkgversion\t<string>\n"
|
||||
" getpkgname\t\t<string>\n"
|
||||
"\n"
|
||||
" Options shared by all actions:\n"
|
||||
" -r\t\t\t<rootdir>\n"
|
||||
"\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 sanitize-plist /blah/foo.plist\n"
|
||||
" $ xbps-pkgdb unregister pkgname 2.0\n"
|
||||
" $ xbps-pkgdb version pkgname\n"
|
||||
" $ xbps-pkgdb getpkgversion foo-2.0\n"
|
||||
" $ xbps-pkgdb getpkgname foo-2.0\n");
|
||||
" $ xbps-pkgdb version pkgname\n");
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
prop_dictionary_t dbdict = NULL, pkgdict;
|
||||
prop_dictionary_t dict;
|
||||
const char *version;
|
||||
char *dbfile, *pkgname, *in_chroot_env, *root = NULL;
|
||||
char *plist, *pkgname, *in_chroot_env, *root = NULL;
|
||||
bool in_chroot = false;
|
||||
int c, rv = 0;
|
||||
|
||||
|
@ -101,8 +106,8 @@ main(int argc, char **argv)
|
|||
if (argc < 1)
|
||||
usage();
|
||||
|
||||
dbfile = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
|
||||
if (dbfile == NULL) {
|
||||
plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
|
||||
if (plist == NULL) {
|
||||
printf("=> ERROR: couldn't find regpkdb file (%s)\n",
|
||||
strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -136,7 +141,7 @@ main(int argc, char **argv)
|
|||
if (argc != 3)
|
||||
usage();
|
||||
|
||||
if (!xbps_remove_pkg_dict_from_file(argv[1], dbfile)) {
|
||||
if (!xbps_remove_pkg_dict_from_file(argv[1], plist)) {
|
||||
if (errno == ENODEV)
|
||||
printf("=> ERROR: %s not registered "
|
||||
"in database.\n", argv[1]);
|
||||
|
@ -155,39 +160,41 @@ main(int argc, char **argv)
|
|||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
dbdict = prop_dictionary_internalize_from_file(dbfile);
|
||||
if (dbdict == NULL)
|
||||
dict = xbps_find_pkg_from_plist(plist, argv[1]);
|
||||
if (dict == NULL)
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
pkgdict = xbps_find_pkg_in_dict(dbdict, "packages", argv[1]);
|
||||
if (pkgdict == NULL)
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
if (!prop_dictionary_get_cstring_nocopy(pkgdict, "version",
|
||||
if (!prop_dictionary_get_cstring_nocopy(dict, "version",
|
||||
&version))
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
printf("%s\n", version);
|
||||
prop_object_release(dict);
|
||||
|
||||
} 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)
|
||||
usage();
|
||||
|
||||
dbdict = prop_dictionary_internalize_from_file(argv[1]);
|
||||
if (dbdict == NULL) {
|
||||
dict = prop_dictionary_internalize_from_file(argv[1]);
|
||||
if (dict == NULL) {
|
||||
printf("=> ERROR: couldn't sanitize %s plist file "
|
||||
"(%s)\n", argv[1], strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
write_plist_file(dbdict, argv[1]);
|
||||
write_plist_file(dict, argv[1]);
|
||||
|
||||
} else if (strcasecmp(argv[0], "getpkgversion") == 0) {
|
||||
/* Returns the version of a pkg string */
|
||||
if (argc != 2)
|
||||
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) {
|
||||
/* Returns the name of a pkg string */
|
||||
|
@ -195,6 +202,10 @@ main(int argc, char **argv)
|
|||
usage();
|
||||
|
||||
pkgname = xbps_get_pkg_name(argv[1]);
|
||||
if (pkgname == NULL) {
|
||||
printf("Invalid string, expected <string>-<version>\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("%s\n", pkgname);
|
||||
free(pkgname);
|
||||
|
||||
|
|
Loading…
Reference in New Issue