Skip to content

Commit

Permalink
Fix: Multiplication result converted to larger type
Browse files Browse the repository at this point in the history
This rule finds code that converts the result of an integer multiplication to a larger type. Since the conversion applies after the multiplication, arithmetic overflow may still occur.

Fixes by cast before operation.
  • Loading branch information
Kraemii committed May 22, 2023
1 parent 13ae510 commit 2fdf66a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions samba/librpc/ndr/ndr_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ _PUBLIC_ NTSTATUS ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, const cha
ret = convert_string_talloc(ndr->current_mem_ctx,
chset, CH_UNIX,
ndr->data+ndr->offset,
(len2 + c_len_term)*byte_mul,
(size_t) (len2 + c_len_term)*byte_mul,
(void **)&as);
if (ret == -1) {
return ndr_pull_error(ndr, NDR_ERR_CHARCNV,
Expand Down Expand Up @@ -122,7 +122,7 @@ _PUBLIC_ NTSTATUS ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, const cha
ret = convert_string_talloc(ndr->current_mem_ctx,
chset, CH_UNIX,
ndr->data+ndr->offset,
(len1 + c_len_term)*byte_mul,
(size_t) (len1 + c_len_term)*byte_mul,
(void **)&as);
if (ret == -1) {
return ndr_pull_error(ndr, NDR_ERR_CHARCNV,
Expand Down Expand Up @@ -160,7 +160,7 @@ _PUBLIC_ NTSTATUS ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, const cha
ret = convert_string_talloc(ndr->current_mem_ctx,
chset, CH_UNIX,
ndr->data+ndr->offset,
(len1 + c_len_term)*byte_mul,
(size_t) (len1 + c_len_term)*byte_mul,
(void **)&as);
if (ret == -1) {
return ndr_pull_error(ndr, NDR_ERR_CHARCNV,
Expand Down

0 comments on commit 2fdf66a

Please sign in to comment.