Commit Graph

1281 Commits

Author SHA1 Message Date
Panu Matilainen 8fb86477c7 Add a separate mutex for serializing logging events
- Logging output (including callback activities) is conceptually always
  a "write"-event, but independent of log context manipulation so it
  needs a mutex of its own to serialize log events. Previously we
  write-locked only for records that need saving, so messages above
  warning level could get interleaved.
2014-10-24 09:18:32 +03:00
Panu Matilainen df8718190b Free context lock before logging output (and callback)
- Grab the bits we need from context to local variables and free
  the lock before callback and output, either of which could involve
  writing to files (and in case of callback, who knows what) so
  it could take long and prevent something silly like rpmIsDebug() from
  proceeding. Also this way callback can call some rpmlog-related
  functions without much worries of getting stuck or other trouble.
2014-10-24 08:58:03 +03:00
Panu Matilainen db10a21efb Delay lock context acquisition to time of actual logging
- Checking whether we need to log requires a (read) lock on entry,
  but most of the time that's all. Hide that locking behind calling
  rpmlogSetMask() and move ctx acquire into dolog()
- Means we're now taking two different logs when actually logging,
  but since that's the rarer condition it hardly matters.
2014-10-24 08:39:51 +03:00
Panu Matilainen 19ce9ee104 rpmlogSetMask() only needs write-lock on non-zero mask 2014-10-24 08:34:56 +03:00
Panu Matilainen 4cab3a1691 Handle context aquisition failures throughout rpmlog
- Locking can fail, and we need to handle it somehow. Return
  NULL context and handle that in callers, as in "dont crash".
2014-10-23 15:33:34 +03:00
Panu Matilainen 841c5e5fd7 Eliminate stupid asserts from rpmlogRecMessage and -Priority() 2014-10-23 15:07:09 +03:00
Panu Matilainen 7d05842996 Remove incorrect comment
- A string pointer returned rpmlogMessage() is in fact guaranteed to
  be valid until rpmlogClose(), because its malloced separately
  from the owning record. So while the address of the owning record
  can change via realloc(), the contained message stays put.
2014-10-23 12:44:45 +03:00
Panu Matilainen ace7fe9d58 Enable the unused macro warning again, now without performance penalty
- Track non-global macro definitions in a helper variable, this
  eliminates the need for costly macro table walking at end of each
  expansion cycle as we only bother doing it if non-global macros
  were defined during a given expansion cycle.
2014-09-02 11:50:41 +03:00
Panu Matilainen 0ffc0e29e9 Dont try to close non-existent fdno's on Fclose()
- Commit 547a004b7e introduced a regression
  on stacked io Fclose() return code, details at
  http://lists.rpm.org/pipermail/rpm-maint/2014-August/003731.html
- The original code seems fishy in other ways (missed errors), this
  hopefully fixes both cases by only attempting to close actually
  open fdno's and only considering actual closes for error codes.
2014-08-27 08:33:05 +03:00
Panu Matilainen d4ab1d82d7 Macro-expand %{load:...} argument to make the thing more useful... 2014-07-01 12:05:51 +03:00
Panu Matilainen 3f2f483515 Use unified libtool version for all our libraries
- Our libraries are in reality so interdependent that its not even
  possible to use them independently of others, so having them
  all follow sort of independent versioning information just doesn't
  make any sense and is a PITA everytime I need to touch the data.
- This causes librpmsign soname bump with no good reason so its
  probably "evil" and all ... so sue me, its not as if anybody
  is actually using this library outside rpm itself.
2014-06-25 13:21:00 +03:00
Panu Matilainen 817959609b Handle line continuation in grabArgs() (related to RhBug:1045723)
- Commit 1bdcd05008 to fix RhBug:1045723
  broke some funky java macros in Fedora which include line continuation
  in the argument (comments 6-7 in the bug). That it ever worked seems
  far more like luck than by design but since this seems to fix it...
2014-06-25 11:32:24 +03:00
Panu Matilainen eb62542695 Fix ancient buffer overflow on unterminated macro options
- Test for terminating ')' existence before copying, otherwise we'll
  end up walking over the edge of the world.
- Return address from doDefine() on error will likely differ after
  this, whether that actually affects anything remains to be seen...
