Commit Graph

15811 Commits

Author SHA1 Message Date
Andrew Borodin
9a964edea9 (edit_print_string): refactor loop.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andrew Borodin
293fdafaa7 (str_8bit_casecmp, str_8bit_ncasecmp): refactor loops.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andrew Borodin
771f6911a0 (str_8bit_casecmp, str_8bit_ncasecmp): reduce variable scope.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andreas Mohr
43a398d76f (do_background): fix leak of file descriptors.
background.c: In function 'do_background':
background.c:587:1: error: leak of file descriptor 'comm[0]' []8;;https://cwe.mitre.org/data/definitions/775.htmlCWE-775]8;;] []8;;https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html#index-Wanalyzer-fd-leak-Werror=analyzer-fd-leak]8;;]
  587 | }
      | ^
  'do_background': events 1-12
    |
    |  527 |     if (pipe (comm) == -1)
    |      |        ~^~~~~~~~~~~
    |      |        ||
    |      |        |(1) opened here as read-write
    |      |        |(2) when 'pipe' succeeds
    |      |        (3) following 'false' branch...
    |......
    |  530 |     if (pipe (back_comm) == -1)
    |      |     ~~ ~~~~~~~~~~~~~~~~~
    |      |     |  ||
    |      |     |  |(5) when 'pipe' succeeds
    |      |     |  (6) following 'false' branch...
    |      |     (4) ...to here
    |......
    |  538 |     pid = fork ();
    |      |     ~~~
    |      |     |
    |      |     (7) ...to here
    |  539 |     if (pid == -1)
    |      |        ~
    |      |        |
    |      |        (8) following 'false' branch (when 'pid != -1')...
    |......
    |  552 |     if (pid == 0)
    |      |     ~~ ~
    |      |     |  |
    |      |     |  (10) following 'true' branch (when 'pid == 0')...
    |      |     (9) ...to here
    |  553 |     {
    |  554 |         int nullfd;
    |      |         ~~~
    |      |         |
    |      |         (11) ...to here
    |......
    |  587 | }
    |      | ~
    |      | |
    |      | (12) 'comm[0]' leaks here
    |
background.c:587:1: error: leak of file descriptor 'back_comm[1]' []8;;https://cwe.mitre.org/data/definitions/775.htmlCWE-775]8;;] []8;;https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html#index-Wanalyzer-fd-leak-Werror=analyzer-fd-leak]8;;]
  587 | }
      | ^
  'do_background': events 1-12
    |
    |  527 |     if (pipe (comm) == -1)
    |      |        ~^~~~~~~~~~~
    |      |        ||
    |      |        |(1) when 'pipe' succeeds
    |      |        (2) following 'false' branch...
    |......
    |  530 |     if (pipe (back_comm) == -1)
    |      |     ~~ ~~~~~~~~~~~~~~~~~
    |      |     |  ||
    |      |     |  |(4) opened here as read-write
    |      |     |  |(5) when 'pipe' succeeds
    |      |     |  (6) following 'false' branch...
    |      |     (3) ...to here
    |......
    |  538 |     pid = fork ();
    |      |     ~~~
    |      |     |
    |      |     (7) ...to here
    |  539 |     if (pid == -1)
    |      |        ~
    |      |        |
    |      |        (8) following 'false' branch (when 'pid != -1')...
    |......
    |  552 |     if (pid == 0)
    |      |     ~~ ~
    |      |     |  |
    |      |     |  (10) following 'true' branch (when 'pid == 0')...
    |      |     (9) ...to here
    |  553 |     {
    |  554 |         int nullfd;
    |      |         ~~~
    |      |         |
    |      |         (11) ...to here
    |......
    |  587 | }
    |      | ~
    |      | |
    |      | (12) 'back_comm[1]' leaks here
    |
