Fix rare 1 byte buffer over-read
This commit is contained in:
parent
48964bc5cc
commit
af98b8ea0f
|
@ -144,28 +144,29 @@ private static Key? get_key(string sig, bool priv) throws GLib.Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string get_string_from_data(Data data) {
|
private static string get_string_from_data(Data data) {
|
||||||
|
const size_t BUF_SIZE = 256;
|
||||||
data.seek(0);
|
data.seek(0);
|
||||||
uint8[] buf = new uint8[256];
|
uint8[] buf = new uint8[BUF_SIZE + 1];
|
||||||
ssize_t? len = null;
|
ssize_t len = 0;
|
||||||
string res = "";
|
string res = "";
|
||||||
do {
|
do {
|
||||||
len = data.read(buf);
|
len = data.read(buf, BUF_SIZE);
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
string part = (string) buf;
|
buf[len] = 0;
|
||||||
part = part.substring(0, (long) len);
|
res += (string) buf;
|
||||||
res += part;
|
|
||||||
}
|
}
|
||||||
} while (len > 0);
|
} while (len > 0);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static uint8[] get_uint8_from_data(Data data) {
|
private static uint8[] get_uint8_from_data(Data data) {
|
||||||
|
const size_t BUF_SIZE = 256;
|
||||||
data.seek(0);
|
data.seek(0);
|
||||||
uint8[] buf = new uint8[256];
|
uint8[] buf = new uint8[BUF_SIZE + 1];
|
||||||
ssize_t? len = null;
|
ssize_t len = 0;
|
||||||
ByteArray res = new ByteArray();
|
ByteArray res = new ByteArray();
|
||||||
do {
|
do {
|
||||||
len = data.read(buf);
|
len = data.read(buf, BUF_SIZE);
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
res.append(buf[0:len]);
|
res.append(buf[0:len]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -474,7 +474,7 @@ namespace GPG {
|
||||||
[CCode (cname = "gpgme_data_release_and_get_mem")]
|
[CCode (cname = "gpgme_data_release_and_get_mem")]
|
||||||
public string release_and_get_mem(out size_t len);
|
public string release_and_get_mem(out size_t len);
|
||||||
|
|
||||||
public ssize_t read(uint8[] buf);
|
public ssize_t read([CCode (array_length = false)] uint8[] buf, size_t len);
|
||||||
|
|
||||||
public ssize_t write(uint8[] buf);
|
public ssize_t write(uint8[] buf);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue