Skip to content

Fixed: "cd on quit": cmd history not saved, 'cfgpath' corrupted; - #2180

Merged
jarun merged 1 commit into
jarun:masterfrom
ezequielv:dev_ezequielv-fix-history_pathname_corrupted_when_cdquit-v5_3-01_01
Oct 24, 2026
Merged

jarun merged 1 commit into
jarun:masterfrom
ezequielv:dev_ezequielv-fix-history_pathname_corrupted_when_cdquit-v5_3-01_01

Conversation

@ezequielv

Copy link
Copy Markdown
Contributor

When invoked with outfile == NULL, write_lastdir() overwrites the
global var cfgpath with the full pathname of the .lastd file for
the "cd on quit" functionality;

Unfortunately, that variable is used at a later point during the
program exit process, resulting in an incorrect pathname for the
.history file, causing the history file not to be written.

This commit:

  • Uses a buffer (g_buf) other than cfgpath to hold the constructed pathname for the .lastd file;

  • Simplifies the logic deciding which const char * value to pass to open();

  When invoked with 'outfile == NULL', write_lastdir() overwrites the
  global var 'cfgpath' with the full pathname of the '.lastd' file for
  the "cd on quit" functionality;

  Unfortunately, that variable is used at a later point during the
  program exit process, resulting in an incorrect pathname for the
  '.history' file, causing the history file not to be written.

  This commit:

    * Uses a buffer ('g_buf') other than 'cfgpath' to hold the
      constructed pathname for the '.lastd' file;

    * Simplifies the logic deciding which 'const char *' to pass to
      'open()';
Comment thread src/nnn.c
int fd = open(outfile
? (tilde ? g_buf : outfile)
: cfgpath, O_CREAT | O_WRONLY | O_TRUNC, S_IWUSR | S_IRUSR);
int fd = open(use_g_buf ? g_buf : outfile,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the failure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @jarun. Thank you for looking at this.

I've reviewed the tool's output and it looks to me as if these are all pre-existing issues, and none of the modifications I've done have (should have) made a difference with regards to accepting "user input" (environment variables in this case) and using that as input for file access functions. That's the whole point of having environment variables like NNN_TMPFILE, where the user is explicitly given the ability to control which file(s) are accessed by the program.

I'd be curious to see the same tool checks applied to the code before my suggested changes. I strongly suspect those "security vulnerabilities" are present upstream.

Would it be possible to run the checks against master just to see what the differences are? (to establish a baseline, as they say).

Thank you :-)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore these.

@jarun
jarun merged commit ea4493a into jarun:master Oct 24, 2026
7 of 8 checks passed
@jarun

jarun commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants