diff options
author | Andrew Bartlett <abartlet@samba.org> | 2004-07-06 01:28:12 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:56:52 -0500 |
commit | b359f5d89301882bbec657084b99c8d3e93dc3f2 (patch) | |
tree | 2a4e2edd394fe2462e682bc6a86348924528bc30 /source4/libcli/util | |
parent | 3b7872f69ffa0b1cde8d14ab9122a91ee8aab7a6 (diff) | |
download | samba-b359f5d89301882bbec657084b99c8d3e93dc3f2.tar.gz samba-b359f5d89301882bbec657084b99c8d3e93dc3f2.tar.bz2 samba-b359f5d89301882bbec657084b99c8d3e93dc3f2.zip |
r1352: Add a 'peek' function to our ASN1 code, so we can safely perform the
various switches without looking one byte past te end of the buffer.
(This used to be commit 5bce188d429b4166f3d0314922ae40204de182a7)
Diffstat (limited to 'source4/libcli/util')
-rw-r--r-- | source4/libcli/util/asn1.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/source4/libcli/util/asn1.c b/source4/libcli/util/asn1.c index 943ce4d1c1..da51340774 100644 --- a/source4/libcli/util/asn1.c +++ b/source4/libcli/util/asn1.c @@ -239,6 +239,28 @@ BOOL asn1_read_uint8(ASN1_DATA *data, uint8_t *v) return asn1_read(data, v, 1); } +/* read from a ASN1 buffer, advancing the buffer pointer */ +BOOL asn1_peek(ASN1_DATA *data, void *p, int len) +{ + if (len < 0 || data->ofs + len < data->ofs || data->ofs + len < len) { + data->has_error = True; + return False; + } + + if (data->ofs + len > data->length) { + data->has_error = True; + return False; + } + memcpy(p, data->data + data->ofs, len); + return True; +} + +/* read a uint8_t from a ASN1 buffer */ +BOOL asn1_peek_uint8(ASN1_DATA *data, uint8_t *v) +{ + return asn1_peek(data, v, 1); +} + /* start reading a nested asn1 structure */ BOOL asn1_start_tag(ASN1_DATA *data, uint8_t tag) { |