2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
9 #define _XOPEN_SOURCE /* glibc2 needs this */
10 #include <sys/types.h>
18 #include "solv_xmlparser.h"
19 #include "repo_updateinfoxml.h"
21 #include "tools_util.h"
25 * <update from="rel-eng@fedoraproject.org" status="stable" type="security" version="1.4">
26 * <id>FEDORA-2007-4594</id>
27 * <title>imlib-1.9.15-6.fc8</title>
28 * <severity>Important</severity>
29 * <release>Fedora 8</release>
30 * <rights>Copyright 2007 Company Inc</rights>
31 * <issued date="2007-12-28 16:42:30"/>
32 * <updated date="2008-03-14 12:00:00"/>
34 * <reference href="https://bugzilla.redhat.com/show_bug.cgi?id=426091" id="426091" title="CVE-2007-3568 imlib: infinite loop DoS using crafted BMP image" type="bugzilla"/>
36 * <description>This update includes a fix for a denial-of-service issue (CVE-2007-3568) whereby an attacker who could get an imlib-using user to view a specially-crafted BMP image could cause the user's CPU to go into an infinite loop.</description>
38 * <collection short="F8">
39 * <name>Fedora 8</name>
40 * <package arch="ppc64" name="imlib-debuginfo" release="6.fc8" src="http://download.fedoraproject.org/pub/fedora/linux/updates/8/ppc64/imlib-debuginfo-1.9.15-6.fc8.ppc64.rpm" version="1.9.15">
41 * <filename>imlib-debuginfo-1.9.15-6.fc8.ppc64.rpm</filename>
42 * <reboot_suggested>True</reboot_suggested>
76 static struct solv_xmlparser_element stateswitches[] = {
77 { STATE_START, "updates", STATE_UPDATES, 0 },
78 { STATE_START, "update", STATE_UPDATE, 0 },
79 { STATE_UPDATES, "update", STATE_UPDATE, 0 },
80 { STATE_UPDATE, "id", STATE_ID, 1 },
81 { STATE_UPDATE, "title", STATE_TITLE, 1 },
82 { STATE_UPDATE, "severity", STATE_SEVERITY, 1 },
83 { STATE_UPDATE, "rights", STATE_RIGHTS, 1 },
84 { STATE_UPDATE, "release", STATE_RELEASE, 1 },
85 { STATE_UPDATE, "issued", STATE_ISSUED, 0 },
86 { STATE_UPDATE, "updated", STATE_UPDATED, 0 },
87 { STATE_UPDATE, "description", STATE_DESCRIPTION, 1 },
88 { STATE_UPDATE, "message", STATE_MESSAGE , 1 },
89 { STATE_UPDATE, "references", STATE_REFERENCES, 0 },
90 { STATE_UPDATE, "pkglist", STATE_PKGLIST, 0 },
91 { STATE_REFERENCES, "reference", STATE_REFERENCE, 0 },
92 { STATE_PKGLIST, "collection", STATE_COLLECTION, 0 },
93 { STATE_COLLECTION, "name", STATE_NAME, 1 },
94 { STATE_COLLECTION, "package", STATE_PACKAGE, 0 },
95 { STATE_PACKAGE, "filename", STATE_FILENAME, 1 },
96 { STATE_PACKAGE, "reboot_suggested",STATE_REBOOT, 1 },
97 { STATE_PACKAGE, "restart_suggested",STATE_RESTART, 1 },
98 { STATE_PACKAGE, "relogin_suggested",STATE_RELOGIN, 1 },
111 struct solv_xmlparser xmlp;
116 * Convert date strings ("1287746075" or "2010-10-22 13:14:35")
120 datestr2timestamp(const char *date)
127 for (p = date; *p >= '0' && *p <= '9'; p++)
131 memset(&tm, 0, sizeof(tm));
132 if (!strptime(date, "%F%T", &tm))
138 * create evr (as Id) from 'epoch', 'version' and 'release' attributes
141 makeevr_atts(Pool *pool, struct parsedata *pd, const char **atts)
143 const char *e, *v, *r, *v2;
148 for (; *atts; atts += 2)
150 if (!strcmp(*atts, "epoch"))
152 else if (!strcmp(*atts, "version"))
154 else if (!strcmp(*atts, "release"))
157 if (e && (!*e || !strcmp(e, "0")))
161 for (v2 = v; *v2 >= '0' && *v2 <= '9'; v2++)
163 if (v2 > v && *v2 == ':')
174 c = space = solv_xmlparser_contentspace(&pd->xmlp, l);
196 fprintf(stderr, "evr: %s\n", space);
198 return pool_str2id(pool, space, 1);
204 startElement(struct solv_xmlparser *xmlp, int state, const char *name, const char **atts)
206 struct parsedata *pd = xmlp->userdata;
207 Pool *pool = pd->pool;
208 Solvable *solvable = pd->solvable;
213 * <update from="rel-eng@fedoraproject.org"
215 * type="bugfix" (enhancement, security)
220 const char *from = 0, *type = 0, *version = 0;
221 for (; *atts; atts += 2)
223 if (!strcmp(*atts, "from"))
225 else if (!strcmp(*atts, "type"))
227 else if (!strcmp(*atts, "version"))
230 solvable = pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo));
231 pd->handle = pd->solvable - pool->solvables;
233 solvable->vendor = pool_str2id(pool, from, 1);
234 solvable->evr = pool_str2id(pool, version, 1);
235 solvable->arch = ARCH_NOARCH;
237 repodata_set_str(pd->data, pd->handle, SOLVABLE_PATCHCATEGORY, type);
238 pd->buildtime = (time_t)0;
245 const char *date = solv_xmlparser_find_attr("date", atts);
248 time_t t = datestr2timestamp(date);
249 if (t && t > pd->buildtime)
255 case STATE_REFERENCE:
257 const char *href = 0, *id = 0, *title = 0, *type = 0;
259 for (; *atts; atts += 2)
261 if (!strcmp(*atts, "href"))
263 else if (!strcmp(*atts, "id"))
265 else if (!strcmp(*atts, "title"))
267 else if (!strcmp(*atts, "type"))
270 refhandle = repodata_new_handle(pd->data);
272 repodata_set_str(pd->data, refhandle, UPDATE_REFERENCE_HREF, href);
274 repodata_set_str(pd->data, refhandle, UPDATE_REFERENCE_ID, id);
276 repodata_set_str(pd->data, refhandle, UPDATE_REFERENCE_TITLE, title);
278 repodata_set_poolstr(pd->data, refhandle, UPDATE_REFERENCE_TYPE, type);
279 repodata_add_flexarray(pd->data, pd->handle, UPDATE_REFERENCE, refhandle);
283 /* <package arch="ppc64" name="imlib-debuginfo" release="6.fc8"
284 * src="http://download.fedoraproject.org/pub/fedora/linux/updates/8/ppc64/imlib-debuginfo-1.9.15-6.fc8.ppc64.rpm"
288 * -> patch.conflicts: {name} < {version}.{release}
292 const char *arch = 0, *name = 0;
293 Id evr = makeevr_atts(pool, pd, atts); /* parse "epoch", "version", "release" */
297 for (; *atts; atts += 2)
299 if (!strcmp(*atts, "arch"))
301 else if (!strcmp(*atts, "name"))
304 /* generated Id for name */
305 n = pool_str2id(pool, name, 1);
309 /* generate Id for arch and combine with name */
310 a = pool_str2id(pool, arch, 1);
311 rel_id = pool_rel2id(pool, n, a, REL_ARCH, 1);
313 rel_id = pool_rel2id(pool, rel_id, evr, REL_LT, 1);
314 solvable->conflicts = repo_addid_dep(pd->repo, solvable->conflicts, rel_id, 0);
316 /* who needs the collection anyway? */
317 pd->collhandle = repodata_new_handle(pd->data);
318 repodata_set_id(pd->data, pd->collhandle, UPDATE_COLLECTION_NAME, n);
319 repodata_set_id(pd->data, pd->collhandle, UPDATE_COLLECTION_EVR, evr);
321 repodata_set_id(pd->data, pd->collhandle, UPDATE_COLLECTION_ARCH, a);
333 endElement(struct solv_xmlparser *xmlp, int state, char *content)
335 struct parsedata *pd = xmlp->userdata;
336 Pool *pool = pd->pool;
337 Solvable *s = pd->solvable;
338 Repo *repo = pd->repo;
343 s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
346 repodata_set_num(pd->data, pd->handle, SOLVABLE_BUILDTIME, pd->buildtime);
347 pd->buildtime = (time_t)0;
352 s->name = pool_str2id(pool, join2(&pd->jd, "patch", ":", content), 1);
355 /* <title>imlib-1.9.15-6.fc8</title> */
357 /* strip trailing newlines */
358 while (pd->xmlp.lcontent > 0 && content[pd->xmlp.lcontent - 1] == '\n')
359 content[--pd->xmlp.lcontent] = 0;
360 repodata_set_str(pd->data, pd->handle, SOLVABLE_SUMMARY, content);
364 repodata_set_poolstr(pd->data, pd->handle, UPDATE_SEVERITY, content);
368 repodata_set_poolstr(pd->data, pd->handle, UPDATE_RIGHTS, content);
372 * <description>This update ...</description>
374 case STATE_DESCRIPTION:
375 repodata_set_str(pd->data, pd->handle, SOLVABLE_DESCRIPTION, content);
379 * <message>Warning! ...</message>
382 repodata_set_str(pd->data, pd->handle, UPDATE_MESSAGE, content);
386 repodata_add_flexarray(pd->data, pd->handle, UPDATE_COLLECTION, pd->collhandle);
390 /* <filename>libntlm-0.4.2-1.fc8.x86_64.rpm</filename> */
391 /* <filename>libntlm-0.4.2-1.fc8.x86_64.rpm</filename> */
393 repodata_set_str(pd->data, pd->collhandle, UPDATE_COLLECTION_FILENAME, content);
396 /* <reboot_suggested>True</reboot_suggested> */
398 if (content[0] == 'T' || content[0] == 't'|| content[0] == '1')
400 /* FIXME: this is per-package, the global flag should be computed at runtime */
401 repodata_set_void(pd->data, pd->handle, UPDATE_REBOOT);
402 repodata_set_void(pd->data, pd->collhandle, UPDATE_REBOOT);
406 /* <restart_suggested>True</restart_suggested> */
408 if (content[0] == 'T' || content[0] == 't'|| content[0] == '1')
410 /* FIXME: this is per-package, the global flag should be computed at runtime */
411 repodata_set_void(pd->data, pd->handle, UPDATE_RESTART);
412 repodata_set_void(pd->data, pd->collhandle, UPDATE_RESTART);
416 /* <relogin_suggested>True</relogin_suggested> */
418 if (content[0] == 'T' || content[0] == 't'|| content[0] == '1')
420 /* FIXME: this is per-package, the global flag should be computed at runtime */
421 repodata_set_void(pd->data, pd->handle, UPDATE_RELOGIN);
422 repodata_set_void(pd->data, pd->collhandle, UPDATE_RELOGIN);
431 errorCallback(struct solv_xmlparser *xmlp, const char *errstr, unsigned int line, unsigned int column)
433 struct parsedata *pd = xmlp->userdata;
434 pd->ret = pool_error(pd->pool, -1, "repo_updateinfoxml: %s at line %u:%u", errstr, line, column);
438 repo_add_updateinfoxml(Repo *repo, FILE *fp, int flags)
440 Pool *pool = repo->pool;
444 data = repo_add_repodata(repo, flags);
446 memset(&pd, 0, sizeof(pd));
450 solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement, errorCallback);
451 solv_xmlparser_parse(&pd.xmlp, fp);
452 solv_xmlparser_free(&pd.xmlp);
453 join_freemem(&pd.jd);
455 if (!(flags & REPO_NO_INTERNALIZE))
456 repodata_internalize(data);