diff options
author | Simon Rettberg | 2017-04-21 16:31:06 +0200 |
---|---|---|
committer | Simon Rettberg | 2017-04-21 16:31:06 +0200 |
commit | b61176f17b59a94750dff1f959231dadc4e6078a (patch) | |
tree | 88ee419323ba332a1dd06c5aa801c87f59b36bb3 /scan_asn1rawint.c | |
parent | ldadp.h: Add missing SearchRequestReference opcode (diff) | |
download | ldadp-b61176f17b59a94750dff1f959231dadc4e6078a.tar.gz ldadp-b61176f17b59a94750dff1f959231dadc4e6078a.tar.xz ldadp-b61176f17b59a94750dff1f959231dadc4e6078a.zip |
Update ldap/asn1/... files with current tinyldap
Diffstat (limited to 'scan_asn1rawint.c')
-rw-r--r-- | scan_asn1rawint.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/scan_asn1rawint.c b/scan_asn1rawint.c index 6f6f676..375da1d 100644 --- a/scan_asn1rawint.c +++ b/scan_asn1rawint.c @@ -1,17 +1,21 @@ #include "asn1.h" size_t scan_asn1rawint(const char* src,const char* max,size_t len,long* l) { - size_t i,j; + size_t i; long m; - if (src>=max) return 0; - if (*src<0) m=-1; else m=0; - for (i=j=0; i<len; ++i,++j) { - if ((m==0 && *src==0) || (m==-1 && *src==-1)) --j; - m=(m<<8)|(unsigned char)*src; - ++src; - if (src>max) return 0; + if (src>=max) return 0; // 0 bytes input buffer + if (*src<0) m=-1; else m=0; // negative number? + if (len>1 && *src==m) { + // we want to catch things like 00 01 + // but a leading 0 byte is needed for 00 a0 because otherwise it would be -96 + if ((src[1]>>7)==m) return 0; // non-minimal encoding + if (len>sizeof(m)+1) return 0; // value too large, does not fit + } else + if (len>sizeof(m)) return 0; // value too large, does not fit + if (src+len>max) return 0; // input buffer not sufficient + for (i=0; i<len; ++i) { + m=(m<<8)|(unsigned char)src[i]; } - if (j>sizeof(long)) return 0; *l=m; return len; } |