255 Commits
Author SHA1 Message Date
David Kalnischkies 320245536a Include our config.h in all C++ files to avoid ODR violations
Some of our headers use APT_COMPILING_APT trickery to avoid exposing too
broadly details we don't want external clients to know and make use of.
The flip-side is that this can lead to different compilation units
seeing different definitions if they aren't all using the same config.
2022-05-07 10:45:44 +02:00
David Kalnischkies 70c669e256 Streamline access to barbarian architecture functionality
APT is not the place this information should be stored at, but it is a
good place to experiment and see what will be (not) needed in the future
for a proper implementation higher up the stack.

This is why "BarbarianArchitectures" is chosen instead of a more neutral
and/or sensible "VeryForeign" and isn't readily exported in the API to
other clients for this PoC as a to be drawn up standard will likely
require potentially incompatible changes. Having a then outdated and
slightly different implementation block a "good" name would be bad.

The functionality itself mostly exists (ignoring bugs) since the
introduction of MultiArch as we always had the risk of encountering
packages of architectures not known to dpkg (forced onto the system,
potentially before MultiArch) we had to deal with somehow and other
edge cases.

All this commit really does is allowing what could previously only be
achieved with editing sources.list and some conf options via a single
config option: -o APT::BarbarianArchitectures=foo,bar
2021-09-04 16:20:12 +02:00
Julian Andres Klode b5211b9b21 json: Encode NULL strings as null
This is the only nullable thing we have here.
2021-04-23 12:25:40 +02:00
Julian Andres Klode 09e3c0c855 json: Actually pop states
The JSON encoder only looked at the top state, but did not
pop it, so if we nested objects, we got stuck in whatever
the last state we pushed aside was, so in our example, we
wrongly get a comma inserted _after_ key "b":

{"a":[{}],
 "b":,[{}]
}
2021-04-23 12:25:40 +02:00
Julian Andres Klode 57b727af4e json: Escape strings using \u escape sequences, add test
This allows us to correctly encode strings containing quotation
marks, escape characters and control characters.

The test case is a bit nasty because it embeds private-cachefile.cc
for linkage reasons.
2021-04-23 12:25:40 +02:00
Julian Andres Klode 8613225f31 Check for and discard expected warning from MaybeAddAuth
MaybeAddAuth() here tells us that it refused to use the credentials
for an http source; but that caused the test suite to fail at a later
stage because we checked if there were any errors/warning. Strangely,
this is only triggered with LTO enabled.

Actually check that the warning is being set and then reject it.
2021-03-31 15:29:09 +02:00
David Kalnischkies c4da2ff42d Avoid overstepping bounds in config file parsing
Our configuration files are not security relevant, but having a parser
which avoids crashing on them even if they are seriously messed up is
not a bad idea anyway. It is also a good opportunity to brush up the
code a bit avoiding a few small string copies with our string_view.
2021-02-03 17:43:13 +01:00
David Kalnischkies e0743a85c5 Forbid negative values in unsigned StrToNum explicitly
strtoul(l) surprises us with parsing negative values which should not
exist in the places we use to parse them, so we can just downright
refuse them rather than trying to work with them by having them promoted
to huge positive values.
2021-02-03 17:36:46 +01:00
David Kalnischkies ed192f410d Don't parse \x and \0 past the end in DeEscapeString
This has no attack surface though as the loop is to end very soon anyhow
and the method only used while reading CD-ROM mountpoints which seems
like a very unlikely attack vector…
2021-02-03 17:36:45 +01:00
David Kalnischkies 10f13938bb Fix incorrect base64 encoding due to int promotion
For \xff and friends with the highest bit set and hence being a negative
value on signed char systems the wrong encoding is produced as we run
into undefined behaviour accessing negative array indexes.
We can avoid this problem simply by using an unsigned data type.
2021-02-03 17:36:45 +01:00
David Kalnischkies 1b3ad38914 Add a simple test for APT::String::DisplayLength
References: 2497198e95
Gbp-Dch: Ignore
2021-02-03 17:36:45 +01:00
Julian Andres Klode f9a621d335 patterns: Terminate short pattern by ~ and !
This allows patterns like ~nalpha~nbeta and ~nalpha!~nbeta to
work like they do in APT.

Also add a comment to remind readers that everything in START
should be in short too.

