Skip to content

look(1): Capsicumise - #1489

Closed
kfv wants to merge 1 commit into
freebsd:mainfrom
kfv:kfv/capsicum/look
Closed

look(1): Capsicumise#1489
kfv wants to merge 1 commit into
freebsd:mainfrom
kfv:kfv/capsicum/look

Conversation

@kfv

@kfv kfv commented Oct 24, 2024

Copy link
Copy Markdown
Member

No description provided.

@lwhsu

lwhsu commented Oct 25, 2024

Copy link
Copy Markdown
Member

@oshogbo can you review this?

Comment thread usr.bin/look/look.c Outdated
Comment thread usr.bin/look/look.c
Comment thread usr.bin/look/look.c Outdated
@oshogbo

oshogbo commented Oct 31, 2024

Copy link
Copy Markdown
Contributor

@kfv Can you also fix the style issues reported by GitHub Actions?

@kfv

kfv commented Nov 1, 2024

Copy link
Copy Markdown
Member Author

@oshogbo: The style checks are already passing, but I assume you're referring to the warnings for lines exceeding 80 characters. I’ll go ahead and address those as well, sure.

@kfv
kfv force-pushed the kfv/capsicum/look branch from 8201453 to cc71657 Compare November 1, 2024 10:13
@kfv

kfv commented Nov 1, 2024

Copy link
Copy Markdown
Member Author

@oshogbo: I applied soft wrapping but kept mmap() on line 162 unwrapped for clarity. I also removed WITHOUT_CAPSICUM by handling ENOSYS as suggested. I’ll just need to go over the code again to address the dynamic stack allocation we discussed.

@kfv
kfv force-pushed the kfv/capsicum/look branch from cc71657 to 3a79009 Compare November 1, 2024 11:05
@oshogbo

oshogbo commented Nov 27, 2024

Copy link
Copy Markdown
Contributor

Sorry, why haven't we used capsicum_helpers here?

@bsdimp

bsdimp commented Jun 12, 2025

Copy link
Copy Markdown
Member

@markjdb any final comments?

@markjdb

markjdb commented Jun 12, 2025

Copy link
Copy Markdown
Member

@markjdb any final comments?

@oshogbo 's comments still apply here: these should just use capsicum helpers (i.e., caph_* routines which handle ENOSYS), and the dynamically allocated stack array is kind of iffy and should be converted to an explicit allocation.

@bsdimp

bsdimp commented Aug 4, 2025

Copy link
Copy Markdown
Member

@kfv What are your plans here? This seems to be stuck waiting for addressing the helper feedback comments.

@kfv

kfv commented Aug 4, 2025

Copy link
Copy Markdown
Member Author

Hi, apologies for the extended delay in addressing the requested changes. The past year has been personally and geopolitically challenging, and I appreciate your patience. I make sure to go through all the pending requests within the coming week at most. Thank you again for your understanding.

@kfv
kfv force-pushed the kfv/capsicum/look branch from 3a79009 to bcbdb50 Compare August 6, 2025 12:05
@kfv
kfv requested a review from oshogbo August 6, 2025 12:05
@kfv

kfv commented Aug 6, 2025

Copy link
Copy Markdown
Member Author

I think this is ready for final review. Let me know if I’ve missed anything or if there’s anything else you'd like me to adjust.

Comment thread usr.bin/look/look.c Outdated
@oshogbo

oshogbo commented Aug 19, 2025

Copy link
Copy Markdown
Contributor

What do you think @markjdb and @bsdimp ?

@kfv
kfv force-pushed the kfv/capsicum/look branch from bcbdb50 to 122d423 Compare August 22, 2025 21:08
Comment thread usr.bin/look/look.c Outdated
err(EXIT_FAILURE, "failed to enter capability mode");

