← Commit list

08a5dab18

Denys Vlasenko
Denys Vlasenko
2014-11-17
SUCCESS Duration: 134s

Subject

ash: fix handling of negative start value in ${v:start:len}

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

shell/ash.c+9 -1
@@ -6411,7 +6411,15 @@ subevalvar(char *p, char *varname, int strloc, int subtype,
len = number(loc);
}
}
- if (pos >= orig_len) {
+ if (pos < 0) {
+ /* ${VAR:$((-n)):l} starts n chars from the end */
+ pos = orig_len + pos;
+ }
+ if ((unsigned)pos >= orig_len) {
+ /* apart from obvious ${VAR:999999:l},
+ * covers ${VAR:$((-9999999)):l} - result is ""
+ * (bash-compat)
+ */
pos = 0;
len = 0;
}