diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-06-18 22:13:36 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-06-18 22:13:36 -0700 |
commit | 895a74b4352d4fdb0b01e296df90e61255d9c3d9 (patch) | |
tree | b8bf2610f98c185ca095c620efa06a7f858b39d2 | |
parent | 70890e6941a4bdbfd0067b60260b7307a874d38b (diff) | |
download | txr-895a74b4352d4fdb0b01e296df90e61255d9c3d9.tar.gz txr-895a74b4352d4fdb0b01e296df90e61255d9c3d9.tar.bz2 txr-895a74b4352d4fdb0b01e296df90e61255d9c3d9.zip |
* lib.c (cat_str): Detect overflow in the total length
calculation.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib.c | 25 |
2 files changed, 26 insertions, 4 deletions
@@ -1,5 +1,10 @@ 2015-06-18 Kaz Kylheku <kaz@kylheku.com> + * lib.c (cat_str): Detect overflow in the total length + calculation. + +2015-06-18 Kaz Kylheku <kaz@kylheku.com> + Improvements in equal hashing function. * hash.c (equal_hash): For conses and vectors, ensure that @@ -2792,15 +2792,29 @@ val cat_str(val list, val sep) if (!item) continue; if (stringp(item)) { - total += c_num(length_str(item)); + cnum ntotal = total + c_num(length_str(item)); + if (len_sep && cdr(iter)) - total += len_sep; + ntotal += len_sep; + + if (ntotal < total) + goto oflow; + + total = ntotal; + continue; } if (chrp(item)) { - total += 1; + cnum ntotal = total + 1; + if (len_sep && cdr(iter)) - total += len_sep; + ntotal += len_sep; + + if (ntotal < total) + goto oflow; + + total = ntotal; + continue; } uw_throwf(error_s, lit("cat-str: ~s is not a character or string"), @@ -2830,6 +2844,9 @@ val cat_str(val list, val sep) *ptr = 0; return string_own(str); + +oflow: + uw_throwf(error_s, lit("cat-str: string length overflow"), nao); } val split_str(val str, val sep) |