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

lib/vfscore: Fix warnings in automount.c #1398

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from

Conversation

keenox
Copy link

@keenox keenox commented Apr 28, 2024

Prerequisite checklist

  • Read the contribution guidelines regarding submitting new changes to the project;
  • Tested your changes against relevant architectures and platforms;
  • Ran the checkpatch.uk on your commit series before opening this PR;
  • Updated relevant documentation.

Base target

  • Application(s): nginx 1.25

Additional configuration

Description of changes

  • remove const from path in vfscore_mount_volume
  • use the device name for the message in uk_list_for_each_entry_reverse

- remove const from path in vfscore_mount_volume
- use the device name for the message in uk_list_for_each_entry_reverse

Signed-off-by: Radu Coriu <radu.gabrielc@gmail.com>
@keenox keenox requested a review from a team as a code owner April 28, 2024 11:16
@github-actions github-actions bot added area/lib Internal Unikraft Microlibrary lang/c Issues or PRs to do with C/C++ lib/vfscore VFS Core Interface labels Apr 28, 2024
@StefanJum StefanJum requested review from StefanJum and removed request for a team April 28, 2024 11:18
@StefanJum StefanJum added this to the v0.17.0 (Calypso) milestone Apr 28, 2024
@@ -625,7 +628,7 @@ static int vfscore_ukopt_mkmp(char *path)
*/
static inline int vfscore_mount_volume(const struct vfscore_volume *vv)
{
const char *path;
char *path;
Copy link
Member

@skuenzer skuenzer Apr 29, 2024

Choose a reason for hiding this comment

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

What is the issue with const here? The path was treated as const on purpose because struct vfscore_volume is handed over as const as well so that we can support a const compiled-in filesystem table.

Copy link
Author

Choose a reason for hiding this comment

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

The path string is actually modified in vfscore_ukopt_mkmp at line 686. I initially wanted to strdup vv->path because of that constness promise in the input param, but after talking to @StefanJum we decided to only remove const.
Now I see that vv->path is also used at line 693 in vfscore_extract_volume, so don't know if a strdup would actually be ok and how the LIBVFSCORE_UKOPT_MKMP flag should interact with CONFIG_LIBUKCPIO

Copy link
Member

@skuenzer skuenzer May 25, 2024

Choose a reason for hiding this comment

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

Hum..., right. The proper patch should do strdup and free within vfscore_ukopt_mkmp() and path should be handed over as const. Because we also compile in paths, these are on purpose on read-only memory, any modification would lead to a crash (that's why also the const) at the same time, exporting handling of a dupped string allocation is typically making interfaces more complicated to use correctly.

Copy link
Author

Choose a reason for hiding this comment

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

@skuenzer I don't really understand why you're saying that we shoud do strdup and free within vfscore_ukopt_mkmp(). For vfscore_ukopt_mkmp it is an in/out parameter (as it's uses further down inside mount at line 695/698)
so we should do:
` if (vv->ukopts & LIBVFSCORE_UKOPT_MKMP) {
char *tmpPath = strdup(path);
rc = vfscore_ukopt_mkmp(tmpPath);
if (unlikely(rc < 0))
{
free(tmpPath);
return rc;
}
path = tmpPath;
}

// plus some extra code to properly free before the last return in case path was strduped
Another option would be to make the existing parameterconstand add an out parameter for thevfscore_ukopt_mkmp`, but that wouldn't make things any nicer IMHO.
Let me know if I'm missing something.

Copy link
Author

Choose a reason for hiding this comment

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

Nevermind, I noticed just now that the function actually restores the replaced slashes. I will do as you suggested and also make the param const.

@razvand
Copy link
Contributor

razvand commented May 29, 2024

@keenox , could you please see @skuenzer 's comments?

- make path const again in vfscore_mount_volume
- make path param const in vfscore_ukopt_mkmp and use strdup/free to avoid writing to readonly input string

Signed-off-by: Radu Coriu <radu.gabrielc@gmail.com>
Signed-off-by: Radu Coriu <radu.gabrielc@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/lib Internal Unikraft Microlibrary lang/c Issues or PRs to do with C/C++ lib/vfscore VFS Core Interface
Projects
Status: 🏗 In Progress
Development

Successfully merging this pull request may close these issues.

None yet

4 participants