for (size_t idx = 0; idx < nfiles; file = argv[idx++]) {
if (fstat(fds[idx], &sb))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is still wrong. I have not run this code, so I might be wrong here.

The open(2) returns -1 for failed open. We ignore actual error codem which is in errno. Then we pass -1 to fstat(2). In result instead of meaningful error like "File doesn't exists", "No access" ect. we provide user with a same error "Invalid file descriptor" when the fstat(2) fails.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right, that was my mistake. It’s now fixed, with the details explained here: #1489 (comment)

Comment thread usr.bin/look/look.c Outdated
if (caph_enter() != 0)
err(EXIT_FAILURE, "failed to enter capability mode");

for (size_t idx = 0; idx < nfiles; file = argv[idx++]) {

@oshogbo oshogbo Aug 24, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually I just noticed that this magic is also wrong.
You forgot to reset file to argv[0]. So if I read this correctly your first file is actually the last from argv. Later it works.

This is why I actually don't like such magical initalization, I think such code like:

for (size_t idx = 0; idx < nfiles; idx++) { 
     file = argv[idx];

I haven't read into more details but it seems that we also move argv by one:

	if (argc >= 2)
		file = *argv++;

So I'm not sure if we can reuse it in the previous snipped. This all seems quite magical.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You are absolutely right, Mariusz — that was my oversight, and thank you for catching it. My intention was to preserve the style of this decades-old codebase, which is why I avoided introducing structural modifications, and in doing so, I miscalculated the handling of argv. My apologies.

I have just pushed a new commit that addresses this by removing the implicit argv++ side effect and introducing a more explicit indexed loop over the files. And to keep track of errno, I added a small structure with fd and err members. I considered adding a name member as well, in which case the iteration domain would shift entirely to that structure, eliminating the need for argv in the second loop. It could be refactored even further if we decide it’s worthwhile.

If the preference is for a more substantial redesign, I am more than happy to work on that as well. Otherwise, please let me know if there are any remaining gaps for our strict "capsicumisation" goal here, or other areas that still need fixing, and I’ll take care of them.

@kfv
kfv force-pushed the kfv/capsicum/look branch from 122d423 to 8a3d887 Compare September 3, 2025 18:00
@kfv
kfv requested a review from oshogbo October 4, 2025 09:39
Comment thread usr.bin/look/look.c
nfiles = argc > 1 ? argc - 1 : argc;
if ((files = malloc(nfiles * sizeof(struct files))) == NULL)
err(2, NULL);
for (size_t idx = 0; idx < nfiles; idx++) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The code (at least for me) seem a little bit puzzling.
First I don't like the play with file. Its seems a little bit hackish.
Maybe we can have something like:

static char *_path_words[] = { _PATH_WORDS };

...

file_list = _path_words;
nfiles = 1;
if (argc >= 2) {
    file_list = argv;
    nfiles = argc - 1;
}

Then using file_list to iterate you don't have to guess which list you are iterating.

To be honest I don't like the fact that argv/argc gets desynchronized.
So I would propose also this change:

key = prepkey(*argv++, termchar);
argc -= 1;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right. Can you take a look and see if the recent updates make it clean enough, or if you still think further improvements are needed? I've kept the ternaries as-is; I think with the rest of the modifications it should be clean enough, but I'm open to any ideas.

Comment thread usr.bin/look/look.c
Comment thread usr.bin/look/look.c Outdated
Comment thread usr.bin/look/look.c Outdated
@bsdimp

bsdimp commented Apr 15, 2026

Copy link
Copy Markdown
Member

Is there a new version of this that addresses the review feedback?

@bsdimp bsdimp added changes-required Cannot land as is, change requested of submitter and removed 15-candidate labels Apr 15, 2026
@kfv

kfv commented May 29, 2026

Copy link
Copy Markdown
Member Author

Don't know why I forgot this PR, thought it's landed. Working on it now.

@kfv
kfv force-pushed the kfv/capsicum/look branch from 8a3d887 to 64a2d4d Compare May 29, 2026 09:47
@kfv
kfv requested a review from oshogbo May 29, 2026 09:50
@kfv

kfv commented Jul 5, 2026

Copy link
Copy Markdown
Member Author

Cc: @oshogbo

@oshogbo

oshogbo commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

LGTM. I will build it and test.

@kfv

kfv commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

May I proceed with this patch?

Cc: @freebsdfrau, @clausecker

@oshogbo

oshogbo commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Yes, please go ahead.

@clausecker

Copy link
Copy Markdown
Contributor

Looking good here!
Approved for commit.

Comment thread usr.bin/look/look.c
Signed-off-by: Faraz Vahedi <kfv@kfv.io>
@kfv
kfv force-pushed the kfv/capsicum/look branch from 64a2d4d to 144f2ed Compare September 5, 2026 12:10
@kfv

kfv commented Sep 5, 2026

Copy link
Copy Markdown
Member Author

It's ready now. I'll land it shortly.

freebsd-git pushed a commit that referenced this pull request Sep 6, 2026
Reviewed by:	fuz, oshogbo
Approved by:	fuz (mentor)
Pull Request:	#1489
@kfv

kfv commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

Closed by commit f66c868

@kfv kfv closed this Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changes-required Cannot land as is, change requested of submitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants