diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2024-08-26 12:05:01 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-08-27 11:32:08 -0300 |
| commit | bdb7345a28f9b8d3edba46ac0dc5cfbd57cb92e8 (patch) | |
| tree | c7e7cd9b5480fb412c18cd000ec266d368ae2d63 | |
| parent | d300c11c6acba4390fdde9030a45b0a31e7501d1 (diff) | |
| download | luarocks-bdb7345a28f9b8d3edba46ac0dc5cfbd57cb92e8.tar.gz luarocks-bdb7345a28f9b8d3edba46ac0dc5cfbd57cb92e8.tar.bz2 luarocks-bdb7345a28f9b8d3edba46ac0dc5cfbd57cb92e8.zip | |
fix: patch: check array indices correctly
| -rw-r--r-- | spec/unit/tools_spec.lua | 5 | ||||
| -rw-r--r-- | src/luarocks/tools/patch.lua | 9 |
2 files changed, 6 insertions, 8 deletions
diff --git a/spec/unit/tools_spec.lua b/spec/unit/tools_spec.lua index 5b85c86a..65d8b73d 100644 --- a/spec/unit/tools_spec.lua +++ b/spec/unit/tools_spec.lua | |||
| @@ -223,9 +223,8 @@ describe("Luarocks patch test #unit", function() | |||
| 223 | 223 | ||
| 224 | it("fails if the patch file is invalid", function() | 224 | it("fails if the patch file is invalid", function() |
| 225 | write_file("test.patch", invalid_patch1, finally) | 225 | write_file("test.patch", invalid_patch1, finally) |
| 226 | local p = patch.read_patch("test.patch") | 226 | local p, all_ok = patch.read_patch("test.patch") |
| 227 | local result = pcall(patch.apply_patch, p) | 227 | assert.falsy(all_ok) |
| 228 | assert.falsy(result) | ||
| 229 | end) | 228 | end) |
| 230 | 229 | ||
| 231 | it("returns false if the files from the patch doesn't exist", function() | 230 | it("returns false if the files from the patch doesn't exist", function() |
diff --git a/src/luarocks/tools/patch.lua b/src/luarocks/tools/patch.lua index 6f36d713..10654e06 100644 --- a/src/luarocks/tools/patch.lua +++ b/src/luarocks/tools/patch.lua | |||
| @@ -11,7 +11,6 @@ | |||
| 11 | local patch = {} | 11 | local patch = {} |
| 12 | 12 | ||
| 13 | local fs = require("luarocks.fs") | 13 | local fs = require("luarocks.fs") |
| 14 | local fun = require("luarocks.fun") | ||
| 15 | 14 | ||
| 16 | local io = io | 15 | local io = io |
| 17 | local os = os | 16 | local os = os |
| @@ -255,7 +254,7 @@ function patch.read_patch(filename, data) | |||
| 255 | local advance | 254 | local advance |
| 256 | if state == 'filenames' then | 255 | if state == 'filenames' then |
| 257 | if startswith(line, "--- ") then | 256 | if startswith(line, "--- ") then |
| 258 | if fun.contains(files.source, nextfileno) then | 257 | if files.source[nextfileno] then |
| 259 | all_ok = false | 258 | all_ok = false |
| 260 | warning(format("skipping invalid patch for %s", | 259 | warning(format("skipping invalid patch for %s", |
| 261 | files.source[nextfileno+1])) | 260 | files.source[nextfileno+1])) |
| @@ -278,7 +277,7 @@ function patch.read_patch(filename, data) | |||
| 278 | table.insert(files.source, match) | 277 | table.insert(files.source, match) |
| 279 | end | 278 | end |
| 280 | elseif not startswith(line, "+++ ") then | 279 | elseif not startswith(line, "+++ ") then |
| 281 | if fun.contains(files.source, nextfileno) then | 280 | if files.source[nextfileno] then |
| 282 | all_ok = false | 281 | all_ok = false |
| 283 | warning(format("skipping invalid patch with no target for %s", | 282 | warning(format("skipping invalid patch with no target for %s", |
| 284 | files.source[nextfileno+1])) | 283 | files.source[nextfileno+1])) |
| @@ -289,7 +288,7 @@ function patch.read_patch(filename, data) | |||
| 289 | end | 288 | end |
| 290 | state = 'header' | 289 | state = 'header' |
| 291 | else | 290 | else |
| 292 | if fun.contains(files.target, nextfileno) then | 291 | if files.target[nextfileno] then |
| 293 | all_ok = false | 292 | all_ok = false |
| 294 | warning(format("skipping invalid patch - double target at line %d", | 293 | warning(format("skipping invalid patch - double target at line %d", |
| 295 | lineno+1)) | 294 | lineno+1)) |
| @@ -331,7 +330,7 @@ function patch.read_patch(filename, data) | |||
| 331 | if not advance and state == 'hunkhead' then | 330 | if not advance and state == 'hunkhead' then |
| 332 | local m1, m2, m3, m4 = match_linerange(line) | 331 | local m1, m2, m3, m4 = match_linerange(line) |
| 333 | if not m1 then | 332 | if not m1 then |
| 334 | if not fun.contains(files.hunks, nextfileno-1) then | 333 | if not files.hunks[nextfileno-1] then |
| 335 | all_ok = false | 334 | all_ok = false |
| 336 | warning(format("skipping invalid patch with no hunks for file %s", | 335 | warning(format("skipping invalid patch with no hunks for file %s", |
| 337 | files.target[nextfileno])) | 336 | files.target[nextfileno])) |
