X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=strbuf.c;h=07e8883ceb297bdde79f06ffa2d0519581ee60b9;hb=bcf3d1fd9ccc04350d793c077d3c112fb26f43f0;hp=9b3c4457f229041784edfa65218aa09de7a5eff8;hpb=7eaf4af426ee29812d49cfa5328e2af8b3f8af95;p=thirdparty%2Fgit.git diff --git a/strbuf.c b/strbuf.c index 9b3c4457f2..07e8883ceb 100644 --- a/strbuf.c +++ b/strbuf.c @@ -63,7 +63,8 @@ void strbuf_attach(struct strbuf *sb, void *buf, size_t len, size_t alloc) void strbuf_grow(struct strbuf *sb, size_t extra) { - if (sb->len + extra + 1 <= sb->len) + if (unsigned_add_overflows(extra, 1) || + unsigned_add_overflows(sb->len, extra + 1)) die("you want to use way too much memory"); if (!sb->alloc) sb->buf = NULL; @@ -152,7 +153,7 @@ int strbuf_cmp(const struct strbuf *a, const struct strbuf *b) void strbuf_splice(struct strbuf *sb, size_t pos, size_t len, const void *data, size_t dlen) { - if (pos + len < pos) + if (unsigned_add_overflows(pos, len)) die("you want to use way too much memory"); if (pos > sb->len) die("`pos' is too far after the end of the buffer");