2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 #include <sys/types.h>
21 #include "repo_updateinfoxml.h"
22 #include "tools_util.h"
26 * <update from="rel-eng@fedoraproject.org" status="stable" type="security" version="1.4">
27 * <id>FEDORA-2007-4594</id>
28 * <title>imlib-1.9.15-6.fc8</title>
29 * <release>Fedora 8</release>
30 * <issued date="2007-12-28 16:42:30"/>
32 * <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"/>
34 * <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>
36 * <collection short="F8">
37 * <name>Fedora 8</name>
38 * <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">
39 * <filename>imlib-debuginfo-1.9.15-6.fc8.ppc64.rpm</filename>
40 * <reboot_suggested>True</reboot_suggested>
50 STATE_UPDATES, /* 1 */
54 STATE_RELEASE, /* 5 */
56 STATE_MESSAGE, /* 7 */
57 STATE_REFERENCES, /* 8 */
58 STATE_REFERENCE, /* 9 */
59 STATE_DESCRIPTION, /* 10 */
60 STATE_PKGLIST, /* 11 */
61 STATE_COLLECTION, /* 12 */
63 STATE_PACKAGE, /* 14 */
64 STATE_FILENAME, /* 15 */
65 STATE_REBOOT, /* 16 */
66 STATE_RESTART, /* 17 */
67 STATE_RELOGIN, /* 18 */
79 /* !! must be sorted by first column !! */
80 static struct stateswitch stateswitches[] = {
81 { STATE_START, "updates", STATE_UPDATES, 0 },
82 { STATE_START, "update", STATE_UPDATE, 0 },
83 { STATE_UPDATES, "update", STATE_UPDATE, 0 },
84 { STATE_UPDATE, "id", STATE_ID, 1 },
85 { STATE_UPDATE, "title", STATE_TITLE, 1 },
86 { STATE_UPDATE, "release", STATE_RELEASE, 1 },
87 { STATE_UPDATE, "issued", STATE_ISSUED, 1 },
88 { STATE_UPDATE, "description", STATE_DESCRIPTION, 1 },
89 { STATE_UPDATE, "message", STATE_MESSAGE , 1 },
90 { STATE_UPDATE, "references", STATE_REFERENCES, 0 },
91 { STATE_UPDATE, "pkglist", STATE_PKGLIST, 0 },
92 { STATE_REFERENCES, "reference", STATE_REFERENCE, 0 },
93 { STATE_PKGLIST, "collection", STATE_COLLECTION, 0 },
94 { STATE_COLLECTION, "name", STATE_NAME, 1 },
95 { STATE_COLLECTION, "package", STATE_PACKAGE, 0 },
96 { STATE_PACKAGE, "filename", STATE_FILENAME, 1 },
97 { STATE_PACKAGE, "reboot_suggested",STATE_REBOOT, 1 },
98 { STATE_PACKAGE, "restart_suggested",STATE_RESTART, 1 },
99 { STATE_PACKAGE, "relogin_suggested",STATE_RELOGIN, 1 },
114 unsigned int datanum;
116 unsigned int timestamp;
119 struct stateswitch *swtab[NUMSTATES];
120 enum state sbtab[NUMSTATES];
127 * if we have seen a <filename>...
128 * inside of <package>...
131 * If not, we must insert an empty filename to UPDATE_COLLECTION_FILENAME
132 * at </package> in order to keep all UPDATE_COLLECTION_* arrays in sync
135 static int package_filename_seen = 0;
136 static int package_flags = 0; /* same for reboot/restart flags, to be written at </package> */
139 * create evr (as Id) from 'epoch', 'version' and 'release' attributes
143 makeevr_atts(Pool *pool, struct parsedata *pd, const char **atts)
145 const char *e, *v, *r, *v2;
150 for (; *atts; atts += 2)
152 if (!strcmp(*atts, "epoch"))
154 else if (!strcmp(*atts, "version"))
156 else if (!strcmp(*atts, "release"))
159 if (e && !strcmp(e, "0"))
163 for (v2 = v; *v2 >= '0' && *v2 <= '9'; v2++)
165 if (v2 > v && *v2 == ':')
175 if (l > pd->acontent)
177 pd->content = realloc(pd->content, l + 256);
178 pd->acontent = l + 256;
202 fprintf(stderr, "evr: %s\n", pd->content);
204 return str2id(pool, pd->content, 1);
210 startElement(void *userData, const char *name, const char **atts)
212 struct parsedata *pd = userData;
213 Pool *pool = pd->pool;
214 Solvable *solvable = pd->solvable;
215 struct stateswitch *sw;
216 /*const char *str; */
219 fprintf(stderr, "start: [%d]%s\n", pd->state, name);
221 if (pd->depth != pd->statedepth)
228 for (sw = pd->swtab[pd->state]; sw->from == pd->state; sw++) /* find name in statetable */
229 if (!strcmp(sw->ename, name))
233 if (sw->from != pd->state)
236 fprintf(stderr, "into unknown: [%d]%s (from: %d)\n", sw->to, name, sw->from);
242 pd->docontent = sw->docontent;
243 pd->statedepth = pd->depth;
254 * <update from="rel-eng@fedoraproject.org"
256 * type="bugfix" (enhancement, security)
261 const char *from = 0, *status = 0, *type = 0, *version = 0;
262 for (; *atts; atts += 2)
264 if (!strcmp(*atts, "from"))
266 else if (!strcmp(*atts, "status"))
268 else if (!strcmp(*atts, "type"))
270 else if (!strcmp(*atts, "version"))
275 solvable = pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo));
276 pd->datanum = (pd->solvable - pool->solvables) - pd->repo->start;
277 repodata_extend(pd->data, pd->solvable - pool->solvables);
278 repodata_extend(pd->data, pd->solvable - pool->solvables);
279 pd->datanum = repodata_get_handle(pd->data, pd->datanum);
282 solvable->vendor = str2id(pool, from, 1);
283 solvable->evr = str2id(pool, version, 1);
284 solvable->arch = ARCH_NOARCH;
285 repodata_set_str(pd->data, pd->datanum, SOLVABLE_PATCHCATEGORY, type);
288 /* <id>FEDORA-2007-4594</id> */
291 /* <title>imlib-1.9.15-6.fc8</title> */
294 /* <release>Fedora 8</release> */
297 /* <issued date="2008-03-21 21:36:55"/>
301 const char *date = 0;
302 for (; *atts; atts += 2)
304 if (!strcmp(*atts, "date"))
307 repodata_set_str(pd->data, pd->datanum, SOLVABLE_BUILDTIME, date);
310 case STATE_REFERENCES:
312 /* <reference href="https://bugzilla.redhat.com/show_bug.cgi?id=330471"
314 * title="LDAP schema file missing for dhcpd"
317 case STATE_REFERENCE:
319 const char *href = 0, *id = 0, *title = 0, *type = 0;
320 for (; *atts; atts += 2)
322 if (!strcmp(*atts, "href"))
324 else if (!strcmp(*atts, "id"))
326 else if (!strcmp(*atts, "title"))
328 else if (!strcmp(*atts, "type"))
332 repodata_add_poolstr_array(pd->data, pd->datanum, UPDATE_REFERENCE_HREF, href);
333 repodata_add_poolstr_array(pd->data, pd->datanum, UPDATE_REFERENCE_ID, id);
334 repodata_add_poolstr_array(pd->data, pd->datanum, UPDATE_REFERENCE_TITLE, title);
335 repodata_add_poolstr_array(pd->data, pd->datanum, UPDATE_REFERENCE_TYPE, type);
339 /* <description>This update ...</description> */
340 case STATE_DESCRIPTION:
342 /* <message type="confirm">This update ...</message> */
347 /* <collection short="F8" */
348 case STATE_COLLECTION:
350 /* <name>Fedora 8</name> */
353 /* <package arch="ppc64" name="imlib-debuginfo" release="6.fc8"
354 * src="http://download.fedoraproject.org/pub/fedora/linux/updates/8/ppc64/imlib-debuginfo-1.9.15-6.fc8.ppc64.rpm"
358 * -> patch.conflicts: {name} < {version}.{release}
362 const char *arch = 0, *name = 0, *src = 0;
363 Id evr = makeevr_atts(pool, pd, atts); /* parse "epoch", "version", "release" */
368 /* reset package_* markers, to be evaluated at </package> */
369 package_filename_seen = 0;
373 for (; *atts; atts += 2)
375 if (!strcmp(*atts, "arch"))
377 else if (!strcmp(*atts, "name"))
379 else if (!strcmp(*atts, "src"))
382 /* generated Ids for name and arch */
383 n = str2id(pool, name, 1);
385 a = str2id(pool, arch, 1);
388 /* now combine both to a single Id */
389 na = rel2id(pool, n, a, REL_ARCH, 1);
392 rel_id = rel2id(pool, na, evr, REL_LT, 1);
394 solvable->conflicts = repo_addid_dep(pd->repo, solvable->conflicts, rel_id, 0);
396 repodata_add_idarray(pd->data, pd->datanum, UPDATE_COLLECTION_NAME, n);
397 repodata_add_idarray(pd->data, pd->datanum, UPDATE_COLLECTION_EVR, evr);
398 repodata_add_idarray(pd->data, pd->datanum, UPDATE_COLLECTION_ARCH, a);
400 /* _FILENAME and _FLAGS are written at </package> */
402 const char *evrstr = id2str(pool, evr);
403 int buflen = strlen(name) + 1 + strlen(evrstr) + 1 + strlen(arch?arch:"") + 1;
405 if (!arch) arch = "";
406 buf = (char *)malloc(buflen);
408 sprintf(buf, "%s %s %s", name, evrstr, arch);
409 repodata_add_poolstr_array(pd->data, pd->datanum, UPDATE_COLLECTION, buf);
415 /* <filename>libntlm-0.4.2-1.fc8.x86_64.rpm</filename> */
416 /* <filename>libntlm-0.4.2-1.fc8.x86_64.rpm</filename> */
419 /* <reboot_suggested>True</reboot_suggested> */
422 /* <restart_suggested>True</restart_suggested> */
425 /* <relogin_suggested>True</relogin_suggested> */
429 split(NULL, NULL, 0); /* just to keep gcc happy about tools_util.h: static ... split() {...} Urgs!*/
439 endElement(void *userData, const char *name)
441 struct parsedata *pd = userData;
442 Pool *pool = pd->pool;
443 Solvable *s = pd->solvable;
444 Repo *repo = pd->repo;
447 fprintf(stderr, "end: %s\n", name);
449 if (pd->depth != pd->statedepth)
453 fprintf(stderr, "back from unknown %d %d %d\n", pd->state, pd->depth, pd->statedepth);
467 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);
476 /* <title>imlib-1.9.15-6.fc8</title> */
479 while (pd->lcontent > 0
480 && *(pd->content + pd->lcontent - 1) == '\n')
483 *(pd->content + pd->lcontent) = 0;
485 repodata_set_str(pd->data, pd->datanum, SOLVABLE_SUMMARY, pd->content);
489 * <release>Fedora 8</release>
495 case STATE_REFERENCES:
497 case STATE_REFERENCE:
500 * <description>This update ...</description>
502 case STATE_DESCRIPTION:
504 repodata_set_str(pd->data, pd->datanum, SOLVABLE_DESCRIPTION, pd->content);
509 * <message>Warning! ...</message>
513 repodata_set_str(pd->data, pd->datanum, UPDATE_MESSAGE, pd->content);
518 case STATE_COLLECTION:
525 /* write _FILENAME and _FLAGS at </package>
526 * to ensure all UPDATE_COLLECTION_* arrays are filled in parallel
528 if (!package_filename_seen)
530 repodata_add_poolstr_array(pd->data, pd->datanum, UPDATE_COLLECTION_FILENAME, "");
532 repodata_add_idarray(pd->data, pd->datanum, UPDATE_COLLECTION_FLAGS, package_flags+1);
536 /* <filename>libntlm-0.4.2-1.fc8.x86_64.rpm</filename> */
537 /* <filename>libntlm-0.4.2-1.fc8.x86_64.rpm</filename> */
541 repodata_add_poolstr_array(pd->data, pd->datanum, UPDATE_COLLECTION_FILENAME, pd->content);
542 package_filename_seen = 1;
546 /* <reboot_suggested>True</reboot_suggested> */
550 && (pd->content[0] == 'T'
551 || pd->content[0] == 't'|| pd->content[0] == '1'))
553 /* FIXME: this is per-package, the global flag should be computed at runtime */
554 repodata_set_void(pd->data, pd->datanum, UPDATE_REBOOT);
559 /* <restart_suggested>True</restart_suggested> */
563 && (pd->content[0] == 'T'
564 || pd->content[0] == 't' || pd->content[0] == '1'))
566 /* FIXME: this is per-package, the global flag should be computed at runtime */
567 repodata_set_void(pd->data, pd->datanum, UPDATE_RESTART);
572 /* <relogin_suggested>True</relogin_suggested> */
576 && (pd->content[0] == 'T'
577 || pd->content[0] == 't' || pd->content[0] == '1'))
579 /* FIXME: this is per-package, the global flag should be computed at runtime */
580 repodata_set_void(pd->data, pd->datanum, UPDATE_RELOGIN);
589 pd->state = pd->sbtab[pd->state];
598 characterData(void *userData, const XML_Char *s, int len)
600 struct parsedata *pd = userData;
603 if (!pd->docontent) {
605 char *dup = strndup( s, len );
606 fprintf(stderr, "Content: [%d]'%s'\n", pd->state, dup );
611 l = pd->lcontent + len + 1;
612 if (l > pd->acontent)
614 pd->content = realloc(pd->content, l + 256);
615 pd->acontent = l + 256;
617 c = pd->content + pd->lcontent;
625 #define BUFF_SIZE 8192
628 repo_add_updateinfoxml(Repo *repo, FILE *fp, int flags)
630 Pool *pool = repo->pool;
634 struct stateswitch *sw;
636 memset(&pd, 0, sizeof(pd));
637 for (i = 0, sw = stateswitches; sw->from != NUMSTATES; i++, sw++)
639 if (!pd.swtab[sw->from])
640 pd.swtab[sw->from] = sw;
641 pd.sbtab[sw->to] = sw->from;
645 pd.data = repo_add_repodata(pd.repo, 0);
647 pd.content = malloc(256);
650 pd.tempstr = malloc(256);
653 XML_Parser parser = XML_ParserCreate(NULL);
654 XML_SetUserData(parser, &pd);
655 XML_SetElementHandler(parser, startElement, endElement);
656 XML_SetCharacterDataHandler(parser, characterData);
659 l = fread(buf, 1, sizeof(buf), fp);
660 if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
662 fprintf(stderr, "repo_updateinfoxml: %s at line %u:%u\n", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
668 XML_ParserFree(parser);
671 repodata_internalize(pd.data);