Author: mlschroe Date: Thu Mar 6 20:10:24 2008 New Revision: 9039 URL: http://svn.opensuse.org/viewcvs/zypp?rev=9039&view=rev Log: - beautify a bit - more overflow checks in repo_solv - add localpool parameter Modified: trunk/sat-solver/src/repo.c trunk/sat-solver/src/repo.h trunk/sat-solver/src/repo_solv.c trunk/sat-solver/src/repodata.c Modified: trunk/sat-solver/src/repo.c URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/repo.c?rev=9039&r1=9038&r2=9039&view=diff ============================================================================== --- trunk/sat-solver/src/repo.c (original) +++ trunk/sat-solver/src/repo.c Thu Mar 6 20:10:24 2008 @@ -849,19 +849,19 @@ /***********************************************************************/ Repodata * -repo_add_repodata(Repo *repo) +repo_add_repodata(Repo *repo, int localpool) { Repodata *data; repo->nrepodata++; repo->repodata = sat_realloc2(repo->repodata, repo->nrepodata, sizeof(*data)); data = repo->repodata + repo->nrepodata - 1; - repodata_init(data, repo, 0); + repodata_init(data, repo, localpool); return data; } static Repodata * -findrepodata(Repo *repo, Id p, Id keyname) +repo_findrepodata(Repo *repo, Id p, Id keyname) { int i; Repodata *data; @@ -878,34 +878,34 @@ repodata_extend(data, p); return data; } - return repo_add_repodata(repo); + return repo_add_repodata(repo, 0); } void repo_set_id(Repo *repo, Id p, Id keyname, Id id) { - Repodata *data = findrepodata(repo, p, keyname); + Repodata *data = repo_findrepodata(repo, p, keyname); repodata_set_id(data, p - data->start, keyname, id); } void repo_set_num(Repo *repo, Id p, Id keyname, Id num) { - Repodata *data = findrepodata(repo, p, keyname); + Repodata *data = repo_findrepodata(repo, p, keyname); repodata_set_num(data, p - data->start, keyname, num); } void repo_set_str(Repo *repo, Id p, Id keyname, const char *str) { - Repodata *data = findrepodata(repo, p, keyname); + Repodata *data = repo_findrepodata(repo, p, keyname); repodata_set_str(data, p - data->start, keyname, str); } void repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str) { - Repodata *data = findrepodata(repo, p, keyname); + Repodata *data = repo_findrepodata(repo, p, keyname); repodata_set_poolstr(data, p - data->start, keyname, str); } Modified: trunk/sat-solver/src/repo.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/repo.h?rev=9039&r1=9038&r2=9039&view=diff ============================================================================== --- trunk/sat-solver/src/repo.h (original) +++ trunk/sat-solver/src/repo.h Thu Mar 6 20:10:24 2008 @@ -159,7 +159,8 @@ /* Internal */ #define __SEARCH_ONESOLVABLE (1 << 31) -Repodata *repo_add_repodata(Repo *repo); +Repodata *repo_add_repodata(Repo *repo, int localpool); + void repo_search(Repo *repo, Id p, Id key, const char *match, int flags, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv), void *cbdata); /* returns the string value of the attribute, or NULL if not found */ Modified: trunk/sat-solver/src/repo_solv.c URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/repo_solv.c?rev=9039&r1=9038&r2=9039&view=diff ============================================================================== --- trunk/sat-solver/src/repo_solv.c (original) +++ trunk/sat-solver/src/repo_solv.c Thu Mar 6 20:10:24 2008 @@ -797,6 +797,8 @@ char *pp = prefix; char *old_str = 0; char *dest = strsp; + int freesp = sizeid; + if (pfsize && fread(prefix, pfsize, 1, fp) != 1) { pool_debug(pool, SAT_ERROR, "read error while reading strings\n"); @@ -806,7 +808,14 @@ for (i = 1; i < numid; i++) { int same = (unsigned char)*pp++; - size_t len = strlen (pp) + 1; + size_t len = strlen(pp) + 1; + freesp -= same + len; + if (freesp < 0) + { + pool_debug(pool, SAT_ERROR, "overflow while expanding strings\n"); + sat_free(prefix); + return SOLV_ERROR_OVERFLOW; + } if (same) memcpy(dest, old_str, same); memcpy(dest + same, pp, len); @@ -815,6 +824,11 @@ dest += same + len; } sat_free(prefix); + if (freesp != 0) + { + pool_debug(pool, SAT_ERROR, "expanding strings size mismatch\n"); + return SOLV_ERROR_CORRUPT; + } } strsp[sizeid] = 0; /* make string space \0 terminated */ sp = strsp; @@ -888,7 +902,7 @@ { sat_free(hashtbl); sat_free(idmap); - pool_debug(pool, SAT_ERROR, "not enough strings\n"); + pool_debug(pool, SAT_ERROR, "not enough strings %d %d\n", i, numid); return SOLV_ERROR_OVERFLOW; } if (!*sp) /* empty string */ Modified: trunk/sat-solver/src/repodata.c URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/repodata.c?rev=9039&r1=9038&r2=9039&view=diff ============================================================================== --- trunk/sat-solver/src/repodata.c (original) +++ trunk/sat-solver/src/repodata.c Thu Mar 6 20:10:24 2008 @@ -37,6 +37,27 @@ #define REPODATA_BLOCK 255 + +void +repodata_init(Repodata *data, Repo *repo, int localpool) +{ + memset(data, 0, sizeof (*data)); + data->repo = repo; + data->localpool = localpool; + if (localpool) + stringpool_init_empty(&data->spool); + data->keys = sat_calloc(1, sizeof(Repokey)); + data->nkeys = 1; + data->schemata = sat_calloc(1, sizeof(Id)); + data->schemadata = sat_calloc(1, sizeof(Id)); + data->nschemata = 1; + data->schemadatalen = 1; + data->start = repo->start; + data->end = repo->end; + data->incoreoffset = sat_extend_resize(0, data->end - data->start, sizeof(Id), REPODATA_BLOCK); + data->pagefd = -1; +} + void repodata_free(Repodata *data) { @@ -72,14 +93,14 @@ } static unsigned char * -forward_to_key(Repodata *data, Id key, Id schemaid, unsigned char *dp) +forward_to_key(Repodata *data, Id keyid, Id schemaid, unsigned char *dp) { Id k, *keyp; keyp = data->schemadata + data->schemata[schemaid]; while ((k = *keyp++) != 0) { - if (k == key) + if (k == keyid) return dp; if (data->keys[k].storage == KEY_STORAGE_VERTICAL_OFFSET) { @@ -260,7 +281,7 @@ make_vertical_available(Repodata *data, Repokey *key, Id off, Id len) { unsigned char *dp; - if (key->type == REPOKEY_TYPE_VOID) + if (!len) return 0; if (off >= data->lastverticaloffset) { @@ -273,6 +294,7 @@ return 0; /* we now have the offset, go into vertical */ off += data->verticaloffset[key - data->keys]; + /* fprintf(stderr, "key %d page %d\n", key->name, off / BLOB_PAGESIZE); */ dp = load_page_range(data, off / BLOB_PAGESIZE, (off + len - 1) / BLOB_PAGESIZE); if (dp) dp += off % BLOB_PAGESIZE; @@ -807,26 +829,6 @@ return 1; } -void -repodata_init(Repodata *data, Repo *repo, int localpool) -{ - memset(data, 0, sizeof (*data)); - data->repo = repo; - data->localpool = localpool; - if (localpool) - stringpool_init_empty(&data->spool); - data->keys = sat_calloc(1, sizeof(Repokey)); - data->nkeys = 1; - data->schemata = sat_calloc(1, sizeof(Id)); - data->schemadata = sat_calloc(1, sizeof(Id)); - data->nschemata = 1; - data->schemadatalen = 1; - data->start = repo->start; - data->end = repo->end; - data->incoreoffset = sat_extend_resize(0, data->end - data->start, sizeof(Id), REPODATA_BLOCK); - data->pagefd = -1; -} - /* extend repodata so that it includes solvables p */ void repodata_extend(Repodata *data, Id p) @@ -881,6 +883,8 @@ repodata_extend(data, start + num - 1); } +/**********************************************************************/ + #define REPODATA_ATTRS_BLOCK 63 #define REPODATA_ATTRDATA_BLOCK 1023 #define REPODATA_ATTRIDDATA_BLOCK 63 -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org