Commit Graph

6403 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
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
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
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
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
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
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
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
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
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
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
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
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
Andrew Borodin
1f61ab0563 tar-sparse.c: turn -Werror=type-limits off here.
...to avoid following error:
comparison of unsigned expression < 0 is always false [-Werror=type-limits]

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-13 13:17:16 +03:00
Andrew Borodin
7e61d298b8 (pax_decode_header): fix the loop range.
The high boundary 'u' of loop was modified in the loop as a result of
decode_num().

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-12 20:48:15 +03:00
Andrew Borodin
02dea0d65d (pax_decode_header): fix comparison of integer expressions of different signedness.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-12 20:48:07 +03:00
Andrew Borodin
38f41e4c82 (tar_free_inode): mark unused parameter.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-12 20:47:47 +03:00
Andrew Borodin
f1cf92f435 Indentation.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-04 21:04:55 +03:00
Andrew Borodin
978ce6d0dd Use vfs_path_get_last_path_vfs() where it is resonable. 2023-08-04 21:04:55 +03:00
Andrew Borodin
e20d9acecb Use vfs_path_get_last_path_str() where it is resonable. 2023-08-04 21:04:55 +03:00
Andrew Borodin
b926c08ec9 sftpfs: refactoring: get rid of code duplication.
* (sftpfs_op_init): make public and use it...
  * (sftpfs_opendir): here,
  * (sftpfs_mkdir): here,
  * (sftpfs_rmdir): and here.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-04 21:04:55 +03:00
Andrew Borodin
ec98810986 (tree_move): get rid of gotos. 2023-08-04 21:04:55 +03:00
Andrew Borodin
e8e9d222a9 (tar_skip_member): fix NULL dereference.
Found by Coverity.
Coverity id #462418.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-04 21:04:55 +03:00
Andrew Borodin
37e7ee5a47 (edit_push_redo_action): reduce variable scope.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-04 21:04:55 +03:00
Andrew Borodin
a9f4626138 (edit_push_undo_action): reduce variable scope.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-04 21:04:55 +03:00
Andrew Borodin
8a0f00ae6f (edit_load_macro_cmd): reduce variable scope.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-04 21:04:54 +03:00
Andrew Borodin
e1c4e7f3cb (info_show_info): fix unused variable.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-04 21:04:54 +03:00
Andrew Borodin
482e183190 (spell_dialog_lang_list_show): ret rid of string duplication.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-04 21:04:54 +03:00
Andrew Borodin
2e78166c23 src/editor/spell.c: refactoring: use GPtrArray instead of GArray for string arrays.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-04 21:04:54 +03:00
Andrew Borodin
583adea34e (edit_suggest_current_word): minor refactoring.
Do not duplcate an empty string.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-04 21:04:54 +03:00
Andrew Borodin
0869946de5 (str_nconvert_to_input): return NULL if input is NULL.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-04 21:04:54 +03:00
Andrew Borodin
464a2eeefc (str_nconvert_to_display): return NULL if input is NULL.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-04 21:04:54 +03:00
Andrew Borodin
6fecb7a9e8 (mc_args__convert_help_to_syscharset): return GString.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-04 21:04:54 +03:00
Andrew Borodin
0a9ecdeb98 Remove #include <errno.h> from files where errno is unused. 2023-08-04 21:04:54 +03:00
Andrew Borodin
f4ac2bb01f (cd_error_msg): new function to show the change directory error message.
Use it where needed.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-04 21:04:54 +03:00
Andrew Borodin
8cc71a7f65 src/viewer/nroff.c: remove unneeded include.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-04 21:04:54 +03:00
Andrew Borodin
044c035900 Use bit-field members of file_entry_t as integers explicitly.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-08-04 21:04:54 +03:00