Skip to content
Snippets Groups Projects
Commit 9022f9e0 authored by Guillem Jover's avatar Guillem Jover
Browse files

libdpkg: Make source version parsing more robust on missing data

Even though we do not call these source version printing functions
anymore for not-installed packages, we should make the function
robust in case a call site passed pkgbin data with no source name or
version present in the Source field.

Ref: #972580
parent 536a3858
No related branches found
No related tags found
1 merge request!3Update to 1.20.9pureos1
......@@ -402,35 +402,38 @@ void
varbuf_add_source_version(struct varbuf *vb,
const struct pkginfo *pkg, const struct pkgbin *pkgbin)
{
const char *version;
size_t len;
struct dpkg_version version = DPKG_VERSION_INIT;
if (pkgbin->source)
version = strchr(pkgbin->source, '(');
else
version = NULL;
if (version == NULL) {
varbufversion(vb, &pkgbin->version, vdew_nonambig);
} else {
version++;
len = strcspn(version, ")");
varbuf_add_buf(vb, version, len);
}
pkg_source_version(&version, pkg, pkgbin);
varbufversion(vb, &version, vdew_nonambig);
varbuf_end_str(vb);
}
void
pkg_source_version(struct dpkg_version *version,
const struct pkginfo *pkg, const struct pkgbin *pkgbin)
{
struct dpkg_error err;
struct varbuf vb = VARBUF_INIT;
const char *version_str;
varbuf_add_source_version(&vb, pkg, pkgbin);
varbuf_end_str(&vb);
if (pkgbin->source)
version_str = strchr(pkgbin->source, '(');
else
version_str = NULL;
if (parseversion(version, vb.buf, &err) < 0)
ohshit(_("version '%s' has bad syntax: %s"), vb.buf, err.str);
if (version_str == NULL) {
*version = pkgbin->version;
} else {
struct dpkg_error err;
struct varbuf vb = VARBUF_INIT;
size_t len;
version_str++;
len = strcspn(version_str, ")");
varbuf_add_buf(&vb, version_str, len);
varbuf_end_str(&vb);
if (parseversion(version, vb.buf, &err) < 0)
ohshit(_("version '%s' has bad syntax: %s"),
vb.buf, err.str);
}
}
......@@ -54,6 +54,9 @@ struct dpkg_version {
#define DPKG_VERSION_OBJECT(e, v, r) \
(struct dpkg_version){ .epoch = (e), .version = (v), .revision = (r) }
#define DPKG_VERSION_INIT \
DPKG_VERSION_OBJECT(0, NULL, NULL)
/**
* Enum constants for the supported relation operations that can be done
* on Debian versions.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment