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>
21 #include "repo_updateinfoxml.h"
23 #include "tools_util.h"
27 * <update from="rel-eng@fedoraproject.org" status="stable" type="security" version="1.4">
28 * <id>FEDORA-2007-4594</id>
29 * <title>imlib-1.9.15-6.fc8</title>
30 * <release>Fedora 8</release>
31 * <issued date="2007-12-28 16:42:30"/>
33 * <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"/>
35 * <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>
37 * <collection short="F8">
38 * <name>Fedora 8</name>
39 * <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">
40 * <filename>imlib-debuginfo-1.9.15-6.fc8.ppc64.rpm</filename>
41 * <reboot_suggested>True</reboot_suggested>
51 STATE_UPDATES, /* 1 */
55 STATE_RELEASE, /* 5 */
57 STATE_MESSAGE, /* 7 */
58 STATE_REFERENCES, /* 8 */
59 STATE_REFERENCE, /* 9 */
60 STATE_DESCRIPTION, /* 10 */
61 STATE_PKGLIST, /* 11 */
62 STATE_COLLECTION, /* 12 */
64 STATE_PACKAGE, /* 14 */
65 STATE_FILENAME, /* 15 */
66 STATE_REBOOT, /* 16 */
67 STATE_RESTART, /* 17 */
68 STATE_RELOGIN, /* 18 */
80 /* !! must be sorted by first column !! */
81 static struct stateswitch stateswitches[] = {
82 { STATE_START, "updates", STATE_UPDATES, 0 },
83 { STATE_START, "update", STATE_UPDATE, 0 },
84 { STATE_UPDATES, "update", STATE_UPDATE, 0 },
85 { STATE_UPDATE, "id", STATE_ID, 1 },
86 { STATE_UPDATE, "title", STATE_TITLE, 1 },
87 { STATE_UPDATE, "release", STATE_RELEASE, 1 },
88 { STATE_UPDATE, "issued", STATE_ISSUED, 1 },
89 { STATE_UPDATE, "description", STATE_DESCRIPTION, 1 },
90 { STATE_UPDATE, "message", STATE_MESSAGE , 1 },
91 { STATE_UPDATE, "references", STATE_REFERENCES, 0 },
92 { STATE_UPDATE, "pkglist", STATE_PKGLIST, 0 },
93 { STATE_REFERENCES, "reference", STATE_REFERENCE, 0 },
94 { STATE_PKGLIST, "collection", STATE_COLLECTION, 0 },
95 { STATE_COLLECTION, "name", STATE_NAME, 1 },
96 { STATE_COLLECTION, "package", STATE_PACKAGE, 0 },
97 { STATE_PACKAGE, "filename", STATE_FILENAME, 1 },
98 { STATE_PACKAGE, "reboot_suggested",STATE_REBOOT, 1 },
99 { STATE_PACKAGE, "restart_suggested",STATE_RESTART, 1 },
100 { STATE_PACKAGE, "relogin_suggested",STATE_RELOGIN, 1 },
115 unsigned int datanum;
119 struct stateswitch *swtab[NUMSTATES];
120 enum state sbtab[NUMSTATES];
124 * Convert date strings ("1287746075" or "2010-10-22 13:14:35")
128 datestr2timestamp(const char *date)
135 for (p = date; *p >= '0' && *p <= '9'; p++)
139 memset(&tm, 0, sizeof(tm));
140 if (!strptime(date, "%F%T", &tm))
146 * if we have seen a <filename>...
147 * inside of <package>...
150 * If not, we must insert an empty filename to UPDATE_COLLECTION_FILENAME
151 * at </package> in order to keep all UPDATE_COLLECTION_* arrays in sync
155 * create evr (as Id) from 'epoch', 'version' and 'release' attributes
159 makeevr_atts(Pool *pool, struct parsedata *pd, const char **atts)
161 const char *e, *v, *r, *v2;
166 for (; *atts; atts += 2)
168 if (!strcmp(*atts, "epoch"))
170 else if (!strcmp(*atts, "version"))
172 else if (!strcmp(*atts, "release"))
175 if (e && !strcmp(e, "0"))
179 for (v2 = v; *v2 >= '0' && *v2 <= '9'; v2++)
181 if (v2 > v && *v2 == ':')
191 if (l > pd->acontent)
193 pd->content = realloc(pd->content, l + 256);
194 pd->acontent = l + 256;
218 fprintf(stderr, "evr: %s\n", pd->content);
220 return str2id(pool, pd->content, 1);
226 startElement(void *userData, const char *name, const char **atts)
228 struct parsedata *pd = userData;
229 Pool *pool = pd->pool;
230 Solvable *solvable = pd->solvable;
231 struct stateswitch *sw;
232 /*const char *str; */
235 fprintf(stderr, "start: [%d]%s\n", pd->state, name);
237 if (pd->depth != pd->statedepth)
244 if (!pd->swtab[pd->state])
246 for (sw = pd->swtab[pd->state]; sw->from == pd->state; sw++) /* find name in statetable */
247 if (!strcmp(sw->ename, name))
250 if (sw->from != pd->state)
253 fprintf(stderr, "into unknown: %s (from: %d)\n", name, pd->state);
259 pd->docontent = sw->docontent;
260 pd->statedepth = pd->depth;
271 * <update from="rel-eng@fedoraproject.org"
273 * type="bugfix" (enhancement, security)
278 const char *from = 0, *status = 0, *type = 0, *version = 0;
279 for (; *atts; atts += 2)
281 if (!strcmp(*atts, "from"))
283 else if (!strcmp(*atts, "status"))
285 else if (!strcmp(*atts, "type"))
287 else if (!strcmp(*atts, "version"))
292 solvable = pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo));
293 pd->datanum = pd->solvable - pool->solvables;
295 solvable->vendor = str2id(pool, from, 1);
296 solvable->evr = str2id(pool, version, 1);
297 solvable->arch = ARCH_NOARCH;
299 repodata_set_str(pd->data, pd->datanum, SOLVABLE_PATCHCATEGORY, type);
302 /* <id>FEDORA-2007-4594</id> */
305 /* <title>imlib-1.9.15-6.fc8</title> */
308 /* <release>Fedora 8</release> */
311 /* <issued date="2008-03-21 21:36:55"/>
315 const char *date = 0;
316 for (; *atts; atts += 2)
318 if (!strcmp(*atts, "date"))
323 time_t t = datestr2timestamp(date);
325 repodata_set_num(pd->data, pd->datanum, SOLVABLE_BUILDTIME, t);
329 case STATE_REFERENCES:
331 /* <reference href="https://bugzilla.redhat.com/show_bug.cgi?id=330471"
333 * title="LDAP schema file missing for dhcpd"
336 case STATE_REFERENCE:
338 const char *href = 0, *id = 0, *title = 0, *type = 0;
340 for (; *atts; atts += 2)
342 if (!strcmp(*atts, "href"))
344 else if (!strcmp(*atts, "id"))
346 else if (!strcmp(*atts, "title"))
348 else if (!strcmp(*atts, "type"))
351 handle = repodata_new_handle(pd->data);
353 repodata_set_str(pd->data, handle, UPDATE_REFERENCE_HREF, href);
355 repodata_set_str(pd->data, handle, UPDATE_REFERENCE_ID, id);
357 repodata_set_str(pd->data, handle, UPDATE_REFERENCE_TITLE, title);
359 repodata_set_poolstr(pd->data, handle, UPDATE_REFERENCE_TYPE, type);
360 repodata_add_flexarray(pd->data, pd->datanum, UPDATE_REFERENCE, handle);
363 /* <description>This update ...</description> */
364 case STATE_DESCRIPTION:
366 /* <message type="confirm">This update ...</message> */
371 /* <collection short="F8" */
372 case STATE_COLLECTION:
374 /* <name>Fedora 8</name> */
377 /* <package arch="ppc64" name="imlib-debuginfo" release="6.fc8"
378 * src="http://download.fedoraproject.org/pub/fedora/linux/updates/8/ppc64/imlib-debuginfo-1.9.15-6.fc8.ppc64.rpm"
382 * -> patch.conflicts: {name} < {version}.{release}
386 const char *arch = 0, *name = 0, *src = 0;
387 Id evr = makeevr_atts(pool, pd, atts); /* parse "epoch", "version", "release" */
391 for (; *atts; atts += 2)
393 if (!strcmp(*atts, "arch"))
395 else if (!strcmp(*atts, "name"))
397 else if (!strcmp(*atts, "src"))
400 /* generated Id for name */
401 n = str2id(pool, name, 1);
405 /* generate Id for arch and combine with name */
406 a = str2id(pool, arch, 1);
407 rel_id = rel2id(pool, n, a, REL_ARCH, 1);
409 rel_id = rel2id(pool, rel_id, evr, REL_LT, 1);
411 solvable->conflicts = repo_addid_dep(pd->repo, solvable->conflicts, rel_id, 0);
413 /* who needs the collection anyway? */
414 pd->collhandle = repodata_new_handle(pd->data);
415 repodata_set_id(pd->data, pd->collhandle, UPDATE_COLLECTION_NAME, n);
416 repodata_set_id(pd->data, pd->collhandle, UPDATE_COLLECTION_EVR, evr);
417 repodata_set_id(pd->data, pd->collhandle, UPDATE_COLLECTION_ARCH, a);
420 /* <filename>libntlm-0.4.2-1.fc8.x86_64.rpm</filename> */
421 /* <filename>libntlm-0.4.2-1.fc8.x86_64.rpm</filename> */
424 /* <reboot_suggested>True</reboot_suggested> */
427 /* <restart_suggested>True</restart_suggested> */
430 /* <relogin_suggested>True</relogin_suggested> */
441 endElement(void *userData, const char *name)
443 struct parsedata *pd = userData;
444 Pool *pool = pd->pool;
445 Solvable *s = pd->solvable;
446 Repo *repo = pd->repo;
449 fprintf(stderr, "end: %s\n", name);
451 if (pd->depth != pd->statedepth)
455 fprintf(stderr, "back from unknown %d %d %d\n", pd->state, pd->depth, pd->statedepth);
469 s->provides = repo_addid_dep(repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
472 s->name = str2id(pool, join2("patch", ":", pd->content), 1);
474 /* <title>imlib-1.9.15-6.fc8</title> */
476 while (pd->lcontent > 0 && pd->content[pd->lcontent - 1] == '\n')
477 pd->content[--pd->lcontent] = 0;
478 repodata_set_str(pd->data, pd->datanum, SOLVABLE_SUMMARY, pd->content);
481 * <release>Fedora 8</release>
487 case STATE_REFERENCES:
489 case STATE_REFERENCE:
492 * <description>This update ...</description>
494 case STATE_DESCRIPTION:
495 repodata_set_str(pd->data, pd->datanum, SOLVABLE_DESCRIPTION, pd->content);
498 * <message>Warning! ...</message>
501 repodata_set_str(pd->data, pd->datanum, UPDATE_MESSAGE, pd->content);
505 case STATE_COLLECTION:
510 repodata_add_flexarray(pd->data, pd->datanum, UPDATE_COLLECTION, pd->collhandle);
513 /* <filename>libntlm-0.4.2-1.fc8.x86_64.rpm</filename> */
514 /* <filename>libntlm-0.4.2-1.fc8.x86_64.rpm</filename> */
516 repodata_set_str(pd->data, pd->collhandle, UPDATE_COLLECTION_FILENAME, pd->content);
518 /* <reboot_suggested>True</reboot_suggested> */
520 if (pd->content[0] == 'T' || pd->content[0] == 't'|| pd->content[0] == '1')
522 /* FIXME: this is per-package, the global flag should be computed at runtime */
523 repodata_set_void(pd->data, pd->datanum, UPDATE_REBOOT);
524 repodata_set_void(pd->data, pd->collhandle, UPDATE_REBOOT);
527 /* <restart_suggested>True</restart_suggested> */
529 if (pd->content[0] == 'T' || pd->content[0] == 't'|| pd->content[0] == '1')
531 /* FIXME: this is per-package, the global flag should be computed at runtime */
532 repodata_set_void(pd->data, pd->datanum, UPDATE_RESTART);
533 repodata_set_void(pd->data, pd->collhandle, UPDATE_RESTART);
536 /* <relogin_suggested>True</relogin_suggested> */
538 if (pd->content[0] == 'T' || pd->content[0] == 't'|| pd->content[0] == '1')
540 /* FIXME: this is per-package, the global flag should be computed at runtime */
541 repodata_set_void(pd->data, pd->datanum, UPDATE_RELOGIN);
542 repodata_set_void(pd->data, pd->collhandle, UPDATE_RELOGIN);
549 pd->state = pd->sbtab[pd->state];
555 characterData(void *userData, const XML_Char *s, int len)
557 struct parsedata *pd = userData;
564 fprintf(stderr, "Content: [%d]'%.*s'\n", pd->state, len, s);
568 l = pd->lcontent + len + 1;
569 if (l > pd->acontent)
571 pd->content = realloc(pd->content, l + 256);
572 pd->acontent = l + 256;
574 c = pd->content + pd->lcontent;
582 #define BUFF_SIZE 8192
585 repo_add_updateinfoxml(Repo *repo, FILE *fp, int flags)
587 Pool *pool = repo->pool;
591 struct stateswitch *sw;
594 data = repo_add_repodata(repo, flags);
596 memset(&pd, 0, sizeof(pd));
597 for (i = 0, sw = stateswitches; sw->from != NUMSTATES; i++, sw++)
599 if (!pd.swtab[sw->from])
600 pd.swtab[sw->from] = sw;
601 pd.sbtab[sw->to] = sw->from;
607 pd.content = malloc(256);
610 XML_Parser parser = XML_ParserCreate(NULL);
611 XML_SetUserData(parser, &pd);
612 XML_SetElementHandler(parser, startElement, endElement);
613 XML_SetCharacterDataHandler(parser, characterData);
616 l = fread(buf, 1, sizeof(buf), fp);
617 if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
619 pool_debug(pool, SAT_FATAL, "repo_updateinfoxml: %s at line %u:%u\n", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
625 XML_ParserFree(parser);
629 if (!(flags & REPO_NO_INTERNALIZE))
630 repodata_internalize(data);