2014-06-11 15:40:00 +03:00
Panu Matilainen 272033470b Avoid pointless large stack alloction (RhBug:1106594)
- Within rpm itself, this allocation from 12 years ago doesn't come anywhere
  close to stack limits on Linux at least, but since we're a library
  we should be considerate to API users stack needs as well. Allocate
  the buffer from heap instead, its not performance critical either
  since this will always be limited by physical IO and digest calculation
  speed rather than a single malloc.
2014-06-11 13:16:06 +03:00
Panu Matilainen 4089316531 Fix ancient buffer overflows on macro define and undefine (RhBug:1087000)
- Both doDefine() and doUndefine() assumed the macro string would
  always fit into MACROBUFSIZ, which of course is true for any
  normal use but we cant make such assumptions.
- In the case of %define/%global there are various other overrun-issues
  that need further changes to fix.
2014-06-09 14:35:19 +03:00
Panu Matilainen e2659684b4 Revert back to DSA-1 only support for NSS
- This essentially reverts commit fe5a1e5dfa
  which apparently causes intermittent failures with DSA-1. Look at
  DSA-2 again on some sunnier day...
2014-05-19 15:50:32 +03:00
Panu Matilainen f07490f5dc Only enable the unused macro warning on errors and when tracing
- In the current macro implementation the check is simply far too
  expensive to leave on always. Its useful though, so enable it
  when tracing macro expansion, in which case you're probably
  troubleshooting some macro-issues...
2014-03-26 11:43:41 +02:00
Panu Matilainen b19348342b And finally, actually enable the unused macro warning.
- Reword the message to something hopefully little more understandable,
  change from error to a warning (only matters for output)
- Check unused macros at end of every scope, but unlike with parametrized
  macros, dont actually delete
- Only whine once per unused macro due to the above to avoid spurious
  output due to above
- This catches the common error in specs where %define is used in a scope
  unintentionally, eg "%{!?foo: %define foo 1}" where the just defined
  macro should actually fall out of scope upon the closing }, but
  only gets erased if any parametrized macro is "called" and causes
  insane behavior such as described in RhBug:552944. So at least we'll
  warn on these situations.
2014-02-28 16:45:33 +02:00
Panu Matilainen f9a6855faa Consider macro used if we've so much as looked it up 2014-02-28 16:38:56 +02:00
Panu Matilainen e65e27ab25 Make macro deletion in freeArgs() optional
- Not used yet, but using this for issuing warnings only
2014-02-28 16:12:33 +02:00
Panu Matilainen ae58c96248 Move macro usage tracking to flags
- We dont really care how many times a macro has been used, just
  whether it has been used or not...
2014-02-28 16:10:14 +02:00
Panu Matilainen fae7325f8d Add + use a flag for identifying automatic macros
- In practise doesn't change anything visible as the "macro not used"
  message is disabled, but tracking a flag bit is saner than
  strlen() + strchr() + bunch of other stuff which isn't even correct:
  prior to this %## would've triggered "unused" errors which is plain
  wrong, and complaining about unused %1 %2 ... isn't really right
  either.
2014-02-28 15:57:09 +02:00
Panu Matilainen 647f0d488f Revert stricter macro substitution syntax entirely, for now
- Revert back to pre commit c22d5b1299
  state wrt macro substitution. The commit does have fixes we want
  but it also breaks valid cases which is not okay. We really need
  a far more thorough macro test suite before these kind of changes,
  and also need to do the changes in more controlled pieces.
2014-02-25 16:17:37 +02:00
Panu Matilainen df686992d7 Perform as-is substitution for %{name} form too, again
- Commit c22d5b1299 changed the parsing
  to require a valid name in %{name} macro, but this outlaws existing
  uses such as %{foo_%{bar}_something}. Relaxing the %{name} form
  to use as-is substitution as well allows these to work again.
2014-02-20 10:42:09 +02:00
Panu Matilainen 1bdcd05008 Dont eat newlines on parametrized macro invocations (RhBug:1045723)
- Makes the testcase from commit f082b5baa4
  succeed. While the old behavior is non-sensical and most likely entirely
  unintentional, we're changing a very long-standing behavior here (tested
  back to rpm 4.4.x and almost certainly much much older than that) so
  its entirely possible people are actually relying on the old
  behavior. Lets see what breaks...
