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"
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;
117 unsigned int timestamp;
120 struct stateswitch *swtab[NUMSTATES];
121 enum state sbtab[NUMSTATES];
128 * if we have seen a <filename>...
129 * inside of <package>...
132 * If not, we must insert an empty filename to UPDATE_COLLECTION_FILENAME
133 * at </package> in order to keep all UPDATE_COLLECTION_* arrays in sync
136 static int package_filename_seen = 0;
137 static int package_flags = 0; /* same for reboot/restart flags, to be written at </package> */
140 * create evr (as Id) from 'epoch', 'version' and 'release' attributes
144 makeevr_atts(Pool *pool, struct parsedata *pd, const char **atts)
146 const char *e, *v, *r, *v2;
151 for (; *atts; atts += 2)
153 if (!strcmp(*atts, "epoch"))
155 else if (!strcmp(*atts, "version"))
157 else if (!strcmp(*atts, "release"))
160 if (e && !strcmp(e, "0"))
164 for (v2 = v; *v2 >= '0' && *v2 <= '9'; v2++)
166 if (v2 > v && *v2 == ':')
176 if (l > pd->acontent)
178 pd->content = realloc(pd->content, l + 256);
179 pd->acontent = l + 256;
203 fprintf(stderr, "evr: %s\n", pd->content);
205 return str2id(pool, pd->content, 1);
211 startElement(void *userData, const char *name, const char **atts)
213 struct parsedata *pd = userData;
214 Pool *pool = pd->pool;
215 Solvable *solvable = pd->solvable;
216 struct stateswitch *sw;
217 /*const char *str; */
220 fprintf(stderr, "start: [%d]%s\n", pd->state, name);
222 if (pd->depth != pd->statedepth)
229 if (!pd->swtab[pd->state])
231 for (sw = pd->swtab[pd->state]; sw->from == pd->state; sw++) /* find name in statetable */
232 if (!strcmp(sw->ename, name))
235 if (sw->from != pd->state)
238 fprintf(stderr, "into unknown: %s (from: %d)\n", name, pd->state);
244 pd->docontent = sw->docontent;
245 pd->statedepth = pd->depth;
256 * <update from="rel-eng@fedoraproject.org"
258 * type="bugfix" (enhancement, security)
263 const char *from = 0, *status = 0, *type = 0, *version = 0;
264 for (; *atts; atts += 2)
266 if (!strcmp(*atts, "from"))
268 else if (!strcmp(*atts, "status"))
270 else if (!strcmp(*atts, "type"))
272 else if (!strcmp(*atts, "version"))
277 solvable = pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo));
278 pd->datanum = (pd->solvable - pool->solvables) - pd->repo->start;
279 repodata_extend(pd->data, pd->solvable - pool->solvables);
280 repodata_extend(pd->data, pd->solvable - pool->solvables);
281 pd->datanum = repodata_get_handle(pd->data, pd->datanum);
284 solvable->vendor = str2id(pool, from, 1);
285 solvable->evr = str2id(pool, version, 1);
286 solvable->arch = ARCH_NOARCH;
287 repodata_set_str(pd->data, pd->datanum, SOLVABLE_PATCHCATEGORY, type);
290 /* <id>FEDORA-2007-4594</id> */
293 /* <title>imlib-1.9.15-6.fc8</title> */
296 /* <release>Fedora 8</release> */
299 /* <issued date="2008-03-21 21:36:55"/>
303 const char *date = 0;
304 for (; *atts; atts += 2)
306 if (!strcmp(*atts, "date"))
309 repodata_set_str(pd->data, pd->datanum, SOLVABLE_BUILDTIME, date);
312 case STATE_REFERENCES:
314 /* <reference href="https://bugzilla.redhat.com/show_bug.cgi?id=330471"
316 * title="LDAP schema file missing for dhcpd"
319 case STATE_REFERENCE:
321 const char *href = 0, *id = 0, *title = 0, *type = 0;
322 for (; *atts; atts += 2)
324 if (!strcmp(*atts, "href"))
326 else if (!strcmp(*atts, "id"))
328 else if (!strcmp(*atts, "title"))
330 else if (!strcmp(*atts, "type"))
334 repodata_add_poolstr_array(pd->data, pd->datanum, UPDATE_REFERENCE_HREF, href);
335 repodata_add_poolstr_array(pd->data, pd->datanum, UPDATE_REFERENCE_ID, id);
336 repodata_add_poolstr_array(pd->data, pd->datanum, UPDATE_REFERENCE_TITLE, title);
337 repodata_add_poolstr_array(pd->data, pd->datanum, UPDATE_REFERENCE_TYPE, type);
341 /* <description>This update ...</description> */
342 case STATE_DESCRIPTION:
344 /* <message type="confirm">This update ...</message> */
349 /* <collection short="F8" */
350 case STATE_COLLECTION:
352 /* <name>Fedora 8</name> */
355 /* <package arch="ppc64" name="imlib-debuginfo" release="6.fc8"
356 * src="http://download.fedoraproject.org/pub/fedora/linux/updates/8/ppc64/imlib-debuginfo-1.9.15-6.fc8.ppc64.rpm"
360 * -> patch.conflicts: {name} < {version}.{release}
364 const char *arch = 0, *name = 0, *src = 0;
365 Id evr = makeevr_atts(pool, pd, atts); /* parse "epoch", "version", "release" */
370 /* reset package_* markers, to be evaluated at </package> */
371 package_filename_seen = 0;
375 for (; *atts; atts += 2)
377 if (!strcmp(*atts, "arch"))
379 else if (!strcmp(*atts, "name"))
381 else if (!strcmp(*atts, "src"))
384 /* generated Ids for name and arch */
385 n = str2id(pool, name, 1);
387 a = str2id(pool, arch, 1);
390 /* now combine both to a single Id */
391 na = rel2id(pool, n, a, REL_ARCH, 1);
394 rel_id = rel2id(pool, na, evr, REL_LT, 1);
396 solvable->conflicts = repo_addid_dep(pd->repo, solvable->conflicts, rel_id, 0);
398 repodata_add_idarray(pd->data, pd->datanum, UPDATE_COLLECTION_NAME, n);
399 repodata_add_idarray(pd->data, pd->datanum, UPDATE_COLLECTION_EVR, evr);
400 repodata_add_idarray(pd->data, pd->datanum, UPDATE_COLLECTION_ARCH, a);
402 /* _FILENAME and _FLAGS are written at </package> */
404 const char *evrstr = id2str(pool, evr);
405 int buflen = strlen(name) + 1 + strlen(evrstr) + 1 + strlen(arch?arch:"") + 1;
407 if (!arch) arch = "";
408 buf = (char *)malloc(buflen);
410 sprintf(buf, "%s %s %s", name, evrstr, arch);
411 repodata_add_poolstr_array(pd->data, pd->datanum, UPDATE_COLLECTION, buf);
417 /* <filename>libntlm-0.4.2-1.fc8.x86_64.rpm</filename> */
418 /* <filename>libntlm-0.4.2-1.fc8.x86_64.rpm</filename> */
421 /* <reboot_suggested>True</reboot_suggested> */
424 /* <restart_suggested>True</restart_suggested> */
427 /* <relogin_suggested>True</relogin_suggested> */
438 endElement(void *userData, const char *name)
440 struct parsedata *pd = userData;
441 Pool *pool = pd->pool;
442 Solvable *s = pd->solvable;
443 Repo *repo = pd->repo;
446 fprintf(stderr, "end: %s\n", name);
448 if (pd->depth != pd->statedepth)
452 fprintf(stderr, "back from unknown %d %d %d\n", pd->state, pd->depth, pd->statedepth);
466 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);
508 * <message>Warning! ...</message>
512 repodata_set_str(pd->data, pd->datanum, UPDATE_MESSAGE, pd->content);
517 case STATE_COLLECTION:
524 /* write _FILENAME and _FLAGS at </package>
525 * to ensure all UPDATE_COLLECTION_* arrays are filled in parallel
527 if (!package_filename_seen)
529 repodata_add_poolstr_array(pd->data, pd->datanum, UPDATE_COLLECTION_FILENAME, "");
531 repodata_add_idarray(pd->data, pd->datanum, UPDATE_COLLECTION_FLAGS, package_flags+1);
535 /* <filename>libntlm-0.4.2-1.fc8.x86_64.rpm</filename> */
536 /* <filename>libntlm-0.4.2-1.fc8.x86_64.rpm</filename> */
540 repodata_add_poolstr_array(pd->data, pd->datanum, UPDATE_COLLECTION_FILENAME, pd->content);
541 package_filename_seen = 1;
545 /* <reboot_suggested>True</reboot_suggested> */
549 && (pd->content[0] == 'T'
550 || pd->content[0] == 't'|| pd->content[0] == '1'))
552 /* FIXME: this is per-package, the global flag should be computed at runtime */
553 repodata_set_void(pd->data, pd->datanum, UPDATE_REBOOT);
558 /* <restart_suggested>True</restart_suggested> */
562 && (pd->content[0] == 'T'
563 || pd->content[0] == 't' || pd->content[0] == '1'))
565 /* FIXME: this is per-package, the global flag should be computed at runtime */
566 repodata_set_void(pd->data, pd->datanum, UPDATE_RESTART);
571 /* <relogin_suggested>True</relogin_suggested> */
575 && (pd->content[0] == 'T'
576 || pd->content[0] == 't' || pd->content[0] == '1'))
578 /* FIXME: this is per-package, the global flag should be computed at runtime */
579 repodata_set_void(pd->data, pd->datanum, UPDATE_RELOGIN);
588 pd->state = pd->sbtab[pd->state];
594 characterData(void *userData, const XML_Char *s, int len)
596 struct parsedata *pd = userData;
603 fprintf(stderr, "Content: [%d]'%.*s'\n", pd->state, len, s);
607 l = pd->lcontent + len + 1;
608 if (l > pd->acontent)
610 pd->content = realloc(pd->content, l + 256);
611 pd->acontent = l + 256;
613 c = pd->content + pd->lcontent;
621 #define BUFF_SIZE 8192
624 repo_add_updateinfoxml(Repo *repo, FILE *fp, int flags)
626 Pool *pool = repo->pool;
630 struct stateswitch *sw;
632 memset(&pd, 0, sizeof(pd));
633 for (i = 0, sw = stateswitches; sw->from != NUMSTATES; i++, sw++)
635 if (!pd.swtab[sw->from])
636 pd.swtab[sw->from] = sw;
637 pd.sbtab[sw->to] = sw->from;
641 pd.data = repo_add_repodata(pd.repo, 0);
643 pd.content = malloc(256);
646 pd.tempstr = malloc(256);
649 XML_Parser parser = XML_ParserCreate(NULL);
650 XML_SetUserData(parser, &pd);
651 XML_SetElementHandler(parser, startElement, endElement);
652 XML_SetCharacterDataHandler(parser, characterData);
655 l = fread(buf, 1, sizeof(buf), fp);
656 if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
658 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));
664 XML_ParserFree(parser);
667 repodata_internalize(pd.data);