diff --git a/src/lib-sieve/plugins/imapflags/tst-hasflag.c b/src/lib-sieve/plugins/imapflags/tst-hasflag.c index bef34f518418fb6865d95070f4bb803823b2c4a5..53a370c193f97dcb34b2ea3959f5683d0e05f14d 100644 --- a/src/lib-sieve/plugins/imapflags/tst-hasflag.c +++ b/src/lib-sieve/plugins/imapflags/tst-hasflag.c @@ -165,14 +165,19 @@ static bool tst_hasflag_opcode_dump (const struct sieve_opcode *opcode ATTR_UNUSED, const struct sieve_runtime_env *renv, sieve_size_t *address) { - unsigned int opt_code; + int opt_code = 1; printf("HASFLAG\n"); /* Handle any optional arguments */ if ( sieve_operand_optional_present(renv->sbin, address) ) { - while ( (opt_code=sieve_operand_optional_read(renv->sbin, address)) ) { + while ( opt_code != 0 ) { + if ( !sieve_operand_optional_read(renv->sbin, address, &opt_code) ) + return FALSE; + switch ( opt_code ) { + case 0: + break; case OPT_COMPARATOR: sieve_opr_comparator_dump(renv->sbin, address); break; @@ -197,7 +202,7 @@ static bool tst_hasflag_opcode_execute (const struct sieve_opcode *opcode ATTR_UNUSED, const struct sieve_runtime_env *renv, sieve_size_t *address) { - unsigned int opt_code; + int opt_code = 1; const struct sieve_comparator *cmp = &i_ascii_casemap_comparator; const struct sieve_match_type *mtch = &is_match_type; struct sieve_match_context *mctx; @@ -210,8 +215,13 @@ static bool tst_hasflag_opcode_execute /* Handle any optional arguments */ if ( sieve_operand_optional_present(renv->sbin, address) ) { - while ( (opt_code=sieve_operand_optional_read(renv->sbin, address)) ) { + while ( opt_code != 0 ) { + if ( !sieve_operand_optional_read(renv->sbin, address, &opt_code) ) + return FALSE; + switch ( opt_code ) { + case 0: + break; case OPT_COMPARATOR: cmp = sieve_opr_comparator_read(renv->sbin, address); break; diff --git a/src/lib-sieve/plugins/vacation/ext-vacation.c b/src/lib-sieve/plugins/vacation/ext-vacation.c index 3cf0b47ac4e56fe2d5b6ce022601e3d92444d0ce..9d2cd138f60725413f3e76b2ad7c8dd892016759 100644 --- a/src/lib-sieve/plugins/vacation/ext-vacation.c +++ b/src/lib-sieve/plugins/vacation/ext-vacation.c @@ -292,13 +292,18 @@ static bool ext_vacation_opcode_dump (const struct sieve_opcode *opcode ATTR_UNUSED, const struct sieve_runtime_env *renv, sieve_size_t *address) { - unsigned int opt_code; + int opt_code = 1; printf("VACATION\n"); if ( sieve_operand_optional_present(renv->sbin, address) ) { - while ( (opt_code=sieve_operand_optional_read(renv->sbin, address)) ) { + while ( opt_code != 0 ) { + if ( !sieve_operand_optional_read(renv->sbin, address, &opt_code) ) + return FALSE; + switch ( opt_code ) { + case 0: + break; case OPT_DAYS: if ( !sieve_opr_number_dump(renv->sbin, address) ) return FALSE; @@ -333,13 +338,18 @@ static bool ext_vacation_opcode_execute (const struct sieve_opcode *opcode ATTR_UNUSED, const struct sieve_runtime_env *renv, sieve_size_t *address) { - unsigned int opt_code; + int opt_code = 1; sieve_size_t days = 0; string_t *reason, *subject, *from, *handle; if ( sieve_operand_optional_present(renv->sbin, address) ) { - while ( (opt_code=sieve_operand_optional_read(renv->sbin, address)) ) { + while ( opt_code != 0 ) { + if ( !sieve_operand_optional_read(renv->sbin, address, &opt_code) ) + return FALSE; + switch ( opt_code ) { + case 0: + break; case OPT_DAYS: if ( !sieve_opr_number_read(renv->sbin, address, &days) ) return FALSE; break; diff --git a/src/lib-sieve/sieve-address-parts.c b/src/lib-sieve/sieve-address-parts.c index 5e3479f324476075cf3cd8fcb55f9ef49434a1fc..4414a6521df402fb73c65e095fc07ca6dd6e17f0 100644 --- a/src/lib-sieve/sieve-address-parts.c +++ b/src/lib-sieve/sieve-address-parts.c @@ -377,11 +377,16 @@ bool sieve_address_match bool sieve_addrmatch_default_dump_optionals (struct sieve_binary *sbin, sieve_size_t *address) { - unsigned int opt_code; + int opt_code = 1; if ( sieve_operand_optional_present(sbin, address) ) { - while ( (opt_code=sieve_operand_optional_read(sbin, address)) ) { + while ( opt_code != 0 ) { + if ( !sieve_operand_optional_read(sbin, address, &opt_code) ) + return FALSE; + switch ( opt_code ) { + case 0: + break; case SIEVE_AM_OPT_COMPARATOR: if ( !sieve_opr_comparator_dump(sbin, address) ) return FALSE; @@ -408,11 +413,17 @@ bool sieve_addrmatch_default_get_optionals const struct sieve_address_part **addrp, const struct sieve_match_type **mtch, const struct sieve_comparator **cmp) { - unsigned int opt_code; + int opt_code = 1; + if ( sieve_operand_optional_present(sbin, address) ) { - while ( (opt_code=sieve_operand_optional_read(sbin, address)) ) { + while ( opt_code != 0 ) { + if ( !sieve_operand_optional_read(sbin, address, &opt_code) ) + return FALSE; + switch ( opt_code ) { + case 0: + break; case SIEVE_AM_OPT_COMPARATOR: if ( (*cmp = sieve_opr_comparator_read(sbin, address)) == NULL ) return FALSE; diff --git a/src/lib-sieve/sieve-code.c b/src/lib-sieve/sieve-code.c index 283e8ea6e6ea82f307d48a97a719bbc57b9fd63f..6f61f6a9ffed7283c6fdc7061b5d010c2c6b89ac 100644 --- a/src/lib-sieve/sieve-code.c +++ b/src/lib-sieve/sieve-code.c @@ -137,19 +137,18 @@ bool sieve_operand_optional_present(struct sieve_binary *sbin, sieve_size_t *add return FALSE; } -unsigned int sieve_operand_optional_read(struct sieve_binary *sbin, sieve_size_t *address) +bool sieve_operand_optional_read(struct sieve_binary *sbin, sieve_size_t *address, int *id_code) { - unsigned int id = -1; - + unsigned int id; + if ( sieve_binary_read_byte(sbin, address, &id) ) { - /* No more optionals */ - if ( id == 0 ) - return 0; - - return id; + *id_code = (int) id; + return TRUE; } - return -1; + *id_code = 0; + + return FALSE; } /* diff --git a/src/lib-sieve/sieve-code.h b/src/lib-sieve/sieve-code.h index dc18752f6b759560b7cda72c8de61bac9bac30c0..fd9f6e8035c99135f8c4a9e71298bebec4f75f0e 100644 --- a/src/lib-sieve/sieve-code.h +++ b/src/lib-sieve/sieve-code.h @@ -77,8 +77,8 @@ const struct sieve_operand *sieve_operand_read (struct sieve_binary *sbin, sieve_size_t *address); bool sieve_operand_optional_present(struct sieve_binary *sbin, sieve_size_t *address); -unsigned int sieve_operand_optional_read - (struct sieve_binary *sbin, sieve_size_t *address); +bool sieve_operand_optional_read + (struct sieve_binary *sbin, sieve_size_t *address, int *id_code); void sieve_opr_number_emit(struct sieve_binary *sbin, sieve_size_t number); bool sieve_opr_number_dump(struct sieve_binary *sbin, sieve_size_t *address); diff --git a/src/lib-sieve/sieve-generator.c b/src/lib-sieve/sieve-generator.c index a2230dcedbd3b39f5280fbd250a4fc5435f6c126..c889de01b29dd8b95ff44a26d396c1a697d0cf6d 100644 --- a/src/lib-sieve/sieve-generator.c +++ b/src/lib-sieve/sieve-generator.c @@ -119,7 +119,7 @@ bool sieve_generate_arguments(struct sieve_generator *generator, sieve_binary_emit_byte(generator->binary, SIEVE_OPERAND_OPTIONAL); /* Emit argument id for optional operand */ - sieve_binary_emit_byte(generator->binary, arg->arg_id_code); + sieve_binary_emit_byte(generator->binary, (unsigned char) arg->arg_id_code); state = ARG_OPTIONAL; } @@ -129,7 +129,7 @@ bool sieve_generate_arguments(struct sieve_generator *generator, state = ARG_POSITIONAL; /* Emit argument id for optional operand (0 marks the end of the optionals) */ - sieve_binary_emit_byte(generator->binary, arg->arg_id_code); + sieve_binary_emit_byte(generator->binary, (unsigned char) arg->arg_id_code); break; case ARG_POSITIONAL: diff --git a/src/lib-sieve/tst-header.c b/src/lib-sieve/tst-header.c index 02ade4a972c84cc725f2861f081359999454eaa1..48125b8abb18a8d65836675249e56462a5f54a37 100644 --- a/src/lib-sieve/tst-header.c +++ b/src/lib-sieve/tst-header.c @@ -117,14 +117,19 @@ static bool tst_header_opcode_dump (const struct sieve_opcode *opcode ATTR_UNUSED, const struct sieve_runtime_env *renv, sieve_size_t *address) { - unsigned int opt_code; + int opt_code = 1; printf("HEADER\n"); /* Handle any optional arguments */ if ( sieve_operand_optional_present(renv->sbin, address) ) { - while ( (opt_code=sieve_operand_optional_read(renv->sbin, address)) ) { + while ( opt_code != 0 ) { + if ( !sieve_operand_optional_read(renv->sbin, address, &opt_code) ) + return FALSE; + switch ( opt_code ) { + case 0: + break; case OPT_COMPARATOR: sieve_opr_comparator_dump(renv->sbin, address); break; @@ -148,7 +153,7 @@ static bool tst_header_opcode_execute (const struct sieve_opcode *opcode ATTR_UNUSED, const struct sieve_runtime_env *renv, sieve_size_t *address) { - unsigned int opt_code; + int opt_code = 1; const struct sieve_comparator *cmp = &i_octet_comparator; const struct sieve_match_type *mtch = &is_match_type; struct sieve_match_context *mctx; @@ -161,8 +166,13 @@ static bool tst_header_opcode_execute /* Handle any optional arguments */ if ( sieve_operand_optional_present(renv->sbin, address) ) { - while ( (opt_code=sieve_operand_optional_read(renv->sbin, address)) ) { + while ( opt_code != 0 ) { + if ( !sieve_operand_optional_read(renv->sbin, address, &opt_code) ) + return FALSE; + switch ( opt_code ) { + case 0: + break; case OPT_COMPARATOR: cmp = sieve_opr_comparator_read(renv->sbin, address); break;