diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2019-01-17 13:11:06 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2020-03-26 11:57:58 +0200 |
commit | e0e753d721dc0e11e36fe84125ccca36ef26f22e (patch) | |
tree | 7264b0dd4ee521880971d95fbb806c0c0ff2f96e | |
parent | b883c1f00de1968ae4b277ef4447c4fd8eadf3d1 (diff) | |
download | rpm-e0e753d721dc0e11e36fe84125ccca36ef26f22e.tar.gz |
Don't let rpmlog() affect errno
There are any number of things that can go wrong and affect errno
inside rpmlog(), but having a function that by its declaration cannot
fail messing with errno is pretty dumb. Always save and restore
errno from rpmlog().
(cherry picked from commit 61b0287831e9bddaf9c333c9678bf698d72bd92c)
-rw-r--r-- | rpmio/rpmlog.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/rpmio/rpmlog.c b/rpmio/rpmlog.c index d9f5cfaab..d52b897fc 100644 --- a/rpmio/rpmlog.c +++ b/rpmio/rpmlog.c @@ -407,6 +407,7 @@ static void dolog(struct rpmlogRec_s *rec, int saverec) void rpmlog (int code, const char *fmt, ...) { + int saved_errno = errno; unsigned pri = RPMLOG_PRI(code); unsigned mask = RPMLOG_MASK(pri); int saverec = (pri <= RPMLOG_WARNING); @@ -414,7 +415,7 @@ void rpmlog (int code, const char *fmt, ...) int n; if ((mask & rpmlogSetMask(0)) == 0) - return; + goto exit; va_start(ap, fmt); n = vsnprintf(NULL, 0, fmt, ap); @@ -437,4 +438,6 @@ void rpmlog (int code, const char *fmt, ...) free(msg); } +exit: + errno = saved_errno; } |