Skip to content

Commit c3fd442

Browse files
committed
Merge branch '4717_open_syntax_file_segfault'
* 4717_open_syntax_file_segfault: (edit_load_syntax_file): create user syntax directory if it doesn't exist. Fix i18n of copy/move/delete progress window title. (check_file_access): return FALSE immediately in case of error message Ticket #4717: mcedit: fix segfault at open Syntax file.
2 parents 91b47d0 + 503c0af commit c3fd442

File tree

4 files changed

+64
-15
lines changed

4 files changed

+64
-15
lines changed

src/editor/edit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ check_file_access (WEdit *edit, const vfs_path_t *filename_vpath, struct stat *s
308308
if (file < 0)
309309
{
310310
file_error_message (_ ("Cannot open\n%s"), vfs_path_as_str (filename_vpath));
311-
goto cleanup;
311+
return FALSE;
312312
}
313313

314314
// New file, delete it if it's not modified or saved
@@ -319,7 +319,7 @@ check_file_access (WEdit *edit, const vfs_path_t *filename_vpath, struct stat *s
319319
if (mc_fstat (file, st) < 0)
320320
{
321321
file_error_message (_ ("Cannot stat\n%s"), vfs_path_as_str (filename_vpath));
322-
goto cleanup;
322+
return FALSE;
323323
}
324324

325325
// We want to open regular files only

src/editor/editcmd.c

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#include "lib/strutil.h" // utf string functions
5151
#include "lib/fileloc.h"
5252
#include "lib/lock.h"
53-
#include "lib/util.h" // tilde_expand()
53+
#include "lib/util.h" // tilde_expand(), x_basename()
5454
#include "lib/vfs/vfs.h"
5555
#include "lib/widget.h"
5656
#include "lib/event.h" // mc_event_raise()
@@ -763,6 +763,49 @@ editcmd_dialog_raw_key_query_cb (Widget *w, Widget *sender, widget_msg_t msg, in
763763
}
764764
}
765765

766+
/* --------------------------------------------------------------------------------------------- */
767+
768+
static gboolean
769+
editcmd_check_and_create_user_syntax_directory (const vfs_path_t *user_syntax_file_vpath)
770+
{
771+
gboolean ret;
772+
struct stat st;
773+
774+
ret = mc_stat (user_syntax_file_vpath, &st) == 0;
775+
if (!ret)
776+
{
777+
// file doesn't exist -- check why
778+
const char *user_syntax_file_path = vfs_path_as_str (user_syntax_file_vpath);
779+
780+
// check directory
781+
const char *user_syntax_file_basename = x_basename (user_syntax_file_path);
782+
char *user_syntax_dir;
783+
vfs_path_t *user_syntax_vpath;
784+
785+
user_syntax_dir =
786+
g_strndup (user_syntax_file_path, user_syntax_file_basename - user_syntax_file_path);
787+
user_syntax_vpath = vfs_path_from_str (user_syntax_dir);
788+
789+
ret = mc_stat (user_syntax_vpath, &st) == 0;
790+
if (!ret)
791+
ret = mc_mkdir (user_syntax_vpath, 0700) == 0;
792+
else if (!S_ISDIR (st.st_mode))
793+
{
794+
ret = FALSE;
795+
// set for file_error_message()
796+
errno = EEXIST;
797+
}
798+
799+
if (!ret)
800+
file_error_message (_ ("Cannot create directory\n%s"), user_syntax_dir);
801+
802+
vfs_path_free (user_syntax_vpath, TRUE);
803+
g_free (user_syntax_dir);
804+
}
805+
806+
return ret;
807+
}
808+
766809
/* --------------------------------------------------------------------------------------------- */
767810
/*** public functions ****************************************************************************/
768811
/* --------------------------------------------------------------------------------------------- */
@@ -1146,9 +1189,14 @@ edit_load_syntax_file (WDialog *h)
11461189
vfs_path_t *user_syntax_file_vpath;
11471190

11481191
user_syntax_file_vpath = mc_config_get_full_vpath (EDIT_SYNTAX_FILE);
1149-
check_for_default (extdir_vpath, user_syntax_file_vpath);
1150-
edit_arg_init (&arg, user_syntax_file_vpath, 0);
1151-
ret = edit_load_file_from_filename (h, &arg);
1192+
1193+
if (editcmd_check_and_create_user_syntax_directory (user_syntax_file_vpath))
1194+
{
1195+
check_for_default (extdir_vpath, user_syntax_file_vpath);
1196+
edit_arg_init (&arg, user_syntax_file_vpath, 0);
1197+
ret = edit_load_file_from_filename (h, &arg);
1198+
}
1199+
11521200
vfs_path_free (user_syntax_file_vpath, TRUE);
11531201
}
11541202
else if (dir == 1)

src/filemanager/file.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3506,14 +3506,6 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl
35063506

35073507
gboolean do_bg = FALSE; // do background operation?
35083508

3509-
static gboolean i18n_flag = FALSE;
3510-
if (!i18n_flag)
3511-
{
3512-
for (i = G_N_ELEMENTS (op_names); i-- != 0;)
3513-
op_names[i] = Q_ (op_names[i]);
3514-
i18n_flag = TRUE;
3515-
}
3516-
35173509
linklist = free_linklist (linklist);
35183510
dest_dirs = free_linklist (dest_dirs);
35193511

@@ -3731,7 +3723,7 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl
37313723
FileProgressStatus
37323724
file_error (file_op_context_t *ctx, gboolean allow_retry, const char *format, const char *file)
37333725
{
3734-
return files_error (ctx, allow_retry, format, file, NULL);
3726+
return files_error (ctx, allow_retry, format, file, "");
37353727
}
37363728

37373729
/* --------------------------------------------------------------------------------------------- */

src/filemanager/filegui.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,17 @@ progress_button_callback (MC_UNUSED WButton *button, MC_UNUSED int action)
770770
file_op_context_t *
771771
file_op_context_new (const FileOperation op)
772772
{
773+
static gboolean i18n_flag = FALSE;
774+
773775
file_op_context_t *ctx;
774776

777+
if (!i18n_flag)
778+
{
779+
for (int i = G_N_ELEMENTS (op_names); i-- != 0;)
780+
op_names[i] = Q_ (op_names[i]);
781+
i18n_flag = TRUE;
782+
}
783+
775784
ctx = g_new0 (file_op_context_t, 1);
776785
ctx->operation = op;
777786
ctx->preserve = TRUE;

0 commit comments

Comments
 (0)