karnel-termux 4.9.4 → 4.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -150,7 +150,11 @@ _brain_pick_file() {
150
150
  _brain_editor() {
151
151
  local title="$1"
152
152
 
153
- if ! command -v ${EDITOR:-nano} &>/dev/null; then
153
+ local editor_bin
154
+ editor_bin="${EDITOR:-nano}"
155
+ editor_bin="${editor_bin%% *}"
156
+
157
+ if ! command -v "$editor_bin" &>/dev/null; then
154
158
  log_error "${EDITOR:-nano} not found"
155
159
  list_item "Install it: ${D_CYAN}karnel install editor${D_NC}"
156
160
  return 1
@@ -1082,7 +1086,10 @@ brain_edit() {
1082
1086
  fi
1083
1087
 
1084
1088
  local editor="${EDITOR:-}"
1085
- if command -v ${EDITOR:-nano} &>/dev/null; then
1089
+ local editor_bin
1090
+ editor_bin="${EDITOR:-nano}"
1091
+ editor_bin="${editor_bin%% *}"
1092
+ if command -v "$editor_bin" &>/dev/null; then
1086
1093
  editor="${EDITOR:-nano}"
1087
1094
  elif [[ -z "$editor" ]] || ! command -v "$editor" &>/dev/null; then
1088
1095
  for e in vim nano vi; do
@@ -78,7 +78,13 @@ show_main() {
78
78
  return
79
79
  fi
80
80
 
81
- local readme_path="$KARNEL_PATH/tools/$module/$tool/README.md"
81
+ local readme_path
82
+ readme_path="$(realpath "$KARNEL_PATH/tools/$module/$tool/README.md" 2>/dev/null)"
83
+
84
+ if [[ -z "$readme_path" || "$readme_path" != "$KARNEL_PATH/tools/"* ]]; then
85
+ log_error "No documentation found for $module/$tool"
86
+ return 1
87
+ fi
82
88
 
83
89
  if [[ ! -f "$readme_path" ]]; then
84
90
  log_error "No documentation found for $module/$tool"
@@ -108,15 +108,19 @@ update_engram() {
108
108
  }
109
109
 
110
110
  _update_engram_impl() {
111
- export GOPATH="$HOME/.local/go"
112
- export GOCACHE="$HOME/.cache/go"
113
- export GOMODCACHE="$GOPATH/pkg/mod"
114
-
115
- if ! git -C "$KARNEL_DATA/engram" pull &>>"$LOG_FILE" && go build -C "$KARNEL_DATA/engram/cmd/engram" -o "$PREFIX/bin/engram" &>>"$LOG_FILE"; then
116
- log_error "Failed to update Engram"
117
- return 1
118
- fi
119
- return 0
111
+ export GOPATH="$HOME/.local/go"
112
+ export GOCACHE="$HOME/.cache/go"
113
+ export GOMODCACHE="$GOPATH/pkg/mod"
114
+
115
+ if ! git -C "$KARNEL_DATA/engram" pull &>>"$LOG_FILE"; then
116
+ log_error "Failed to pull engram repository"
117
+ return 1
118
+ fi
119
+ if ! go build -C "$KARNEL_DATA/engram/cmd/engram" -o "$PREFIX/bin/engram" &>>"$LOG_FILE"; then
120
+ log_error "Failed to build Engram"
121
+ return 1
122
+ fi
123
+ return 0
120
124
  }
121
125
 
122
126
  reinstall_engram() {
@@ -31,7 +31,10 @@ _install_hermes_agent_impl() {
31
31
  if [ -d "$HERMES_DIR/.git" ]; then
32
32
  cd "$HERMES_DIR" && git pull
33
33
  else
34
- git clone https://github.com/NousResearch/hermes-agent.git "$HERMES_DIR"
34
+ git clone https://github.com/NousResearch/hermes-agent.git "$HERMES_DIR" || {
35
+ log_error "Failed to clone hermes-agent repository"
36
+ return 1
37
+ }
35
38
  fi
36
39
 
37
40
  cd "$HERMES_DIR"
@@ -24,10 +24,15 @@ install_kiro() {
24
24
 
25
25
  # Try the official installer first
26
26
  log_info "Running official Kiro installer..."
27
- if echo "y" | curl -fsSL https://cli.kiro.dev/install 2>/dev/null | bash 2>>"$LOG_FILE"; then
28
- if command -v kiro &>/dev/null || command -v kiro-cli &>/dev/null; then
29
- log_success "Kiro installed successfully"
30
- return 0
27
+ local install_script
28
+ install_script=$(curl -fsSL https://cli.kiro.dev/install 2>/dev/null)
29
+ if [[ -n "$install_script" ]]; then
30
+ if echo "y" | bash -s -- <<<"$install_script" 2>>"$LOG_FILE"; then
31
+ hash -r
32
+ if command -v kiro &>/dev/null || command -v kiro-cli &>/dev/null; then
33
+ log_success "Kiro installed successfully"
34
+ return 0
35
+ fi
31
36
  fi
32
37
  fi
33
38
 
@@ -93,6 +98,7 @@ for p in d['packages']:
93
98
  # Create symlink for convenience
94
99
  ln -sf "$PREFIX/bin/kiro-cli" "$PREFIX/bin/kiro"
95
100
  rm -rf "$tmpdir"
101
+ hash -r
96
102
  if command -v kiro-cli &>/dev/null || command -v kiro &>/dev/null; then
97
103
  log_success "Kiro installed from direct download"
98
104
  return 0
@@ -240,14 +240,15 @@ int access(const char *p, int mode) {
240
240
  ssize_t readlinkat(int dirfd, const char *path, char *buf, size_t bufsiz) {
241
241
  if (path && streq(path, "/proc/self/exe")) {
242
242
  int len = slen(wrapper_path);
243
- if (len < (int)bufsiz) {
243
+ int to_copy = len < (int)bufsiz ? len : (int)bufsiz - 1;
244
+ if (to_copy > 0) {
244
245
  char *d = buf;
245
246
  const char *s = wrapper_path;
246
- while (*s)
247
+ for (int i = 0; i < to_copy; i++)
247
248
  *d++ = *s++;
248
249
  *d = '\0';
249
250
  }
250
- return len;
251
+ return to_copy > 0 ? to_copy : 0;
251
252
  }
252
253
  return (ssize_t)SREADLINKAT(dirfd, path, buf, bufsiz);
253
254
  }
@@ -270,9 +271,14 @@ ssize_t readlinkat(int dirfd, const char *path, char *buf, size_t bufsiz) {
270
271
  * bionic binaries. We use --library-path/--preload for glibc binaries instead.
271
272
  * Returns pointer to static buffer. */
272
273
  static char **strip_glibc_env(char *const envp[]) {
273
- static char *clean[256];
274
+ int count = 0;
275
+ while (envp[count])
276
+ count++;
277
+ static char *clean[4096];
278
+ if (count > 4095)
279
+ count = 4095;
274
280
  int j = 0;
275
- for (int i = 0; envp[i] && j < 255; i++) {
281
+ for (int i = 0; envp[i] && j < count; i++) {
276
282
  const char *e = envp[i];
277
283
  /* Skip LD_LIBRARY_PATH=* */
278
284
  if (e[0] == 'L' && e[1] == 'D' && e[2] == '_' && e[3] == 'L' &&
@@ -301,7 +307,9 @@ int execve(const char *pathname, char *const argv[], char *const envp[]) {
301
307
  while (argv[argc])
302
308
  argc++;
303
309
 
304
- char *new_argv[64];
310
+ if (argc + 7 > 1024)
311
+ goto fallback;
312
+ char *new_argv[1024];
305
313
  int i = 0;
306
314
  new_argv[i++] = (char *)pathname;
307
315
  new_argv[i++] = "--library-path";
@@ -331,7 +339,9 @@ int execve(const char *pathname, char *const argv[], char *const envp[]) {
331
339
  while (argv[argc])
332
340
  argc++;
333
341
 
334
- char *new_argv[64];
342
+ if (argc + 8 > 1024)
343
+ goto fallback;
344
+ char *new_argv[1024];
335
345
  int i = 0;
336
346
  new_argv[i++] = (char *)ld_path;
337
347
  new_argv[i++] = "--library-path";
@@ -349,4 +359,15 @@ int execve(const char *pathname, char *const argv[], char *const envp[]) {
349
359
 
350
360
  errno = err;
351
361
  return -1;
362
+
363
+ fallback:
364
+ /* If argv was too large for our static buffer, try the original execve */
365
+ r = SEXECVE(pathname, argv, clean_env);
366
+ if (r >= 0)
367
+ return (int)r;
368
+ r = SEXECVE(pathname, argv, envp);
369
+ if (r >= 0)
370
+ return (int)r;
371
+ errno = (int)(-r);
372
+ return -1;
352
373
  }
@@ -9,17 +9,24 @@ declare -A __KARNEL_IMPORTED
9
9
 
10
10
  import() {
11
11
  local base="${KARNEL_PATH}"
12
- local path="${1//@/$base}.sh"
12
+ local resolved="${1//@/$base}.sh"
13
+ local canonical
14
+ canonical="$(realpath "$resolved" 2>/dev/null || echo "$resolved")"
13
15
 
14
- if [[ -n "${__KARNEL_IMPORTED[$path]}" ]]; then
16
+ if [[ "$canonical" != "$base"/* ]]; then
17
+ echo "karnel: import error: path traversal denied: $1" >&2
18
+ return 1
19
+ fi
20
+
21
+ if [[ -n "${__KARNEL_IMPORTED[$canonical]}" ]]; then
15
22
  return
16
23
  fi
17
24
 
18
- if [[ ! -f "$path" ]]; then
19
- echo "karnel: import error: $path not found" >&2
25
+ if [[ ! -f "$canonical" ]]; then
26
+ echo "karnel: import error: $canonical not found" >&2
20
27
  return 1
21
28
  fi
22
29
 
23
- __KARNEL_IMPORTED[$path]=1
24
- source "$path"
30
+ __KARNEL_IMPORTED[$canonical]=1
31
+ source "$canonical"
25
32
  }
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
- KARNEL_VERSION="4.9.4"
3
+ KARNEL_VERSION="4.9.5"
4
4
 
5
5
  # -------------------------
6
6
  # Directorios del usuario
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "karnel-termux",
3
- "version": "4.9.4",
3
+ "version": "4.9.5",
4
4
  "description": "Modular Dev Environment for Termux — install languages, databases, AI agents, editors, and more with one command",
5
5
  "bin": {
6
6
  "karnel": "karnel/bin/karnel"