Permalink
Browse files

Add tainting to U::Buffer#append

  • Loading branch information...
1 parent 53050ef commit f0c67c0409ee94e66b5e15d962e6f72d66141db7 Nikolai Weibull committed Apr 3, 2013
Showing with 25 additions and 7 deletions.
  1. +2 −0 ext/u/rb_u_buffer.c
  2. +23 −7 test/unit/u/buffer.rb
View
2 ext/u/rb_u_buffer.c
@@ -240,6 +240,7 @@ rb_u_buffer_append_m(int argc, VALUE *argv, VALUE self)
const struct rb_u_buffer *buffer = RVAL2RBUBUFFER(argv[i]);
rb_u_buffer_append(self, buffer->c, buffer->length);
+ OBJ_INFECT(self, argv[i]);
} else if (FIXNUM_P(argv[i]) || TYPE(argv[i]) == T_BIGNUM) {
uint32_t c = NUM2UINT(argv[i]);
@@ -269,6 +270,7 @@ rb_u_buffer_append_m(int argc, VALUE *argv, VALUE self)
rb_u_buffer_append(self,
USTRING_STR(string),
USTRING_LENGTH(string));
+ OBJ_INFECT(self, argv[i]);
}
return self;
View
30 test/unit/u/buffer.rb
@@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
Expectations do
- expect ArgumentError.new('wrong number of arguments (0 for at least 1)') do U::Buffer.new.append end
- expect 'abcde'.u do U::Buffer.new.append('abc', 'de').to_u end
- expect 'abcde'.u do (U::Buffer.new << 'abc' << 'de').to_u end
-
- expect 'äbc'.u do U::Buffer.new.append_format('%cbc'.u, 'ä').to_u end
+ expect U::Buffer do U::Buffer.new end
+ expect U::Buffer do U::Buffer.new(128) end
+ expect U::Buffer do U::Buffer.new(nil) end
+ expect TypeError do U::Buffer.new('abc') end
expect U::Buffer.new(5).append('abc') do |buffer| buffer.dup end
expect false do
@@ -14,10 +13,28 @@
end
expect false do
original = U::Buffer.new(5).append('abc')
- original.dup.append('de') == original.object_id
+ original.dup.append('de').object_id == original.object_id
end
+ expect ArgumentError.new('wrong number of arguments (0 for at least 1)') do U::Buffer.new.append end
+ expect 'abcde'.u do U::Buffer.new.append('abc', 'de').to_u end
+ expect 'abcde'.u do (U::Buffer.new << 'abc' << 'de').to_u end
expect "abc\0def".u do U::Buffer.new.append('abc', 0, 'def'.u).to_u end
+ expect result.tainted? do U::Buffer.new.taint.to_u end
+ expect result.tainted? do U::Buffer.new.append(U::Buffer.new.taint).to_u end
+ expect result.tainted? do U::Buffer.new.append(''.taint).to_u end
+ expect result.untrusted? do U::Buffer.new.untrust.to_u end
+ expect result.untrusted? do U::Buffer.new.append(U::Buffer.new.untrust).to_u end
+ expect result.untrusted? do U::Buffer.new.append(''.untrust).to_u end
+
+ expect 'äbc'.u do U::Buffer.new.append_format('%cbc'.u, 'ä').to_u end
+ expect result.tainted? do U::Buffer.new.append_format('abc'.taint).to_u end
+ expect result.tainted? do U::Buffer.new.append_format('%s', 'abc'.taint).to_u end
+ expect result.tainted? do U::Buffer.new.append_format('%p', 'abc'.taint).to_u end
+
+ expect ''.u do U::Buffer.new.to_u! end
+ expect 'äbc'.u do U::Buffer.new.append('äbc').to_u! end
+ expect ''.u do U::Buffer.new.append('äbc').tap(&:to_u!).to_u! end
expect '#<U::Buffer äbc>' do U::Buffer.new.append('äbc'.u).inspect end
expect '#<U::Buffer äbcdëwvxÿz>' do U::Buffer.new.append('äbcdëwvxÿz'.u).inspect end
@@ -30,5 +47,4 @@
expect 4 do U::Buffer.new.append('あbc'.u).width end
expect result.tainted? do U::Buffer.new.taint.to_s end
- expect result.tainted? do U::Buffer.new.taint.to_u end
end

0 comments on commit f0c67c0

Please sign in to comment.