mirror of
				https://github.com/Zygo/bees.git
				synced 2025-11-04 04:00:36 +01:00 
			
		
		
		
	bytevector: validate length in get<T>()
Don't allow a pointer to T to be taken from a ByteVector that is not at least sizeof(T) bytes long. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
		@@ -1,6 +1,8 @@
 | 
				
			|||||||
#ifndef _CRUCIBLE_BYTEVECTOR_H_
 | 
					#ifndef _CRUCIBLE_BYTEVECTOR_H_
 | 
				
			||||||
#define _CRUCIBLE_BYTEVECTOR_H_
 | 
					#define _CRUCIBLE_BYTEVECTOR_H_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <crucible/error.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <memory>
 | 
					#include <memory>
 | 
				
			||||||
#include <mutex>
 | 
					#include <mutex>
 | 
				
			||||||
#include <ostream>
 | 
					#include <ostream>
 | 
				
			||||||
@@ -69,6 +71,7 @@ namespace crucible {
 | 
				
			|||||||
	T*
 | 
						T*
 | 
				
			||||||
	ByteVector::get() const
 | 
						ByteVector::get() const
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
							THROW_CHECK2(out_of_range, size(), sizeof(T), size() >= sizeof(T));
 | 
				
			||||||
		return reinterpret_cast<T*>(data());
 | 
							return reinterpret_cast<T*>(data());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user