Merge pull request #46 from javalsai/fix-45

fix #45
This commit is contained in:
javalsai 2025-07-01 01:53:22 +02:00 committed by GitHub
commit 3bfc2f52f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 81 additions and 12 deletions

3
debug/README.md Normal file
View File

@ -0,0 +1,3 @@
# Debug
This folder contains debug utils like gdb scripts. They are not guaranteed to work but can ease some tasks when debugging.

59
debug/debug.gdb Normal file
View File

@ -0,0 +1,59 @@
# this just meant to run in another term, is probably better to attach to another already running window
set inferior-tty /dev/pts/7
set pagination off
break *(read_press + 62)
define fake_read
set *((char*) $rsi) = $al
set $rax = 1
jump *(read_press + 67)
end
break *(read_press + 108)
define fake_magic_cont
set $eax = 1
jump *(read_press + 113)
end
define fake_magic_end
set $eax = 0
jump *(read_press + 113)
end
run
set $al = 0x1b
fake_read
fake_magic_cont
set $al = '['
fake_read
fake_magic_cont
set $al = 'D'
fake_read
fake_magic_end
set $al = 'p'
fake_read
fake_magic_end
set $al = 'a'
fake_read
fake_magic_end
set $al = 's'
fake_read
fake_magic_end
set $al = 's'
fake_read
fake_magic_end
set $al = 'w'
fake_read
fake_magic_end
set $al = 'd'
fake_read
fake_magic_end
set $al = '\n'
fake_read
fake_magic_end

View File

@ -121,19 +121,26 @@ void moarEnv(char* user, struct session session, struct passwd* pw,
sourceFileTry((char*)vec_get(&config->behavior.source, i));
}
/* printf("\n"); */
if (pw->pw_dir) {
uint home_len = strlen(pw->pw_dir);
for (size_t i = 0; i < config->behavior.user_source.length; i++) {
char* file2sourcepath = (char*)vec_get(&config->behavior.user_source, i);
size_t newbuf_len = home_len + strlen(file2sourcepath) + 2;
char* newbuf = malloc(newbuf_len); // nullbyte and slash
if (newbuf == NULL) continue; // can't bother
memcpy(newbuf, pw->pw_dir, newbuf_len);
newbuf[home_len] = '/'; // assume pw_dir doesn't start with '/' :P
memcpy(&newbuf[home_len + 1], file2sourcepath, newbuf_len - home_len);
sourceFileTry(newbuf);
free(newbuf);
if (pw->pw_dir) {
const char* home = pw->pw_dir;
size_t home_len = strlen(home);
for (size_t i = 0; i < config->behavior.user_source.length; i++) {
const char* filename = (char*)vec_get(&config->behavior.user_source, i);
size_t filename_len = strlen(filename);
size_t path_len = home_len + 1 + filename_len + 1; // nullbyte and slash
char* path = malloc(path_len);
if (!path) continue; // can't bother
memcpy(path, home, home_len);
path[home_len] = '/'; // assume pw_dir doesn't start with '/' :P
memcpy(&path[home_len + 1], filename, filename_len);
path[path_len - 1] = '\0';
sourceFileTry(path);
free(path);
}
}