From 52aff731d74c2ea8785fb3b6840068202365c45e Mon Sep 17 00:00:00 2001
From: Andreas Mohr <and@gmx.li>
Date: Sat, 5 Mar 2016 12:13:06 +0000
Subject: [PATCH] External panelize: Fix absolute path result usage
Fix absolute paths result usage, before list[0] was checked but
it was always ".." from dir_list_init()
so never absolute path result was detected.
Bug #2942 reported by ackalker.
- sanity: access line[1] only if string is long enough
- tweak: use strlen() once only for speed-up
- cleanup: remove unneeded list->len check because list is always init
- cleanup: remove unchecked ret value from mc_chdir()
- cleanup: remove unused LABELS macro
- hint: add external panelize expected absolute _or_ relative results hint
Signed-off-by: Andreas Mohr <and@gmx.li>
---
src/filemanager/panelize.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/src/filemanager/panelize.c b/src/filemanager/panelize.c
index 8050244..42352cd 100644
a
|
b
|
|
63 | 63 | #define UX 3 |
64 | 64 | #define UY 2 |
65 | 65 | |
66 | | #define LABELS 3 |
67 | 66 | #define B_ADD B_USER |
68 | 67 | #define B_REMOVE (B_USER + 1) |
69 | 68 | |
… |
… |
do_external_panelize (char *command) |
333 | 332 | |
334 | 333 | while (TRUE) |
335 | 334 | { |
| 335 | size_t len; |
| 336 | |
336 | 337 | clearerr (external); |
337 | 338 | if (fgets (line, sizeof (line), external) == NULL) |
338 | 339 | { |
… |
… |
do_external_panelize (char *command) |
341 | 342 | else |
342 | 343 | break; |
343 | 344 | } |
344 | | if (line[strlen (line) - 1] == '\n') |
345 | | line[strlen (line) - 1] = 0; |
346 | | if (strlen (line) < 1) |
| 345 | |
| 346 | len = strlen (line); |
| 347 | |
| 348 | if (line[len - 1] == '\n') |
| 349 | line[len - 1] = 0; |
| 350 | if (len < 1) |
347 | 351 | continue; |
348 | | if (line[0] == '.' && IS_PATH_SEP (line[1])) |
| 352 | if (len > 1 && line[0] == '.' && IS_PATH_SEP (line[1])) |
349 | 353 | name = line + 2; |
350 | 354 | else |
351 | 355 | name = line; |
… |
… |
do_external_panelize (char *command) |
364 | 368 | |
365 | 369 | current_panel->is_panelized = TRUE; |
366 | 370 | |
367 | | if (list->len == 0) |
368 | | dir_list_init (list); |
369 | | else if (IS_PATH_SEP (list->list[0].fname[0])) |
| 371 | /* HINT: mixed absolute and relative paths result not supported */ |
| 372 | if (list->len > 1 && IS_PATH_SEP (list->list[1].fname[0])) |
370 | 373 | { |
371 | 374 | vfs_path_t *vpath_root; |
372 | | int ret; |
373 | 375 | |
374 | 376 | vpath_root = vfs_path_from_str (PATH_SEP_STR); |
375 | 377 | panel_set_cwd (current_panel, vpath_root); |
376 | | ret = mc_chdir (vpath_root); |
| 378 | (void) mc_chdir (vpath_root); |
377 | 379 | vfs_path_free (vpath_root); |
378 | | |
379 | | (void) ret; |
380 | 380 | } |
381 | 381 | |
382 | 382 | if (pclose (external) < 0) |