background.c:587:1: error: leak of file descriptor 'comm[1]' []8;;https://cwe.mitre.org/data/definitions/775.htmlCWE-775]8;;] []8;;https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html#index-Wanalyzer-fd-leak-Werror=analyzer-fd-leak]8;;]
  587 | }
      | ^
  'do_background': events 1-12
    |
    |  527 |     if (pipe (comm) == -1)
    |      |        ~^~~~~~~~~~~
    |      |        ||
    |      |        |(1) opened here as read-write
    |      |        |(2) when 'pipe' succeeds
    |      |        (3) following 'false' branch...
    |......
    |  530 |     if (pipe (back_comm) == -1)
    |      |     ~~ ~~~~~~~~~~~~~~~~~
    |      |     |  ||
    |      |     |  |(5) when 'pipe' succeeds
    |      |     |  (6) following 'false' branch...
    |      |     (4) ...to here
    |......
    |  538 |     pid = fork ();
    |      |     ~~~
    |      |     |
    |      |     (7) ...to here
    |  539 |     if (pid == -1)
    |      |        ~
    |      |        |
    |      |        (8) following 'false' branch (when 'pid != -1')...
    |......
    |  552 |     if (pid == 0)
    |      |     ~~ ~
    |      |     |  |
    |      |     |  (10) following 'false' branch (when 'pid != 0')...
    |      |     (9) ...to here
    |......
    |  583 |         ctx->pid = pid;
    |      |         ~~~
    |      |         |
    |      |         (11) ...to here
    |......
    |  587 | }
    |      | ~
    |      | |
    |      | (12) 'comm[1]' leaks here
    |
background.c:587:1: error: leak of file descriptor 'back_comm[0]' []8;;https://cwe.mitre.org/data/definitions/775.htmlCWE-775]8;;] []8;;https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html#index-Wanalyzer-fd-leak-Werror=analyzer-fd-leak]8;;]
  587 | }
      | ^
  'do_background': events 1-12
    |
    |  527 |     if (pipe (comm) == -1)
    |      |        ~^~~~~~~~~~~
    |      |        ||
    |      |        |(1) when 'pipe' succeeds
    |      |        (2) following 'false' branch...
    |......
    |  530 |     if (pipe (back_comm) == -1)
    |      |     ~~ ~~~~~~~~~~~~~~~~~
    |      |     |  ||
    |      |     |  |(4) opened here as read-write
    |      |     |  |(5) when 'pipe' succeeds
    |      |     |  (6) following 'false' branch...
    |      |     (3) ...to here
    |......
    |  538 |     pid = fork ();
    |      |     ~~~
    |      |     |
    |      |     (7) ...to here
    |  539 |     if (pid == -1)
    |      |        ~
    |      |        |
    |      |        (8) following 'false' branch (when 'pid != -1')...
    |......
    |  552 |     if (pid == 0)
    |      |     ~~ ~
    |      |     |  |
    |      |     |  (10) following 'false' branch (when 'pid != 0')...
    |      |     (9) ...to here
    |......
    |  583 |         ctx->pid = pid;
    |      |         ~~~
    |      |         |
    |      |         (11) ...to here
    |......
    |  587 | }
    |      | ~
    |      | |
    |      | (12) 'back_comm[0]' leaks here
    |

Found by gcc-13 (-fanalyzer-fd-leak).

Signed-off-by: Andreas Mohr <and@gmx.li>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andrew Borodin
2edbf44dc0 (tty_color_get_name_by_index): fix format overflow.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andreas Mohr
2c49acf868 tar (uintmax_from_header): remove unused function and macro.
Found by clang-16.

Signed-off-by: Andreas Mohr <and@gmx.li>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andrew Borodin
1cada10e14 tar: parse in a more locale-independent way.
Use g_ascii_isspace() rather than isspace().

