mirror of
https://github.com/tezc/sc.git
synced 2025-01-14 06:43:04 +08:00
Merge pull request #68 from tezc/str-fix
bounds check in sc_str to prevent misuse
This commit is contained in:
commit
ac312c7192
@ -18,6 +18,12 @@ void test1()
|
||||
assert(sc_buf_valid(&buf) == false);
|
||||
sc_buf_term(&buf);
|
||||
|
||||
sc_buf_init(&buf, 100);
|
||||
sc_buf_put_32(&buf, 1000);
|
||||
assert(sc_buf_get_str(&buf) == NULL);
|
||||
assert(sc_buf_valid(&buf) == false);
|
||||
sc_buf_term(&buf);
|
||||
|
||||
sc_buf_init(&buf, 100);
|
||||
sc_buf_init(&buf2, 100);
|
||||
sc_buf_put_str(&buf, "s");
|
||||
|
@ -565,6 +565,11 @@ const char *sc_buf_get_str(struct sc_buf *b)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (b->rpos + len > b->wpos) {
|
||||
b->err |= SC_BUF_CORRUPT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
str = (char *) b->mem + b->rpos;
|
||||
b->rpos += len + 1;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user