Cc: stable >= 2.0
2020-12-07 15:11:20 +01:00
David Kalnischkies c470d92366 Allow prefix to be a complete filename for GetTempFile
Our testcases had their own implementation of GetTempFile with the
feature of a temporary file with a choosen suffix. Merging this into
GetTempFile lets us drop this duplicate and hence test more our code
rather than testing our helpers for test implementation.

And then hashsums_test had another implementation… and extracttar wasn't
even trying to use a real tempfile… one GetTempFile to rule them all!
That also ensures that these tempfiles are created in a temporary
directory rather than the current directory which is a nice touch and
tries a little harder to clean up those tempfiles.
2020-05-18 15:55:36 +02:00
David Kalnischkies 110078022a Parse records including empty tag names correctly
No sensible file should include these, but even insensible files do not
gain unfair advantages with it as this parser does not deal with
security critical files before they haven't passed other checks like
signatures or hashsums.

The problem is that the parser accepts and parses empty tag names
correctly, but does not store the data parsed which will effect later
passes over the data resulting e.g. in the following tag containing
the name and value of the previous (empty) tag, its own tagname and its
own value or a crash due to an attempt to access invalid memory
depending on who passes over the data and what is done with it.

This commit fixes both, the incidient of the crash reported by
Anatoly Trosinenko who reproduced it via apt-sortpkgs:
| $ cat /tmp/Packages-null
| 0:
| PACKAGE:0
|
| :
| PACKAGE:
|
| PACKAGE::
| $ apt-sortpkgs /tmp/Packages-null
and the deeper parsing issue shown by the included testcase.

Reported-By: Anatoly Trosinenko <anatoly.trosinenko@gmail.com>
References: 8710a36a01
2020-02-26 18:12:18 +01:00
Julian Andres Klode e8016805b8 Remove code tagged APT_PKG_590, add some missing includes
Remove all code scheduled to be removed after 5.90, and fix
files to include files they previously got from hashes.h
including more headers.
2020-02-18 12:48:38 +01:00
Julian Andres Klode 404771d0ec patterns: test for empty terms, reject them 2020-02-03 12:55:54 +01:00
Julian Andres Klode 11a40ab11f Correctly stop parsing short form arguments on space, also on ?
we have to stop parsing on space so that things like ~ramd64 | ~rall
work correctly.

aptitude does not stop parsing on ?, but we'll do as it gets very
confusing otherwise if you write stuff like ~ramd64?name(foo), and
it resolves to ?and(?architecture(amd64?name), (foo))...
2020-02-03 12:55:54 +01:00
Julian Andres Klode 8886ea1630 patterns: Implement parsing of (...) groups 2020-02-03 12:55:54 +01:00
Julian Andres Klode d6f38436a2 Implement | as or 2020-02-03 12:55:54 +01:00
Julian Andres Klode 250119362e patterns: Parse sequence of patterns as ?and 2020-02-03 12:55:54 +01:00
Julian Andres Klode ebe5f39bfb patterns: Allow bare words only in arguments
This changes the syntax from approximately

	expr = unary
	unary = '!'? primary
	primary = pattern | short-pattern | word | quoted-word
	pattern = '?' name [ '(' expr [',' expr]* ')' ]
	short-pattern = ~ name | ~name expr
to:

        primary = pattern | short-pattern
        argument = word | quoted-word | expr
        pattern = '?' name [ '(' argument [',' argument]* ')' ]
        short-pattern = ~ name | ~name argument
2020-02-03 12:55:54 +01:00
Julian Andres Klode 8d4967d3a1 patterns: Implement unary ! 2020-02-03 12:55:54 +01:00
Julian Andres Klode fd43b1694f Implement short patterns (patterns starting with ~)
Also make pattern detector in cacheset and private's list accept
such patterns. We probably should just try to parse and see if it
is a (start of a) pattern.
2020-02-03 12:55:54 +01:00
Julian Andres Klode 5872a2e7dd Deprecate the Summation classes and mark them for removal 2020-01-14 13:10:36 +01:00
Julian Andres Klode 436993e9d7 gtests: Fix netrc parser test regression from https-only changes
We missed that because the CI never ran GTests, because it did
not find the GTest library and failed silently (until the previous
commit).
2020-01-07 21:45:53 +01:00