Sync with GNU tar 01f986b921d988ae51de6c937cc374b50a8b23b0.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andrew Borodin
16d9f23161 tar: use single is_octal_digit function.
Sync with GNU tar 05fcfaafb648cb7e9bd01004593ce016b8fb1f32.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andrew Borodin
1c81987cf6 (load_codepages_list_from_file): fix memory leak in free_codepages_list().
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andrew Borodin
4077522b2b (dff_reparse): get rif of code duplication.
Move diff displaying to separate function.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andrew Borodin
e1ee8a4da2 ydiff.c: refactror loops: replace 'while' with 'for' where reasonably.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andrew Borodin
6a10d8e932 (scan_diff): eliminate 'continue', use 'else' instead. 2023-11-06 21:06:14 +03:00
Andrew Borodin
c2e7bb9336 ydiff.c (fill_by_space): new helper function.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andrew Borodin
b05c1731fc ydiff.c: rename functions.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andrew Borodin
bee7d2aa39 ydiff.c: use g_array_set_clear_func().
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andrew Borodin
56f31e03ff Bump minimum GLib requirenment to 2.32.0.
This is required for g_array_set_clear_func().

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andrew Borodin
f373af88b7 (hdiff_multi): g_array_new() doesn't return NULL.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andrew Borodin
c3bc39814e (redo_diff): g_array_new() doesn't return NULL.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andrew Borodin
5cb55be2a3 (redo_diff): g_ptr_array_new() doesn't return NULL.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andrew Borodin
92cc9b053d WDiff::display_symbols: change type from int to gboolean. Related changes.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:14 +03:00
Andrew Borodin
313b06034e ydiff.c: fix coding style.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:13 +03:00
Andrew Borodin
1821e0e2f8 (vfs_path_build_url_params_str): return NULL instead of an empty string.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:13 +03:00
Andrew Borodin
5d8399befb tty: refactoring of color pairs deallocation.
* (tty_color_free_all_tmp): rename to tty_color_free_temp and call
    g_hash_table_foreach_remove().
  * (tty_color_free_all_non_tmp): rename to tty_color_free_all and call
    g_hash_table_remove_all().
  * (tty_color_free_all): remove.
  * (tty_color_free_condition_cb): rename to tty_color_free_temp_cb and
    simplify.
  * (mc_skin_deinit): use changed API.
  * (edit_free_syntax_rules): likewise.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:13 +03:00
Andrew Borodin
2d6d8a477e tty: color-related API changes
* (tty_try_alloc_color_pair): remove.
  * (tty_try_alloc_color_pair2): rename to tty_try_alloc_color_pair,
  change arguments.
  * (tty_color_set_defaults): changes arguments.
  * (this_try_alloc_color_pair): likewise.
  * lib/skin/color.c: related changes.
  * src/editor/syntax.c: likewise.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:13 +03:00
Andrew Borodin
c76c6820e6 lib/tty/color.c: use variable of tty_color_pair_t type for default color pair.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:13 +03:00
Andrew Borodin
4a116608d4 tty: refactoring of color pairs definition.
Rename structure mc_skin_color_t -> tty_color_pair_t and move to lib/tty/color.h.
Rename members.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:13 +03:00
Andrew Borodin
2c01bd53cb Ticket #4490: code cleanup before 4.8.31 release.
tty: refactoring of color pairs definition.

Rename structure tty_color_pair_t -> tty_color_lib_pair_t. Rename members.
Rename tty_color_try_alloc_pair_lib() -> tty_color_try_alloc_lib_pair().

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-11-06 21:06:13 +03:00
Andrew Borodin
cf7846cd62 Merge branch '4506_sftpfs_hashed_hostname'
* 4506_sftpfs_hashed_hostname:
  sftpfs: don't set preferred hostkey methods too restrictively.
2023-10-22 18:06:01 +03:00
Michal Sojka
8303ccaec3 sftpfs: don't set preferred hostkey methods too restrictively.
This fixes "sftp: failure establishing SSH session (-5)" error that
may appear on some systems when using SFTP link feature. The error
appears even when connecting to the same host via the "ssh" command
works. Whether the error appears or not depends on the content of
~/.ssh/known_hosts file.

Problem description:

Midnight Commander uses ~/.ssh/known_hosts for two reasons. Obviously,
one reason is checking for hostkey match after the SSH handshake. The
second reason is to set preferences which host key the remote side
should send us during the SSH handshake. And this is the problematic
place.

Entries in ~/.ssh/known_hosts store host names either in plain text or
in a hashed form. libssh2 does not export host name hashes, only plain
text host names. When mc tries to find a matching entry to set hostkey
preferences, it cannot cannot reliably match the hashed host names.
Before this change, mc assumed that any entry with hashed host name
matches the connecting host and set hostkey preference to the type of
that key. In many cases, this was incorrect. For example, when the
first hashed entry in ~/.ssh/known_hosts appeared before the matching
non-hashed one, and its key type was ssh-rsa, which is disabled by
default since OpenSSH 8.8 (released 2021-09-26), then mc requested
only the ssh-rsa host key from the remote host. Since this host key is
likely disabled these days, no key was sent by the remote host and mc
reported error -5 (LIBSSH2_ERROR_KEX_FAILURE).

