From: Adam Dickmeiss Date: Sat, 1 Mar 2003 20:41:34 +0000 (+0000) Subject: Bug fix: uinitialized xpath predicate member (value) X-Git-Tag: ZEBRA.1.3.8~54 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=da923ac841e6e83bf7ce9abd27be1445e7917207;p=idzebra-moved-to-github.git Bug fix: uinitialized xpath predicate member (value) --- diff --git a/util/xpath.c b/util/xpath.c index 1155cb1..43fe1d0 100644 --- a/util/xpath.c +++ b/util/xpath.c @@ -1,5 +1,5 @@ -/* $Id: xpath.c,v 1.1 2003-02-04 12:06:48 pop Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: xpath.c,v 1.2 2003-03-01 20:41:34 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps This file is part of the Zebra server. @@ -28,114 +28,119 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -char *get_xp_part (char **strs, NMEM mem) { - char *str = *strs; - char *res = '\0'; - char *cp = str; - char *co; - int quoted = 0; - - /* ugly */ - char *sep = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\" "; - - while (*cp == ' ') {cp++; str++;} - if (!strchr("><=] ", *cp)) sep = "><=] "; - - while (*cp && !(strchr(sep,*cp) && !quoted) && (*cp != ']')) { - if (*cp =='"') quoted = 1 - quoted; - cp++; - } - /* removing leading and trailing " */ - co = cp; - if (*str == '"') str++; - if (*(cp-1) == '"') cp--; - if (str < co) { - res = nmem_malloc(mem, cp - str + 1); +char *get_xp_part (char **strs, NMEM mem) +{ + char *str = *strs; + char *res = '\0'; + char *cp = str; + char *co; + int quoted = 0; + + /* ugly */ + char *sep = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\" "; + + while (*cp == ' ') {cp++; str++;} + if (!strchr("><=] ", *cp)) sep = "><=] "; + + while (*cp && !(strchr(sep,*cp) && !quoted) && (*cp != ']')) { + if (*cp =='"') quoted = 1 - quoted; + cp++; + } + /* removing leading and trailing " */ + co = cp; + if (*str == '"') str++; + if (*(cp-1) == '"') cp--; + if (str < co) { + res = nmem_malloc(mem, cp - str + 1); memcpy (res, str, (cp-str)); *(res + (cp-str)) = '\0'; *strs = co; - } - - return (res); + } + + return (res); } -struct xpath_predicate *get_xpath_predicate(char *predicates, NMEM mem) { - char *p1; - char *p2; - char *p3; - char *p4; - - struct xpath_predicate *r1; - struct xpath_predicate *r2; - struct xpath_predicate *res = 0; - - char *pr = predicates; - - if ((p1 = get_xp_part(&pr, mem))) { - if ((p2 = get_xp_part(&pr, mem))) { - if (!strcmp (p2, "and") || !strcmp (p2, "or") || !strcmp (p2, "not")) { - r1=nmem_malloc(mem, sizeof(struct xpath_predicate)); - r1->which = XPATH_PREDICATE_RELATION; - r1->u.relation.name = p1; - r1->u.relation.op = ""; - r1->u.relation.value = ""; - - r2 = get_xpath_predicate (pr, mem); - - res = nmem_malloc(mem, sizeof(struct xpath_predicate)); - res->which = XPATH_PREDICATE_BOOLEAN; - res->u.boolean.op = p2; - res->u.boolean.left = r1; - res->u.boolean.right = r2; - - return (res); - } - - if (strchr("><=] ", *p2)) { - r1 = nmem_malloc(mem, sizeof(struct xpath_predicate)); - - r1->which = XPATH_PREDICATE_RELATION; - r1->u.relation.name = p1; - r1->u.relation.op = p2; - - if ((p3 = get_xp_part(&pr, mem))) { - r1->u.relation.value = p3; - } else { - /* error */ - } - } - - if ((p4 = get_xp_part(&pr, mem))) { - if (!strcmp (p4, "and") || !strcmp (p4, "or") || !strcmp (p4, "not")) { - - r2 = get_xpath_predicate (pr, mem); - - res = nmem_malloc(mem, sizeof(struct xpath_predicate)); - res->which = XPATH_PREDICATE_BOOLEAN; - res->u.boolean.op = p4; - res->u.boolean.left = r1; - res->u.boolean.right = r2; - return (res); - } else { - /* error */ - } - } else { - return (r1); - } - - } else { - r1 = nmem_malloc(mem, sizeof(struct xpath_predicate)); - - r1->which = XPATH_PREDICATE_RELATION; - r1->u.relation.name = p1; - r1->u.relation.op = ""; - r1->u.relation.value = ""; - - return (r1); +struct xpath_predicate *get_xpath_predicate(char *predicates, NMEM mem) +{ + char *p1; + char *p2; + char *p3; + char *p4; + + struct xpath_predicate *r1; + struct xpath_predicate *r2; + struct xpath_predicate *res = 0; + + char *pr = predicates; + + if ((p1 = get_xp_part(&pr, mem))) { + if ((p2 = get_xp_part(&pr, mem))) { + if (!strcmp (p2, "and") || !strcmp (p2, "or") || !strcmp (p2, "not")) { + r1=nmem_malloc(mem, sizeof(struct xpath_predicate)); + r1->which = XPATH_PREDICATE_RELATION; + r1->u.relation.name = p1; + r1->u.relation.op = ""; + r1->u.relation.value = ""; + + r2 = get_xpath_predicate (pr, mem); + + res = nmem_malloc(mem, sizeof(struct xpath_predicate)); + res->which = XPATH_PREDICATE_BOOLEAN; + res->u.boolean.op = p2; + res->u.boolean.left = r1; + res->u.boolean.right = r2; + + return (res); + } + + if (strchr("><=] ", *p2)) { + r1 = nmem_malloc(mem, sizeof(struct xpath_predicate)); + + r1->which = XPATH_PREDICATE_RELATION; + r1->u.relation.name = p1; + r1->u.relation.op = p2; + r1->u.relation.value = ""; + + if ((p3 = get_xp_part(&pr, mem))) { + r1->u.relation.value = p3; + } else { + /* error */ + } + } + + if ((p4 = get_xp_part(&pr, mem))) { + if (!strcmp (p4, "and") || !strcmp (p4, "or") || + !strcmp (p4, "not")) + { + + r2 = get_xpath_predicate (pr, mem); + + res = nmem_malloc(mem, sizeof(struct xpath_predicate)); + res->which = XPATH_PREDICATE_BOOLEAN; + res->u.boolean.op = p4; + res->u.boolean.left = r1; + res->u.boolean.right = r2; + return (res); + } else { + /* error */ + } + } else { + return (r1); + } + + } else { + r1 = nmem_malloc(mem, sizeof(struct xpath_predicate)); + + r1->which = XPATH_PREDICATE_RELATION; + r1->u.relation.name = p1; + r1->u.relation.op = ""; + r1->u.relation.value = ""; + + return (r1); + } } - } - return 0; + return 0; } int parse_xpath_str(const char *xpath_string, @@ -143,13 +148,13 @@ int parse_xpath_str(const char *xpath_string, { const char *cp; char *a; - + int no = 0; if (!xpath_string || *xpath_string != '/') return -1; cp = xpath_string; - + while (*cp) { int i = 0; @@ -185,30 +190,32 @@ int parse_xpath_str(const char *xpath_string, return no; } -void dump_xp_predicate (struct xpath_predicate *p) { +void dump_xp_predicate (struct xpath_predicate *p) +{ if (p) { - if (p->which == XPATH_PREDICATE_RELATION && + if (p->which == XPATH_PREDICATE_RELATION && p->u.relation.name[0]) { - fprintf (stderr, "%s,%s,%s", - p->u.relation.name, - p->u.relation.op, - p->u.relation.value); - } else { - fprintf (stderr, "("); - dump_xp_predicate(p->u.boolean.left); - fprintf (stderr, ") %s (", p->u.boolean.op); - dump_xp_predicate(p->u.boolean.right); - fprintf (stderr, ")"); - } + fprintf (stderr, "%s,%s,%s", + p->u.relation.name, + p->u.relation.op, + p->u.relation.value); + } else { + fprintf (stderr, "("); + dump_xp_predicate(p->u.boolean.left); + fprintf (stderr, ") %s (", p->u.boolean.op); + dump_xp_predicate(p->u.boolean.right); + fprintf (stderr, ")"); + } } } -void dump_xp_steps (struct xpath_location_step *xpath, int no) { - int i; - for (i=0; i