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

Missing nullptr check for API call in "net/phy.h" #84146

Open
8t-tni opened this issue Jan 17, 2025 · 2 comments
Open

Missing nullptr check for API call in "net/phy.h" #84146

8t-tni opened this issue Jan 17, 2025 · 2 comments
Labels
area: Ethernet bug The issue is a bug, or the PR is fixing a bug

Comments

@8t-tni
Copy link

8t-tni commented Jan 17, 2025

Describe the bug

The function static inline int phy_link_callback_set(const struct device *dev, phy_callback_t callback,void *user_data) claims to return the error code "-ENOTSUP" if the API call is not supported.

But the function misses a correspondung nullptr check.

Current implementation:

static inline int phy_link_callback_set(const struct device *dev, phy_callback_t callback,
					void *user_data)
{
	const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;

	return api->link_cb_set(dev, callback, user_data);
}

Posseblie fix:

static inline int phy_link_callback_set(const struct device *dev, phy_callback_t callback,
					void *user_data)
{
	const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
        if (api->link_cb_set != NULL)
	    return api->link_cb_set(dev, callback, user_data);
        else
            return -ENOTSUP;
}

To Reproduce
Steps to reproduce the behavior:

  1. Create a little sample application using a STM32 nucleo H7
  2. Try to set a callback using phy_link_callback_set
  3. Run your sample application

Expected behavior
The function returns -ENOTSUP indicating that the ehternet driver does not support that API call.

Impact
The sample application crashes with a memory/access violation.

Logs and console output

Environment (please complete the following information):

  • OS: Windows with VsCode and WSL/docker
  • Toolchain Zephyr SDK

Additional context

@8t-tni 8t-tni added the bug The issue is a bug, or the PR is fixing a bug label Jan 17, 2025
Copy link

Hi @8t-tni! We appreciate you submitting your first issue for our open-source project. 🌟

Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙

@kartben
Copy link
Collaborator

kartben commented Jan 20, 2025

@8t-tni thanks for the report! Would you be interested in submitting a pull request to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Ethernet bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

No branches or pull requests

3 participants