2014-02-19 14:24:54 +02:00
Panu Matilainen 85b62554d2 Make room for SHA224 in digest bundles. Doh.
- Should've really been in commit 20cfa7d2b4
  but at the time NSS didn't even support SHA-224 so it was untestable.
  Now that it does, and somebody actually bothered to test...
  Fixes RhBug:1066494.
2014-02-18 18:26:38 +02:00
Panu Matilainen 51cc2ec3b1 Support macro file load from Lua too (similar in rpm5.org as well) 2014-01-30 15:22:29 +02:00
Panu Matilainen 784dfb4219 Port %{load:<path>} macro from rpm5.org
- Allow loading custom macro files from eg specs. This is quite different
  from %include which inlines arbitrary content into a spec, but which
  cannot be used for including macro files as their syntax is entirely
  different. Both have their uses.
- rpm5.org also supports %load within macro files, we dont as I find the
  imperative %load very alien in what's otherwise an entirely declarative
  file "format"
2014-01-30 14:57:52 +02:00
Panu Matilainen f2d5e7ecd7 Clarify a couple of comments 2013-12-02 13:13:00 +02:00
Panu Matilainen 25406a133f Track chunk usage in the pool struct directly
- This simplifies things a bit as we dont need to worry about the
  id storage and the starting location of the next string in advance.
- Also make it clearer the string is copied into the current chunk,
  to which pool->offs only points to. Make pool->offs const to
  enforce the strings are never written through it.
2013-12-02 12:47:23 +02:00
Panu Matilainen 938b86b8bd Clarify pool chunk allocation
- Assign newly alloc'ed chunks to pool->chunks, pool->offs just
  contains pointers into the chunks. This doesn't change actual
  behavior at all, just (IMO) clarifies the code a bit.
2013-12-02 12:29:21 +02:00
Panu Matilainen c24930219a Fix a harmless off-by-one in rpmstrPoolPu()
- ssize already has the trailing \0 accounted for
2013-12-02 10:54:18 +02:00
Panu Matilainen cfe99e08ad Drop the end-of-chunk dummy entries from string pool
- As pointed out by Michael Schroeder in
  http://lists.rpm.org/pipermail/rpm-maint/2013-September/003605.html,
  the dummy entries used for optimizing rpmstrPoolStrlen() are
  problematic in number of ways:
  - Walking the id's in a pool is unreliable, and rehashing can cause
    bogus empty strings to be added to a pool where they otherwise
    do not exist
  - rpmstrPoolNumStr() is not accurate when more than one chunk is in use
- Unfortunately this means giving up the rpmstrPoolStrlen() optimization,
  for now at least.
2013-12-02 10:45:33 +02:00
Michael Schroeder 41a01d2563 Fix off-by-one in rpmstrPoolRehash()
- pool->offs_size is the last used id, thus it should be "<=" instead of "<"

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2013-11-29 10:42:36 +02:00
Panu Matilainen 5f3598a700 Fix segfault executing a -p <lua> scriptlet without a body (RhBug:1004062)
- There are any number of places where this could be fixed, but
  to keep the behavior similar to eg /bin/sh scriptlet without a body,
  just turn a non-existent script into an empty string.
2013-09-06 16:31:25 +03:00
Michael Schroeder 1777d2a492 digest_beecrypt: add missing break statement
Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2013-08-30 08:33:00 +03:00
Michael Schroeder 1fe1873955 digest_beecryt: do not call pgpMpiLen(p) so many times
Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2013-08-30 08:33:00 +03:00
Michael Schroeder 817481900e digest_beecrypt: move pkcs1 padding into a separate function
Also use the byte count of the MPI as block size instead of using
MP_WORDS_TO_BITS, as the latter depends on the internal word size
used in the beecryt library.

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2013-08-30 08:33:00 +03:00
Michael Schroeder e83256f3bc digest_beecrypt: use the length of the pubkey MPI when doing PKCS padding
Before, the code used the MPI from the signature, which may have
a smaller size.

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2013-08-28 20:34:11 +03:00
Michael Schroeder c18840147c digest_beecrypt: get rid of unneeded helper functions
Use the _bin variants instead of converting the MPIs to hex.
Also check the exit status of the beecrypt functions.

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2013-08-28 20:34:11 +03:00
Michael Schroeder ee8b3653c3 digest_beecrypt: implement DSA2 hash truncation (untested)
Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2013-08-28 20:34:11 +03:00
Michael Schroeder 4d34ca5906 digest_beecrypt: plug memory leaks
Free the beecrypt numbers when freeing the key/sig data.

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2013-08-28 20:34:11 +03:00
Michael Schroeder 70af849f0c Check the mpi length before calling setmpi, remove pend parameter
Simplifies the code a lot. Also check that that there's room for the
mpi len before calling pgpMpiLen().

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2013-08-28 20:34:11 +03:00
Panu Matilainen ae57958971 Fix ages old segfault on trying to expand %{lua} (RhBug:972646)
- Using the already calculated macro arg + arglen for copying the
  buffer instead of buggy local variant helps... This is as old as
  the embedded lua interpreter in rpm, close to a decade.