Solution:

In this commit, we fix the problem as follows:

1. When finding a matching known_hosts entry in order to set the
   preferred hostkey method, we ignore the entries with hashed host
   names. If we find no matching entry with the plain text host name,
   no preference is set, resulting in the server sending us whatever
   key it wants and our libssh2 supports it. Likely, that key will
   match an entry with hashed host name later during the host key
   check.

2. If, on the other hand, a matching plain text entry is found, we use
   its type as a preference, but newly, we add other methods as a
   fallback. If the matched entry has a server-supported key type, it
   will be used. If it is not supported by the server (e.g. the old
   ssh-rsa type), the added fallback ensures that the server sends us
   some host key, which will likely match an entry with hashed host
   name later during the host key check.

This solution is not ideal, but I think it's good enough. For example,
the following situation is not solved ideally (I think): The
known_hosts file contains a single entry for some server. It has a
hashed host name and key of type B. Since we ignore hashed entries,
the server can send its host key as type A, which is higher on the
preference list. To the user, it will appear as that she has never
connected to that server before. After accepting the new key, it will
be added to known_hosts and the problem disappears.

Ideal solution would IMHO be to create libssh2_knownhost_find()
function in libssh2. It would allow finding all matching entries (even
with hashed host names) in known_hosts. Midnight commander would then
use all key types of found entries as its preference.

Note: Since the code modified by this commit was inspired by code from
curl, curl has the same problem. See
https://github.com/libssh2/libssh2/issues/676#issuecomment-1741877207.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-10-22 18:03:44 +03:00
Andrew Borodin
789f951c3f Merge branch '4507_shell_vfs_cyrillic'
* 4507_shell_vfs_cyrillic:
  Ticket #4507: shell VFS: incorrect file names with cyrillic or diacritic symbols.
2023-10-22 18:00:11 +03:00
lnx
3c4941867a Ticket #4507: shell VFS: incorrect file names with cyrillic or diacritic symbols.
When using "Shell link", filenames with cyrillic or diacritic symbols
are displayed as chains of numbers.

The problem is due to Perl version. With Perl v5.36.0, there is no
S_ISLNK in POSIX.pm. With Perl v5.38.0, there is S_ISLNK in POSIX.pm,
so S_IMODE and S_IFMT are not imported from Fcntl due to condition
unless defined &S_ISLNK.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-10-15 16:21:31 +03:00
Andrew Borodin
74d9f24858 Merge branch '4232_drop_fish_protocol'
* 4232_drop_fish_protocol:
  Rename FISH VFS to SHELL one.
  Ticket #4232: drop comatibility with native FISH protocol and FISH server.
2023-10-15 16:06:41 +03:00
Andrew Borodin
6ca4ab4b4e Rename FISH VFS to SHELL one. 2023-10-15 16:04:39 +03:00
Andrew Borodin
3f42309a5d Ticket #4232: drop comatibility with native FISH protocol and FISH server.
Does anybody know any implementation of FISH server?

Should we keep the compatibility with unimplemented server?

Let's forget about the compatibility with FISH command formats. Let's
just send shell scripts with arguments that are convenient for us to the
remote host and get results of script work. The part of FISH protocol
relative to remote host answers will be used as is.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-10-15 16:04:38 +03:00
Andrew Borodin
3e44333776 Merge branch '4419_mc.ext.ini_makefile'
* 4419_mc.ext.ini_makefile:
  Ticket #4419: mc.ext.ini: clarify regex for Makefile.
2023-10-08 18:54:30 +03:00
Andrew Borodin
372cb29d80 Ticket #4419: mc.ext.ini: clarify regex for Makefile.
Consider "Makefile" as whole word to avoid handling of
files named like "Makefile.zip" as makefiles.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-10-07 14:58:21 +03:00
Andrew Borodin
e8c4677b7e Merge branch '4502_mc.ext.ini'
* 4502_mc.ext.ini:
  Ticket #4502: mc.ext.ini: escape backslashes.
