Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
Fix potential segfault upon overflowing slice bounds.
Browse files Browse the repository at this point in the history
  • Loading branch information
alcinnz committed Feb 2, 2021
1 parent 3ef602f commit 87710c2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Services/Prosody/slice.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ public class Slice : Gee.Hashable<Slice>, Object {
public Slice.b(Bytes? b) {_ = b == null ? empty : b;}

public int length {get {return _.length;}}
public new uint8 get(int i) {return _[i < 0 ? length + i : i];}
public new uint8 get(int i) {
if (i > length) return 0;
return _[i < 0 ? length + i : i];
}
public Slice slice(int start_, int end_) {
// Add some Python-style convenience
var start = start_; if (start < 0) start += _.length;
var end = end_; if (end < 0) end += _.length;
if (end > _.length) end = _.length;
if (start >= end) return new Slice(); // Gracefully handle minor errors.

// NOTE: Using the slice method of Bytes (which is provided by the
Expand Down

0 comments on commit 87710c2

Please sign in to comment.