Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dummy smart_amp: copy input_pins and output_pin separately #7588

Merged
merged 1 commit into from
May 16, 2023

Conversation

andrula-song
Copy link
Contributor

@andrula-song andrula-song commented May 11, 2023

The original code confuses static code analyzers since it was
relying on the fact that we have the 2x input and 1x output pin
config in adjacent position in smart_amp_data struct similarly
to the extended module configuration.

While it works, it is not a good practice.

Split the copy of input and output pin formats to make the code
obvious and less error prone.

Fixes: andrula-song@bcc1407 ("smart_amp_test: Split the module config and blob receiving for IPC4")

Signed-off-by: Andrula Song andrula.song@intel.com

@andrula-song andrula-song changed the title Dummy smart_amp: Fix the buffer overflow issue reported by klocwork Dummy smart_amp: copy input_pins and output_pin separately May 11, 2023
@marc-hb marc-hb requested review from lyakh and ujfalusi May 11, 2023 06:41
src/samples/audio/smart_amp_test_ipc4.c Outdated Show resolved Hide resolved
memcpy_s(sad->ipc4_cfg.input_pins, in_size,
base_cfg->base_cfg_ext.pin_formats, in_size);
memcpy_s(&sad->ipc4_cfg.output_pin, out_size,
base_cfg->base_cfg_ext.pin_formats + in_size, out_size);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pointer arithmetic on a flexible array member, wow! I wonder what that means. It looks suspicious... maybe this instead?

Suggested change
base_cfg->base_cfg_ext.pin_formats + in_size, out_size);
&base_cfg->base_cfg_ext.pin_formats[0] + in_size, out_size);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pointer arithmetic on a flexible array member, wow! I wonder what that means.

Most likely the same thing as a regular array, sorry the noise. In that case:

Suggested change
base_cfg->base_cfg_ext.pin_formats + in_size, out_size);
&base_cfg->base_cfg_ext.pin_formats[in_size], out_size);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may cause memory leak, it may add pointer based on pin_format size instead of byte, better continue add (char *) at beginning in case xtensa compiler is not so strong.
(char *)&base_cfg->base_cfg_ext.pin_formats[0] + in_size

or
(char *)&base_cfg->base_cfg_ext.pin_formats[1] ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case xtensa compiler is not so strong.

The xtensa compiler is based on either GCC or Clang so there's no standard compliance concern.

Copy link
Collaborator

@marc-hb marc-hb May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may cause memory leak,

I think you mean buffer overflow. Memory leak is something entirely different.

add (char *) at beginning

Yes the code assumes that sizeof(pin_formats[0]) is 1 and that's not very obvious. Especially not considering input_pins and output_pin are totally different.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, should be buffer overflow.

Copy link
Collaborator

@paulstelian97 paulstelian97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code change is good, commit message does have a tiny issue...

This change makes the code less error prone, not more.

@andrula-song
Copy link
Contributor Author

Code change is good, commit message does have a tiny issue...

This change makes the code less error prone, not more.

Thanks.

The original code confuses static code analyzers since it was
relying on the fact that we have the 2x input and 1x output pin
config in adjacent position in smart_amp_data struct similarly
to the extended module configuration.

While it works, it is not a good practice.

Split the copy of input and output pin formats to make the code
obvious and less error prone.

Fixes: andrula-song@ bcc1407 ("smart_amp_test: Split the module
config and blob receiving for IPC4")

Signed-off-by: Andrula Song <andrula.song@intel.com>
@andrula-song andrula-song marked this pull request as ready for review May 12, 2023 04:24
@andrula-song
Copy link
Contributor Author

SPFCI TEST

@ranj063
Copy link
Collaborator

ranj063 commented May 16, 2023

SOFCI TEST

1 similar comment
@andrula-song
Copy link
Contributor Author

SOFCI TEST

@kv2019i
Copy link
Collaborator

kv2019i commented May 16, 2023

One fail hit in https://sof-ci.01.org/sofpr/PR7588/build7818/devicetest/index.html -- a known bug.

@kv2019i kv2019i merged commit 3955017 into thesofproject:main May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants