Skip to content

Commit 3ace245

Browse files
committed
bin/xbps-create: verify that "provides" are valid pkgver's
1 parent 1aa8f0c commit 3ace245

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

bin/xbps-create/main.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,14 @@ entry_type_str(enum entry_type type)
184184
diex("unknown entry type");
185185
}
186186

187+
static bool
188+
validate_pkgver(const char *pkgver)
189+
{
190+
return xbps_pkg_version(pkgver) != NULL;
191+
}
192+
187193
static void
188-
process_array(const char *key, const char *val)
194+
process_array(const char *key, const char *val, bool (*validate)(const char *s))
189195
{
190196
xbps_array_t array = NULL;
191197
char *args, *p = NULL, *saveptr = NULL;
@@ -200,16 +206,22 @@ process_array(const char *key, const char *val)
200206
die("xbps_array_create");
201207

202208
if (strchr(val, ' ') == NULL) {
209+
if (validate && !validate(val)) {
210+
diex("%s: invalid value: %s", key, val);
211+
}
203212
xbps_array_add_cstring_nocopy(array, val);
204213
goto out;
205214
}
206215

207-
args = strdup(val);
216+
args = strdup(val);
208217
if (args == NULL)
209218
die("strdup");
210219

211220
for ((p = strtok_r(args, " ", &saveptr)); p;
212221
(p = strtok_r(NULL, " ", &saveptr))) {
222+
if (validate && !validate(p)) {
223+
diex("%s: invalid value: %s", key, p);
224+
}
213225
xbps_array_add_cstring(array, p);
214226
}
215227
free(args);
@@ -991,6 +1003,7 @@ main(int argc, char **argv)
9911003
diex("short description not set!");
9921004
else if (arch == NULL)
9931005
diex("architecture not set!");
1006+
9941007
/*
9951008
* Sanity check for required options.
9961009
*/
@@ -1053,14 +1066,14 @@ main(int argc, char **argv)
10531066
"changelog", changelog);
10541067

10551068
/* Optional arrays */
1056-
process_array("run_depends", deps);
1057-
process_array("conf_files", config_files);
1058-
process_array("conflicts", conflicts);
1059-
process_array("provides", provides);
1060-
process_array("replaces", replaces);
1061-
process_array("reverts", reverts);
1062-
process_array("shlib-provides", shlib_provides);
1063-
process_array("shlib-requires", shlib_requires);
1069+
process_array("run_depends", deps, NULL);
1070+
process_array("conf_files", config_files, NULL);
1071+
process_array("conflicts", conflicts, NULL);
1072+
process_array("provides", provides, validate_pkgver);
1073+
process_array("replaces", replaces, NULL);
1074+
process_array("reverts", reverts, NULL);
1075+
process_array("shlib-provides", shlib_provides, NULL);
1076+
process_array("shlib-requires", shlib_requires, NULL);
10641077
process_dict_of_arrays("alternatives", alternatives);
10651078

10661079
/* save cwd */

0 commit comments

Comments
 (0)