Commit Graph

4651 Commits

Author SHA1 Message Date
qu1ck 2fab317040
Add TR_TORRENT_LABELS to env variables available to scripts (#868)
* Add TR_TORRENT_LABELS to env variables available to scripts

* Add unit test for tr_strjoin

Co-authored-by: Charles Kerr <charles@charleskerr.com>
2020-05-13 18:54:44 -05:00
Mingye Wang d7f2dee4e0
crypto-utils: do tr_rand_int without abs (#1198)
* crypto-utils: do tr_rand_int without abs

There is really not much point in trying to abs a random int when you can just interpret it as unsigned in the first place.

* fixup! trailing space

how did this get in here?

* fixup! unsigned int

Co-authored-by: Charles Kerr <charles@charleskerr.com>
2020-05-11 20:34:03 -05:00
Tom Richards a82e728ad5
fix: memory leak in magnet parsing (#1222)
* Fix memory leak in magnet parsing

* Update libtransmission/magnet.c

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* Lint

Co-authored-by: Charles Kerr <charles@charleskerr.com>
2020-05-11 19:57:06 -05:00
Charles Kerr fa6df52d58
chore: remove unused methods (#1207)
* chore: remove unused methods in qt client

* chore: remove unused libtransmission methods

* chore: remove unused gtk methods

* chore: remove more unused libtransmission methods

* chore: remove more unused code found by @reardonia
2020-05-11 17:20:46 -05:00
Charles Kerr 87c9287b6a
refactor: in tr_truncd(), use DBL_DIG in printf() (#1186)
Previously it was calculated from `log10(1.0 / DBL_EPISILON) - 1`;
however, there's no need to calculate it out when there's an ANSI
standard that already spells it out consisely.
2020-05-01 22:11:45 -05:00
Mike Gelfand 2123adf8e5 CVE-2018-10756: Fix heap-use-after-free in tr_variantWalk
In libtransmission/variant.c, function tr_variantWalk, when the variant
stack is reallocated, a pointer to the previously allocated memory
region is kept. This address is later accessed (heap use-after-free)
while walking back down the stack, causing the application to crash.
The application can be any application which uses libtransmission, such
as transmission-daemon, transmission-gtk, transmission-show, etc.

Reported-by: Tom Richards <tom@tomrichards.net>
2020-04-29 17:29:38 +03:00
Bogdan Vasiliev a6482b0061
GTK: behavior improvements of the torrent details window (#892)
* gtk: torrent details file-list default sort

* gtk: save torrent details window size

* gtk: torrent details window size & sort, code style

* gtk: torrent details window, conf.c dict fix

Co-authored-by: Charles Kerr <ckerr@github.com>
2020-04-27 16:34:02 -05:00
RobCrowston 6bb8b2e78a
Refactor tr_torrentFindFile2 (#921)
* Factor-out file seek in tr_torrentFindFile2.

* Update libtransmission/torrent.c

Co-Authored-By: RobCrowston <crowston@protonmail.com>

* Fix code style.

Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
Co-authored-by: Charles Kerr <ckerr@github.com>
2020-04-27 15:07:01 -05:00
Charles Kerr 44fc571a67
feat: add editDate to RPC (#1056)
* feat: add tr_stat.infoDate to note tr_info changes

The last time during this session that any tr_info field changed
(e.g. trackers/filenames edited or magnet torrent got metadata).
RPC clients can monitor this to know when to reload fields which
don't usually change.
2019-11-12 17:13:42 -06:00
Charles Kerr c62cb35fd4
qt client speedups
* faster updating of trackers combobox.
* generate trackerDisplayNames just once per torrent
* refactor: cache torrent delegate's warning emblem
* refactor: change mainwin refresh debounce to 200ms
* refactor: do not store trackers, hosts in QVariant
* refactor: don't use `virtual` when it's not needed
* refactor: faster counting torrents-matching-filter
* refactor: faster tracker handling in filterbar
* refactor: improve json parser's prealloc heuristic
* refactor: make Torrent::hasError() faster
* refactor: remove redundant speed stats collection
* refactor: remove unnecessary tor->isQueued() calls
* refactor: use unordered containers where possible
* scale favicons only once, when adding to the cache
2019-11-11 19:37:05 -06:00
Charles Kerr 49fdd0b430
chore: update jsonsl parser snapshot (#1050)
source: https://github.com/mnunberg/jsonsl
2019-11-09 18:06:36 -06:00
Charles Kerr 96f76999aa
feat: add "table" format in torrent-get RPC (#1049)
* feat: add optional "format" arg to torrent-get RPC

If the "format" request was "objects" (default), "torrents" will be an
array of objects, each of which contains the key/value pairs matching
the request's "fields" arg. This is unchanged from previous versions.

If the format was "table", then "torrents" will be an array of arrays.
The first row holds the keys and each remaining row holds a torrent's
values for those keys. This format is more efficient in terms of JSON
generation and JSON parsing.
2019-11-09 17:02:23 -06:00
Charles Kerr abac811dd2
fix: gcc warnings in libtransmission/ and utils/ (#843)
* fix: __attribute__(__printf__) warnings

* fix: implicit fallthrough warning

* fixup! fix: implicit fallthrough warning

* fix: disable warnings for 3rd party code

Since we want to leave upstream code as-is

* fixup! fix: disable warnings for 3rd party code

* fixup! fix: disable warnings for 3rd party code

* silence spurious alignment warning

Xrefs
Discussion: https://stackoverflow.com/a/35554349
Macro inspiration: 90ac46f710/f/src/util/util_safealign.h (_35)

* fixup! fix: disable warnings for 3rd party code

* fixup! fix: implicit fallthrough warning

* make uncrustify happy

* remove uncrustify-test.sh

that's probably off-topic for this PR

* fixup! fix: __attribute__(__printf__) warnings

* Update libtransmission/CMakeLists.txt

Co-Authored-By: ckerr <ckerr@github.com>

* fixup! silence spurious alignment warning

* use -w for DISABLE_WARNINGS in Clang

* refactor: fix libtransmission deprecation warnings

* fix: pthread_create's start_routine's return value

This was defined as `void` on non-Windows but should have been `void*`

* chore: uncrustify

* fix: add DISABLE_WARNINGS option for SunPro Studio

* fix "unused in lambda capture" warnings by clang++

* fix 'increases required alignment' warning

Caused from storing int16_t's in a char array.

* fix net.c 'increases required alignment' warning

The code passes in a `struct sockaddr_storage*` which is a padded struct
large enough for the necessary alignment. Unfortunately it was recast as
a `struct sockaddr*` which has less padding and a smaller alignment. The
warning occrred because of these differing alignments.

* make building quieter so warnings are more visible

* fixup! fix 'increases required alignment' warning

* Fix -Wcast-function-type warnings in GTK+ app code

https://gitlab.gnome.org/GNOME/gnome-terminal/issues/96 talks about both
the issue and its solution.

GCC 8's -Wcast-function-type, enabled by -Wextra, is problematic in glib
applications because it's idiomatic there to recast function signatures,
e.g. `g_slist_free(list, (GFunc)g_free, NULL);`.

Disabling the warning with pragmas causes "unrecognized pragma" warnings
on clang and older versions of gcc, and disabling the warning could miss
actual bugs. GCC defines `void (*)(void)` as a special case that matches
anything so we can silence warnings by double-casting through GCallback.

In the previous example, the warning is silenced by changing the code to
read `g_slist_free(list, (GFunc)(GCallback)g_free, NULL);`).

* fixup! fix "unused in lambda capture" warnings by clang++

* fixup! fix "unused in lambda capture" warnings by clang++

* fix two more libtransmission compiler warnings

* fix: in watchdir, use TR_ENABLE_ASSERTS not NDEBUG
2019-11-06 11:27:03 -06:00
Tom Forbes 8d7fbb5d45 Increase the buffer size used in tr_moveFile (#933)
In some filesystems, including ones mounted on a network drive, using a small buffer size 
significantly hurts copy performance. Upping the buffer to 1024kb to increase copy performance.
2019-11-06 09:46:13 -06:00
Pavel Shlyak 2ef07517b6 Cleanup duplicates in clients.c (#991) 2019-10-21 08:20:40 -05:00
Mingye Wang bcf8128400 Unify/Modernize TOS to DSCP standards (#737)
* Unify/Modernize TOS to DSCP standards

The set of pre-named TOS values are now renamed to the latest DSCP
standards, with traffic classes and everything exciting. To keep
everything in the same place, a segment has been added to net.h to keep
the currently named values.

A result of these changes is that "lowcost" is probably no longer
harmless, as it now encourages the router to preferentially drop the
packages when bandwidth requires so. "lowdelay" is assigned to a pretty
high AF class for SIP and stuff. I am not sure at all about the
"throughput" assignment. I mean, the whole point of DSCP-fication is
translating from the old ToS bits to a more precedence-based notation,
and precedence is supposed to lie beside the old 4 ToS bits...

A funny interaction between the AFxy and the old ToS fields lies in
the old "reliability" (0x08) field. All odd numbers of y (1, 3 : low,
high) switches it on. If you spend 5 more minutes on it you can probably
come up with "pun" values that hold similar meanings in DSCP and
Prec/ToS.

By removing the IPv6 override, I should have kind of satisfied the #692
request.

Fixes: #692
2019-07-21 14:09:04 +03:00
Mike Gelfand eef4799388 Update Uncrustify config to 0.69 2019-07-15 02:30:41 +03:00
Mike Gelfand 35ed02a1fd Use explicit boolean conversions (follow-up) 2019-07-14 22:57:40 +03:00
Mike Gelfand 10cdd7f790 Use explicit boolean conversions 2019-07-14 16:25:07 +03:00
Mike Gelfand 16d385e4c7 Fixup code style 2019-07-13 23:02:27 +03:00
Mike Gelfand ec79767e5f Support OFD locks and missing flock 2019-07-13 22:53:04 +03:00
Mike Gelfand a3e4919385 Introduce `tr_str_is_empty` to relay intent better 2019-07-13 12:00:06 +03:00
Mike Gelfand bff188c2cf Fully cover `tr_metainfo_sanitize_path_component` 2019-06-24 06:32:38 +03:00
Mike Gelfand 99033b067d Sanitize suspicious path components instead of rejecting them
Apply the same rules on all the supported platforms to avoid issues
with network shares and alien file systems.

For future compatibility, explicitly mark adjusted paths as renamed.

Fixes: #294
2019-06-23 18:08:31 +03:00
Mike Gelfand 139f3a3f4b Add missing declaration for `tr_strcasestr` 2019-06-23 12:07:33 +03:00
Mike Gelfand f3968b7708 Load CA certs from system store on Windows / OpenSSL
Fixes: #446
2019-06-23 11:59:53 +03:00
LaserEyess 750589101a Parse session-id header case-insensitively (#765)
RFC 2616 defines headers as case-insensitive, so if rpc is behind a
reverse proxy that lowers the case of headers, transmission will not
parse them correctly.

A new wrapper function, `tr_strcasestr` is added to
libtransmission/utils.c to allow for comparisons of headers case
insensitively, and checks in cmake and autogen are included.
2019-03-17 17:37:52 +03:00
Mike Gelfand 5693e59256 Define each identifier in a dedicated statement
* MISRA C++:2008, 8-0-1 - An init-declarator-list or a member-declarator-list
  shall consist of a single init-declarator or member-declarator respectively
* CERT, DCL52-J. - Do not declare more than one variable per declaration
* CERT, DCL04-C. - Do not declare more than one variable per declaration
2019-03-17 09:15:35 +03:00
Mike Gelfand 97a0fed734 Remove side effects from right hand operands of && or ||
* MISRA C:2004, 12.4 - The right-hand operand of a logical && or || operator
  shall not contain side effects.
* MISRA C++:2008, 5-14-1 - The right hand operand of a logical && or ||
  operator shall not contain side effects.
* MISRA C:2012, 13.5 - The right hand operand of a logical && or || operator
  shall not contain persistent side effects
* CERT, EXP02-C. - Be aware of the short-circuit behavior of the logical AND
  and OR operators
2019-03-17 09:09:08 +03:00
Mike Gelfand 17307e7484 Extract assignments from expression
Assignments explicitly enclosed in parentheses are ignored.

* MISRA C:2004, 13.1 - Assignment operators shall not be used in expressions
  that yield a Boolean value
* MISRA C++:2008, 6-2-1 - Assignment operators shall not be used in
  sub-expressions
* MISRA C:2012, 13.4 - The result of an assignment operator should not be used
* MITRE, CWE-481 - Assigning instead of Comparing
* CERT, EXP45-C. - Do not perform assignments in selection statements
* CERT, EXP51-J. - Do not perform assignments in conditional expressions
2019-03-17 08:00:15 +03:00
Mike Gelfand d3b8982195 Uppercase the literal suffixes
* MISRA C++:2008, 2-13-4 - Literal suffixes shall be upper case
* MISRA C:2012, 7.3 - The lowercase character "l" shall not be used in a
  literal suffix
* CERT DCL16-C. - Use "L," not "l," to indicate a long value
* CERT, DCL50-J. - Use visually distinct identifiers
2019-03-17 07:07:48 +03:00
Mike Gelfand 698bb2c418 Attempt to explain something to Coverity
I'm seeing 7 potentially false reported issues re. use of uninitialized buffer
data here. It seems that `read` function should be properly supported by
Coverity, but maybe it can't figure out the postconditions of it properly...
Walking in the dark here.
2019-03-13 05:32:35 +03:00
Mike Gelfand 10b0a280b1 Let compiler calculate static quark lenghts for us 2019-03-13 00:01:17 +03:00
Mike Gelfand 1442f8fded Fix build break from previous commit on old Clangs
Remove static assert altogether: it should have worked everywhere anyway,
otherwise there is no point.

Add a few casts here and there to ensure proper type for directory handle.
2019-03-10 19:52:27 +03:00
Mike Gelfand 36110e18c4 Fix build on E2K with LCC (patch by Michael Shigorin, ALT Linux) 2019-03-10 19:35:10 +03:00
Charles Kerr 309d97c578
fix: Coverity warnings (#842)
* Silence coverity CHECKED_RETURN on added.f load

The existing code behaved alright since added.f is optional.
However, by testing for success we can both silence the warning
and prevent a useless initialization of NULL/0 to added_f and
added_f_length.

* Silence coverity CHECKED_RETURN on added6.f load

ipv6 variant of previous commit.

* Silence coverity CHECKED_RETURN writing benc strs

saveStringFunc() gets the target string by calling tr_variantGetStr().
It previously didn't check to see if this function succeeded because
saveStringFunc() isn't reached without the type already being known.
However, checking the return value costs nothing and makes Coverity happy.

* Silence coverity CHECKED_RETURN on ut metadata

Like earlier few Coverity commits in this PR, we're handling optional
values by declaring stack locals set to the default (e.g. -1) and then
trying to read the variant.

Unlike the earlier commits, there is a two-part step to thise read:
checking for the metadata, then checking for the individual fields.
The earlier fixes' aproach -- e.g. initializing to -1 only if the reads
failed -- would involve new nested conditionals. I find the new complexity
to outweigh the benefit of removing the dead store, so in this case I'm
casting the return value to `(void)` to tell Coverity to shush.

* Silence coverity CHECKED_RETURN on scrape

Check the return value of tr_variantGetInt() when showing
seeder and leecher counts in transmission-show.

* Silence CHECKED_RETURN on rpc recently-active

When building a list of removed torrent IDs from variants, confirm that
we can read the IDs from the variants before adding them to the list.
I don't _think_ this would have failed before, but Coverity's right that
it's reasonable to add a safeguard here.

* fix: better fix to serializing benc strings

The approach in 33e2ece7e5 was
a little problematic: GetString() shouldn't fail here; but if
it somehow did, we still want to encode a zero-length benc string here.

* chore: make uncrustify happy
2019-02-18 22:38:24 +00:00
qu1ck 7aa12a025d Add labels feature (#822)
* applied changes from https://github.com/Elbandi/transmission/tree/elbandi/labels to official transmission repo

* Fix compilation errors

* Address review comments

Changed `tr_ptrArray* labels` to `tr_ptrArray labels`;
Removed tr_ptrArrayNew() tr_ptrArrayDup() tr_ptrArrayFree()
Use tr_strsep() to split string by delimiters
Update transmission-remote.1
Update rpc-spec.txt

* Fix warning, address comments

* Rebase, fix formatting and address comments

Use uncrustify to format changed files
Fix "const <type>" -> "<type> const"
Fix small comments

* Lock torrent for setLabels, check for duplicates

* Check for empty labels in daemon

* Stop on first error
2019-02-17 04:33:57 -05:00
Charles Kerr 2013772aad
feat: make multiscrape limits adaptive (#837)
* feat: make multiscrape limits adaptive

Previously hardcoded by TR_MULTISCRAPE_MAX. This change makes
that the initial value, then incrementally lowers the value
when multiscrapes get "req too long" style errors.

* fix: don't log personal announce url

* chore: treat HTTP 400 as scrape-too-long

* chore: copyediting

* chore: copyediting

* move 'const' to the right of the type

* make conditional tests explicitly boolean

* make 'key' const

* don't lookup a value we already have

* make an array for known too-big scrape error messages

* improved multiscrape throttle logging

* fix: multiscraping of low numbers of torrents

Handle the case of getting a 'multiscrape too big' error message
back even if the user fewer than TR_MULTISCRAPE_MAX torrents.

* uncrustify

* fix oops

* refactor: remove TR_MULTISCRAPE_MIN

Is there any reason to have a minimum batch size?

* make test explicit boolean

Co-Authored-By: ckerr <ckerr@github.com>

* improve declaration of too_long_errors

Co-Authored-By: ckerr <ckerr@github.com>

* make test explicitly boolean

Co-Authored-By: ckerr <ckerr@github.com>

* make test explicitly boolean

Co-Authored-By: ckerr <ckerr@github.com>

* improve looping decl of too_long_errors
2019-02-16 15:19:38 -05:00
Mike Gelfand 1d6d946388 Fixup some formatting leftovers 2019-02-16 10:50:37 +03:00
Mike Gelfand 82df3a87f4 Update to Uncrustify 0.68.1
Tweak a few rules in the process. Now all code in cli, daemon, gtk,
libtransmission, qt, and utils is properly formatted with no manual
intervention.
2019-02-15 09:21:48 +03:00
Charles Kerr 39d1a54fbd
Merge branch 'master' into update-resume-file-before-invoking-torrent-scripts 2019-02-06 02:00:47 -05:00
Charles Kerr 5082393d92 address dirty/save sequencing issue in prev commit 2019-02-02 14:49:53 -06:00
Charles Kerr b04f2df299
Merge pull request #741 from Artoria2e5/parseline-cidr
Support CIDR-notated blocklists
2019-02-01 23:38:48 -06:00
Charles Kerr 08f5a0fdaa fix: update the resume file before running scripts
This is useful if the client script is going to access
the .resume file. Ensuring an up-to-date .resume file
means that user scripts will be able to access it.
2019-02-01 21:59:17 -06:00
Peter Dave Hello 7a0d2e63c7 Refactor shell scripts with syntax and styling fixes 2019-01-16 03:22:29 +08:00
Mingye Wang 847b43ffd3 (squash later) test rule count 2018-10-17 10:26:05 -04:00
Mingye Wang 94ee776113 (squash later) blocklist cidr endianness 2018-10-17 09:41:19 -04:00
Mingye Wang f61306f65f (squash later) fix pflen handling in cidr 2018-10-14 12:44:01 -04:00
Mingye Wang b3129591db Support CIDR-notated blocklists
This commit adds a new blocklist line format, namely individual IPv4
CIDR ranges separated by newlines. Text put after each entry is ignored
by sscanf, so feel free to put any kind of comments there.

Fix #230.
2018-10-13 17:23:45 -04:00
Mike Gelfand a53bae2849 Fix file-test on Win32 due to file/dir symlinks difference 2018-09-04 01:06:21 +03:00