[Rpm-maint] [PATCH] bugfixes for 4.8.x
Tero Aho
ext-tero.aho at nokia.com
Fri Apr 1 11:32:58 UTC 2011
Some random bugfixes for 4.8.x. Most also apply directly to
4.9.x (or master), and the for the rest one has to find the
new place for the function.
I'm sending these for 4.8.x because most of MeeGo work has
been done there. Please take a look if they are reasonable,
useful, don't introduce new bugs, etc.
Autotest cases run normally after patching these in.
---
build.c | 1 +
build/files.c | 2 +-
build/pack.c | 8 ++-
build/rpmfc.c | 111
+++++++++++++++++++++++++++--------------------------
build/spec.c | 2 +-
lib/fsm.c | 2 +-
lib/headerfmt.c | 15 ++++---
lib/psm.c | 2 +-
lib/rpmdb.c | 13 ++++--
lib/rpmlock.c | 4 +-
lib/transaction.c | 2 +-
rpmio/base64.c | 2 +-
rpmio/macro.c | 6 +-
rpmio/rpmmalloc.c | 2 +-
rpmio/rpmstring.c | 1 +
15 files changed, 92 insertions(+), 81 deletions(-)
diff --git a/build.c b/build.c
index 12ead44..1cf7f29 100644
--- a/build.c
+++ b/build.c
@@ -64,6 +64,7 @@ static int isSpecFile(const char * specfile)
if (f == NULL || ferror(f)) {
rpmlog(RPMLOG_ERR, _("Unable to open spec file %s: %s\n"),
specfile, strerror(errno));
+ if (f) fclose(f);
return 0;
}
count = fread(buf, sizeof(buf[0]), sizeof(buf), f);
diff --git a/build/files.c b/build/files.c
index 82a6508..c892280 100644
--- a/build/files.c
+++ b/build/files.c
@@ -1231,7 +1231,7 @@ static void genCpioListAndHeader(FileList fl,
buf[0] = '\0';
if (S_ISLNK(flp->fl_mode)) {
- buf[readlink(flp->diskPath, buf, BUFSIZ)] = '\0';
+ buf[readlink(flp->diskPath, buf, BUFSIZ-1)] = '\0';
if (fl->buildRoot) {
if (buf[0] == '/' && !rstreq(fl->buildRoot, "/") &&
rstreqn(buf, fl->buildRoot, strlen(fl->buildRoot))) {
diff --git a/build/pack.c b/build/pack.c
index f3b764c..21fe3ae 100644
--- a/build/pack.c
+++ b/build/pack.c
@@ -38,8 +38,10 @@ static rpmRC cpio_doio(FD_t fdo, Header h, CSA_t csa,
int xx, i;
{ char *fmode = rpmExpand(fmodeMacro, NULL);
- if (!(fmode && fmode[0] == 'w'))
+ if (!(fmode && fmode[0] == 'w')) {
+ if (fmode) free(fmode);
fmode = xstrdup("w9.gzdio");
+ }
(void) Fflush(fdo);
cfd = Fdopen(fdDup(Fileno(fdo)), fmode);
fmode = _free(fmode);
@@ -132,9 +134,9 @@ static StringBuf addFileToTagAux(rpmSpec spec,
}
appendStringBuf(sb, buf);
}
- (void) fclose(f);
exit:
+ if (f) fclose(f);
free(fn);
return sb;
@@ -448,7 +450,6 @@ rpmRC writeRPM(Header *hdrp, unsigned char **
pkgidp, const char *fileName,
rpmlog(RPMLOG_ERR, _("Bad CSA data\n"));
}
}
- rpmio_flags = _free(rpmio_flags);
if (rc != RPMRC_OK)
goto exit;
@@ -606,6 +607,7 @@ rpmRC writeRPM(Header *hdrp, unsigned char **
pkgidp, const char *fileName,
rc = RPMRC_OK;
exit:
+ rpmio_flags = _free(rpmio_flags);
SHA1 = _free(SHA1);
h = headerFree(h);
diff --git a/build/rpmfc.c b/build/rpmfc.c
index ac19e82..61ab9d5 100644
--- a/build/rpmfc.c
+++ b/build/rpmfc.c
@@ -554,71 +554,72 @@ void rpmfcPrint(const char * msg, rpmfc fc, FILE * fp)
int dx;
int fx;
-int nprovides;
-int nrequires;
+ int nprovides;
+ int nrequires;
if (fp == NULL) fp = stderr;
if (msg)
fprintf(fp, "===================================== %s\n", msg);
-nprovides = rpmdsCount(fc->provides);
-nrequires = rpmdsCount(fc->requires);
-
- if (fc)
- for (fx = 0; fx < fc->nfiles; fx++) {
-assert(fx < fc->fcdictx->nvals);
- cx = fc->fcdictx->vals[fx];
-assert(fx < fc->fcolor->nvals);
- fcolor = fc->fcolor->vals[fx];
-
- fprintf(fp, "%3d %s", fx, fc->fn[fx]);
- if (fcolor != RPMFC_BLACK)
+ if (fc) {
+ nprovides = rpmdsCount(fc->provides);
+ nrequires = rpmdsCount(fc->requires);
+
+ for (fx = 0; fx < fc->nfiles; fx++) {
+ assert(fx < fc->fcdictx->nvals);
+ cx = fc->fcdictx->vals[fx];
+ assert(fx < fc->fcolor->nvals);
+ fcolor = fc->fcolor->vals[fx];
+
+ fprintf(fp, "%3d %s", fx, fc->fn[fx]);
+ if (fcolor != RPMFC_BLACK)
fprintf(fp, "\t0x%x", fc->fcolor->vals[fx]);
- else
+ else
fprintf(fp, "\t%s", fc->cdict[cx]);
- fprintf(fp, "\n");
+ fprintf(fp, "\n");
- if (fc->fddictx == NULL || fc->fddictn == NULL)
- continue;
+ if (fc->fddictx == NULL || fc->fddictn == NULL)
+ continue;
-assert(fx < fc->fddictx->nvals);
- dx = fc->fddictx->vals[fx];
-assert(fx < fc->fddictn->nvals);
- ndx = fc->fddictn->vals[fx];
-
- while (ndx-- > 0) {
- const char * depval;
- unsigned char deptype;
- unsigned ix;
-
- ix = fc->ddictx->vals[dx++];
- deptype = ((ix >> 24) & 0xff);
- ix &= 0x00ffffff;
- depval = NULL;
- switch (deptype) {
- default:
-assert(depval != NULL);
- break;
- case 'P':
- if (nprovides > 0) {
-assert(ix < nprovides);
- (void) rpmdsSetIx(fc->provides, ix-1);
- if (rpmdsNext(fc->provides) >= 0)
- depval = rpmdsDNEVR(fc->provides);
- }
- break;
- case 'R':
- if (nrequires > 0) {
-assert(ix < nrequires);
- (void) rpmdsSetIx(fc->requires, ix-1);
- if (rpmdsNext(fc->requires) >= 0)
- depval = rpmdsDNEVR(fc->requires);
+ assert(fx < fc->fddictx->nvals);
+ dx = fc->fddictx->vals[fx];
+ assert(fx < fc->fddictn->nvals);
+ ndx = fc->fddictn->vals[fx];
+
+ while (ndx-- > 0) {
+ const char * depval;
+ unsigned char deptype;
+ unsigned ix;
+
+ ix = fc->ddictx->vals[dx++];
+ deptype = ((ix >> 24) & 0xff);
+ ix &= 0x00ffffff;
+ depval = NULL;
+ switch (deptype) {
+ default:
+ assert(depval != NULL);
+ break;
+ case 'P':
+ if (nprovides > 0) {
+ assert(ix < nprovides);
+ (void) rpmdsSetIx(fc->provides, ix-1);
+ if (rpmdsNext(fc->provides) >= 0)
+ depval = rpmdsDNEVR(fc->provides);
+ }
+ break;
+ case 'R':
+ if (nrequires > 0) {
+ assert(ix < nrequires);
+ (void) rpmdsSetIx(fc->requires, ix-1);
+ if (rpmdsNext(fc->requires) >= 0)
+ depval = rpmdsDNEVR(fc->requires);
+ }
+ break;
}
- break;
+ if (depval)
+ fprintf(fp, "\t%s\n", depval);
}
- if (depval)
- fprintf(fp, "\t%s\n", depval);
}
}
}
diff --git a/build/spec.c b/build/spec.c
index d3e6a6a..00dae39 100644
--- a/build/spec.c
+++ b/build/spec.c
@@ -288,7 +288,7 @@ int addSource(rpmSpec spec, Package pkg, const char
*field, rpmTag tag)
*fieldp = '\0';
nump = fieldp_backup;
- SKIPSPACE(nump);
+ if (nump) SKIPSPACE(nump);
if (nump == NULL || *nump == '\0') {
num = flag == RPMBUILD_ISSOURCE ? 0 : INT_MAX;
} else {
diff --git a/lib/fsm.c b/lib/fsm.c
index efb6f58..52ee88a 100644
--- a/lib/fsm.c
+++ b/lib/fsm.c
@@ -1106,7 +1106,7 @@ static int fsmCommitLinks(FSM_t fsm)
break;
}
- for (i = 0; i < fsm->li->nlink; i++) {
+ for (i = 0; fsm->li && i < fsm->li->nlink; i++) {
if (fsm->li->filex[i] < 0) continue;
fsm->ix = fsm->li->filex[i];
rc = fsmNext(fsm, FSM_MAP);
diff --git a/lib/headerfmt.c b/lib/headerfmt.c
index adf844a..440245b 100644
--- a/lib/headerfmt.c
+++ b/lib/headerfmt.c
@@ -640,15 +640,16 @@ static char * formatValue(headerSprintfArgs hsa,
sprintfTag tag, int element)
val = xstrdup("(none)");
}
- need = strlen(val);
+ if (val) {
+ need = strlen(val);
- if (val && need > 0) {
- t = hsaReserve(hsa, need);
- te = stpcpy(t, val);
- hsa->vallen += (te - t);
+ if (need > 0) {
+ t = hsaReserve(hsa, need);
+ te = stpcpy(t, val);
+ hsa->vallen += (te - t);
+ }
+ free(val);
}
- free(val);
-
return (hsa->val + hsa->vallen);
}
diff --git a/lib/psm.c b/lib/psm.c
index abf870f..4c23b2f 100644
--- a/lib/psm.c
+++ b/lib/psm.c
@@ -786,7 +786,7 @@ exit:
if (script) {
if (!rpmIsDebug())
xx = unlink(fn);
- fn = _free(fn);
+ if (fn) fn = _free(fn);
}
free(sname);
diff --git a/lib/rpmdb.c b/lib/rpmdb.c
index f6028e1..518e547 100644
--- a/lib/rpmdb.c
+++ b/lib/rpmdb.c
@@ -392,7 +392,7 @@ static inline void dbiGrowSet(dbiIndexSet set,
unsigned int nrecs)
*/
static int dbt2set(dbiIndex dbi, DBT * data, dbiIndexSet * setp)
{
- int _dbbyteswapped = dbiByteSwapped(dbi);
+ int _dbbyteswapped;
const char * sdbir;
dbiIndexSet set;
unsigned int i;
@@ -405,6 +405,8 @@ static int dbt2set(dbiIndex dbi, DBT * data,
dbiIndexSet * setp)
return 0;
}
+ _dbbyteswapped = dbiByteSwapped(dbi);
+
set = xcalloc(1, sizeof(*set));
dbiGrowSet(set, data->size / dbi->dbi_jlen);
set->count = data->size / dbi->dbi_jlen;
@@ -454,7 +456,7 @@ static int dbt2set(dbiIndex dbi, DBT * data,
dbiIndexSet * setp)
*/
static int set2dbt(dbiIndex dbi, DBT * data, dbiIndexSet set)
{
- int _dbbyteswapped = dbiByteSwapped(dbi);
+ int _dbbyteswapped;
char * tdbir;
unsigned int i;
@@ -468,6 +470,8 @@ static int set2dbt(dbiIndex dbi, DBT * data,
dbiIndexSet set)
}
tdbir = data->data = xmalloc(data->size);
+ _dbbyteswapped = dbiByteSwapped(dbi);
+
switch (dbi->dbi_jlen) {
default:
case 2*sizeof(int32_t):
@@ -1960,6 +1964,7 @@ Header rpmdbNextIterator(rpmdbMatchIterator mi)
size_t keylen;
int rc;
int xx;
+ union _dbswap mi_offset;
if (mi == NULL)
return NULL;
@@ -1987,8 +1992,6 @@ top:
uhlen = 0;
do {
- union _dbswap mi_offset;
-
if (mi->mi_set) {
if (!(mi->mi_setx < mi->mi_set->count))
return NULL;
@@ -2072,7 +2075,7 @@ top:
rpmRC rpmrc = RPMRC_NOTFOUND;
/* Don't bother re-checking a previously read header. */
- if (mi->mi_db->db_bits) {
+ if (mi->mi_db && mi->mi_db->db_bits) {
pbm_set * set;
set = PBM_REALLOC((pbm_set **)&mi->mi_db->db_bits,
diff --git a/lib/rpmlock.c b/lib/rpmlock.c
index d220bee..4b38894 100644
--- a/lib/rpmlock.c
+++ b/lib/rpmlock.c
@@ -36,8 +36,10 @@ static rpmlock rpmlock_new(const char *rootdir)
/* XXX oneshot to determine path for fcntl lock. */
if (rpmlock_path == NULL) {
char * t = rpmGenPath(rootdir, rpmlock_path_default, NULL);
- if (t == NULL || *t == '\0' || *t == '%')
+ if (t == NULL || *t == '\0' || *t == '%') {
+ if (t) free(t);
t = xstrdup(RPMLOCK_PATH);
+ }
rpmlock_path = xstrdup(t);
(void) rpmioMkpath(dirname(t), 0755, getuid(), getgid());
t = _free(t);
diff --git a/lib/transaction.c b/lib/transaction.c
index 88564f7..09908f9 100644
--- a/lib/transaction.c
+++ b/lib/transaction.c
@@ -746,9 +746,9 @@ static void skipInstallFiles(const rpmts ts, rpmte p)
bnlen = strlen(bn);
ix = rpmfiDX(fi);
dn = rpmfiDN(fi);
- dnlen = strlen(dn);
if (dn == NULL)
continue; /* XXX can't happen */
+ dnlen = strlen(dn);
drc[ix]++;
diff --git a/rpmio/base64.c b/rpmio/base64.c
index 6a21a4d..3ebf2a5 100644
--- a/rpmio/base64.c
+++ b/rpmio/base64.c
@@ -104,7 +104,7 @@ static int base64_decode_value(unsigned char value_in)
{
static const int decoding[] =
{62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51};
value_in -= 43;
- if (value_in > sizeof(decoding)/sizeof(int))
+ if (value_in >= sizeof(decoding)/sizeof(int))
return -1;
return decoding[value_in];
}
diff --git a/rpmio/macro.c b/rpmio/macro.c
index 11e23a3..7b1c783 100644
--- a/rpmio/macro.c
+++ b/rpmio/macro.c
@@ -558,7 +558,7 @@ doDefine(MacroBuf mb, const char * se, int level,
int expandbody)
rpmlog(RPMLOG_ERR,
_("Macro %%%s has unterminated body\n"), n);
se = s; /* XXX W2DO? */
- return se;
+ goto exit;
}
s++; /* XXX skip { */
strncpy(b, s, (se - s));
@@ -596,7 +596,7 @@ doDefine(MacroBuf mb, const char * se, int level,
int expandbody)
rpmlog(RPMLOG_ERR,
_("Macro %%%s has unterminated body\n"), n);
se = s; /* XXX W2DO? */
- return se;
+ goto exit;
}
/* Trim trailing blanks/newlines */
@@ -614,7 +614,7 @@ doDefine(MacroBuf mb, const char * se, int level,
int expandbody)
if (!((c = *n) && (risalpha(c) || c == '_') && (ne - n) > 2)) {
rpmlog(RPMLOG_ERR,
_("Macro %%%s has illegal name (%%define)\n"), n);
- return se;
+ goto exit;
}
/* Options must be terminated with ')' */
diff --git a/rpmio/rpmmalloc.c b/rpmio/rpmmalloc.c
index 5a71834..aad977c 100644
--- a/rpmio/rpmmalloc.c
+++ b/rpmio/rpmmalloc.c
@@ -75,6 +75,6 @@ char * rstrdup (const char *str)
void * rfree (void *ptr)
{
- free(ptr);
+ if (ptr) free(ptr);
return NULL;
}
diff --git a/rpmio/rpmstring.c b/rpmio/rpmstring.c
index 68543ce..f3d41a3 100644
--- a/rpmio/rpmstring.c
+++ b/rpmio/rpmstring.c
@@ -236,6 +236,7 @@ char *rstrscat(char **dest, const char *arg, ...)
memmove(p, s, size);
p += size;
}
+ va_end(ap);
*p = '\0';
if ( dest ) {
--
1.7.3.4
More information about the Rpm-maint
mailing list