- Besides fixing the segfault, this actually makes it behave like
  other built-ins, evaluating to empty string when an empty arguments
  or no arguments are passed.
2013-06-11 11:33:53 +03:00
Panu Matilainen 99b40fe5ab Dont try to expand zero-length arguments to built-in macros
- Previously various built-in macros without an actual argument,
  eg %{basename:} would evaluate to "}" which makes no sense
  whatsoever. With this, they evaluate to an empty string similarly
  to when no argument is passed, eg %{basename}. Arguably these
  should emit an error/warning instead but for now...
2013-06-11 10:46:50 +03:00
Panu Matilainen f173f747cd Revert "Fix segfault trying to expand %{lua} (RhBug:972646)"
- This reverts commit 43a34e1554,
  contrary to what the comment said the is NOT how other built-ins
  behave, they evaluate to an empty string without an argument.
  Better fix needed...
2013-06-10 15:31:01 +03:00
Panu Matilainen 43a34e1554 Fix segfault trying to expand %{lua} (RhBug:972646)
- %{lua:...} is used for invoking the embedded Lua interpreter, in
  which case the script must be passed as the macro argument. If
  no argument is passed, let it fall through to normal macro expansion.
  This might not be the most sensible behavior possible but at least
  its in line with what currently happens with other similar built-in
  macros.
2013-06-10 14:44:55 +03:00
Panu Matilainen 71e2d38e3d Make macros thread-safe ... sort of
- Add the actual locking into macro context acquire + release. We're
  using a mutex instead of rwlock because currently any macro can
  involve defines and undefines and we dont know it beforehand. So
  we just use a bigger hammer...
- The macro engine internals shouldn't need recursive mutexes but
  unfortunately Lua macro bindings, which are limited to the
  lock-on-entry interfaces can and do get called recursively
  from macros so currently there's not much choice but to use
  recursive mutex for the macro contexts. What makes it even uglier
  is that there's no portable static initializer for recursive mutex
  so we need to add yet another pthread-construct to safely dynamically
  initialize the mutexes :(
- Of course this doesn't make bunch of threads simultaneously messing
  with macros behave sane: if one thread tries to load new macros
  and the other one frees them, they shouldn't crash but the
  results are unlikely to be what the caller intended. The purpose
  here is just to allow the occasional rpmExpand() and such to
  complete without crashing and burning when multiple threads are
  doing stuff like trying to read packages from disk.
2013-05-22 15:35:29 +03:00
Panu Matilainen 09499d994b Add and use internal (lockless) function for copying macro contexts
- rpmLoadMacros() is a dumb name for what it does: it copies macros
  from one context to another. The only actual use within rpm is
  to copy back the cli macros to global context, but make the
  internal helper more flexible by allowing copying to any context.
- rpmLoadMacros() is mostly just a dumb wrapper around copyMacros()
  to grab locks and guard against copying global context to itself.
  Adjust rpmInitMacros() to use copyMacros() as it already has a
  lock on the global table, it just needs a lock on the cli contexts
  as well.
2013-05-22 11:43:40 +03:00
Panu Matilainen 62d36cce61 Add and use internal (lockless) version of rpmLoadMacroFile()
- rpmInitMacros() already grabs the (theoretical) lock on entry
  so we shouldn't try to grab it again, use the new lockless
  loadMacroFile() version for the purpose.
- rpmLoadMacroFile() is now just a simple lock-wrapper around
  loadMacroFile()
2013-05-22 11:27:29 +03:00