~tdaitx/whoopsie/security-fixes

« back to all changes in this revision

Viewing changes to lib/bson/encoding.c

  • Committer: Tiago Stürmer Daitx
  • Date: 2019-10-30 04:28:50 UTC
  • Revision ID: tiago.daitx@ubuntu.com-20191030042850-u1gymgv6u3gw59ll
SECURITY UPDATE: Integer overflow when handling large bson objects (LP: #1830865)

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
 * If presented with a length > 4, this returns 0.  The Unicode
68
68
 * definition of UTF-8 goes up to 4-byte sequences.
69
69
 */
70
 
static int isLegalUTF8( const unsigned char *source, int length ) {
 
70
static int isLegalUTF8( const unsigned char *source, size_t length ) {
71
71
    unsigned char a;
72
72
    const unsigned char *srcptr = source + length;
73
73
    switch ( length ) {
102
102
}
103
103
 
104
104
static int bson_validate_string( bson *b, const unsigned char *string,
105
 
                                 const int length, const char check_utf8, const char check_dot,
 
105
                                 const size_t length, const char check_utf8, const char check_dot,
106
106
                                 const char check_dollar ) {
107
107
 
108
 
    int position = 0;
109
 
    int sequence_length = 1;
 
108
    size_t position = 0;
 
109
    size_t sequence_length = 1;
110
110
 
111
111
    if( check_dollar && string[0] == '$' ) {
112
112
        b->err |= BSON_FIELD_INIT_DOLLAR;
136
136
 
137
137
 
138
138
int bson_check_string( bson *b, const char *string,
139
 
                       const int length ) {
 
139
                       const size_t length ) {
140
140
 
141
141
    return bson_validate_string( b, ( const unsigned char * )string, length, 1, 0, 0 );
142
142
}
143
143
 
144
144
int bson_check_field_name( bson *b, const char *string,
145
 
                           const int length ) {
 
145
                           const size_t length ) {
146
146
 
147
147
    return bson_validate_string( b, ( const unsigned char * )string, length, 1, 1, 1 );
148
148
}