2023-09-16 20:03:56 +03:00
Andrew Borodin
18421b7e54 Ticket #4502: mc.ext.ini: escape backslashes.
An unescaped backslash \ is treated as invalid escape sequences in
glib-2.77.3 and glib-2.79:
https://gitlab.gnome.org/GNOME/glib/-/issues/3094)

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-09-16 20:03:18 +03:00
Andrew Borodin
892bee5bf7 Merge branch '4497_mc.ext.ini_sections'
* 4497_mc.ext.ini_sections:
  Ticket #4497: mc.ext.ini: fix comments.
2023-09-16 19:59:34 +03:00
Andrew Borodin
75577b66a7 Ticket #4497: mc.ext.ini: fix comments.
Clarify desctiption of how multiple sections and keys with same names
in this file are processed.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-09-16 19:58:37 +03:00
Andrew Borodin
c1263686a7 Merge branch '4499_reget_timestamp'
* 4499_reget_timestamp:
  Ticket #4499: reget: wrong timestamp when resuming copy operation.
2023-09-05 13:00:43 +03:00
Andrew Borodin
0ed72610f2 Ticket #4499: reget: wrong timestamp when resuming copy operation.
(copy_file_file): always set the destination file timestamps to the
source file ones at the end of copy operation regardless of destination
file is complete or not.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-09-05 12:59:44 +03:00
Andrew Borodin
2cff2cfcc5 Merge branch '4500_mcdiff_segfault'
* 4500_mcdiff_segfault:
  Ticket 4500: mcdiff: segfault when display of line numbers is enabled.
2023-09-05 12:55:12 +03:00
Andrew Borodin
dfe3279a36 Ticket 4500: mcdiff: segfault when display of line numbers is enabled.
The bug was introduced in 00f84fbf24.

  * (dview_load_options): avoid NULL dereference: don't caclulate the
    width of line numbers field here because dview->a isn't created yet.
  * (dview_update): caclulate the width of line numbers field using an
    actual length of diff lines array.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-09-05 12:52:03 +03:00
Andrew Borodin
2849d5080e Merge branch '4494_tar_hardlinks'
* 4494_tar_hardlinks:
  Ticket #4494: tar: fix handling of hard links.
2023-08-27 16:21:54 +03:00
Andrew Borodin
a4a5c97e1f Ticket #4494: tar: fix handling of hard links.
* tar.c: add typeflag values for regular file.
  * (tar_skip_member): set data offset here (and for regular file only)...
  * (tar_insert_entry): ...not here.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-27 16:21:19 +03:00
Andrew Borodin
bc88149218 Merge branch '4498_broken_stickchars'
* 4498_broken_stickchars:
  Ticket #4498: broken stickchars (-a ) mode.
2023-08-22 22:07:59 +03:00
Chris Severance
dba05b78ea Ticket #4498: broken stickchars (-a ) mode.
'mc -a' shows ^@ for most box drawing elements. Some drawing elements
only show as ^ as the @ is overwritten by other characters.

Revert "(mc_skin_lines_parse_ini_file): do not overwrite mc_tty_frm array in case of slow and ugly terminal."

This reverts commit 6d639ce942.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-22 22:03:49 +03:00
Andrew Borodin
c56c4f63cc Merge branch '4493_FTBFS_FreeBSD'
* 4493_FTBFS_FreeBSD:
  Ticket #4439: FTBFS on FreeBSD with ext2fs attribute support:
2023-08-19 20:56:07 +03:00
Andrew Borodin
9688e7d015 Ticket #4439: FTBFS on FreeBSD with ext2fs attribute support:
local.c:35:10: fatal error: 'e2p/e2p.h' file not found
         ^~~~~~~~~~~

  * m4.include/mc-ext2fs-attr.m4: add EXT2FS_CFLAGS E2P_CFLAGS to
    CPPFLAGS here...
  * src/filemanager/Makefile.am: ...not here.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-19 20:51:07 +03:00