From: Michael Schroeder Date: Thu, 6 Mar 2008 19:10:24 +0000 (+0000) Subject: - beautify a bit X-Git-Tag: BASE-SuSE-Code-12_1-Branch~834 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7fbd792e2bdf201b4d2214cf1adda60dee6fb94b;p=platform%2Fupstream%2Flibsolv.git - beautify a bit - more overflow checks in repo_solv - add localpool parameter --- diff --git a/src/repo.c b/src/repo.c index 45fb428..f6b1e79 100644 --- a/src/repo.c +++ b/src/repo.c @@ -849,19 +849,19 @@ repo_lookup(Solvable *s, Id key, int (*callback)(void *cbdata, Solvable *s, Repo /***********************************************************************/ 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 @@ findrepodata(Repo *repo, Id p, Id keyname) 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); } diff --git a/src/repo.h b/src/repo.h index b7b9549..fc78dd1 100644 --- a/src/repo.h +++ b/src/repo.h @@ -159,7 +159,8 @@ typedef struct _KeyValue { /* 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 */ diff --git a/src/repo_solv.c b/src/repo_solv.c index 361097b..64ade8d 100644 --- a/src/repo_solv.c +++ b/src/repo_solv.c @@ -797,6 +797,8 @@ repo_add_solv_parent(Repo *repo, FILE *fp, Repodata *parent) 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 @@ repo_add_solv_parent(Repo *repo, FILE *fp, Repodata *parent) 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 @@ repo_add_solv_parent(Repo *repo, FILE *fp, Repodata *parent) 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 @@ repo_add_solv_parent(Repo *repo, FILE *fp, Repodata *parent) { 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 */ diff --git a/src/repodata.c b/src/repodata.c index 037cf36..214ec1d 100644 --- a/src/repodata.c +++ b/src/repodata.c @@ -37,6 +37,27 @@ extern unsigned int unchecked_decompress_buf (const unsigned char *in, #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 @@ repodata_free(Repodata *data) } 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 @@ static unsigned char * 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 @@ make_vertical_available(Repodata *data, Repokey *key, Id off, Id len) 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 @@ weg2: 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_block(Repodata *data, Id start, Id num) repodata_extend(data, start + num - 1); } +/**********************************************************************/ + #define REPODATA_ATTRS_BLOCK 63 #define REPODATA_ATTRDATA_BLOCK 1023 #define REPODATA_ATTRIDDATA_BLOCK 63