Skip to content

Col refactor #1115

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

Merged
merged 16 commits into from
Sep 29, 2020
Merged

Col refactor #1115

merged 16 commits into from
Sep 29, 2020

Conversation

kerolasa
Copy link
Member

@kerolasa kerolasa commented Aug 6, 2020

Welcome back from vacation @karelzak

While back when d8bfcb4 was in review phase I mentioned col(1) is in need for whole bunch of attention. This pull request contains the things that I thought make sense when bringing the command from past to present. The patches start with tests that work when they are added, and do not need changes at any step on the way. I hope that gives more confidence these changes are probably ok.

@evverx
Copy link
Member

evverx commented Aug 6, 2020

@kerolasa I wonder if it would be possible to run $TS_CMD_COL with ts_run? It's the only place where ASAN_OPTIONS and UBSAN_OPTIONS are set correctly: #1072.

kerolasa added a commit to kerolasa/util-linux that referenced this pull request Aug 8, 2020
With these tests coverage is about 89%.

The ts_run is added to ensure ASAN_OPTIONS and UBSAN_OPTIONS are set
correctly when the tests run.

Reference: util-linux#1115 (comment)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
@kerolasa
Copy link
Member Author

kerolasa commented Aug 8, 2020

@kerolasa I wonder if it would be possible to run $TS_CMD_COL with ts_run? It's the only place where ASAN_OPTIONS and UBSAN_OPTIONS are set correctly: #1072.

I can certainly try. Lets see if 2f733b4 works better.

@kerolasa
Copy link
Member Author

kerolasa commented Aug 8, 2020

I should have taken a look what failed. The cf7825e should fix the LeakSanitizer in cost of being free() before exit fix that is usually considered quite pointless activity.

@evverx
Copy link
Member

evverx commented Aug 8, 2020

I think by analogy with #1077 (comment) another option would be to pass detect_leaks=0 when the col tests are run. Though all those memory leaks are still on Coverity Scan: https://scan.coverity.com/projects/karelzak-util-linux. I'd say going through them and figuring out what is intentional isn't exactly meaningful activity either :-)

@evverx
Copy link
Member

evverx commented Aug 8, 2020

Speaking of Coverity @kerolasa I'm not sure if you have access to it. I've just invited you to the "util-linux" organization there. I hope it's all right.

@evverx
Copy link
Member

evverx commented Aug 8, 2020

FWIW to judge from https://travis-ci.org/github/karelzak/util-linux/jobs/716144038 it seems on macOS col/io is failing with

diff-{{{

--- /Users/travis/build/karelzak/util-linux/tests/expected/col/io	2020-08-08 16:10:09.000000000 +0000

+++ /Users/travis/build/karelzak/util-linux/tests/output/col/io	2020-08-08 16:27:10.000000000 +0000

@@ -37,7 +37,6 @@

 half line

 �9
1

 �9exit sane

-col: failed on line 1: Invalid or incomplete multibyte or wide character

 flushing

 1

 2

}}}-diff



 FAILED (col/io)

@kerolasa
Copy link
Member Author

kerolasa commented Aug 8, 2020

Speaking of Coverity @kerolasa I'm not sure if you have access to it. I've just invited you to the "util-linux" organization there. I hope it's all right.

Thank you. Looks like there are plenty of small fixes that could be done. Perhaps I should cease the opportunity and make this release cycle to be mostly about covery fixes.

I will try to look into latest failures. Maybe the easiest is to compile the col(1) on my laptop with leaksanitizer enabled and make the feedback loop a lot shorter.

@evverx
Copy link
Member

evverx commented Aug 8, 2020

@kerolasa apart from Coverity util-linux was integrated into OSS-Fuzz recently (I'll try to start covering more code once #1068 is merged). If you're interested in receiving OSS-Fuzz bug reports let me know so that I can add your email address to https://github.com/google/oss-fuzz/blob/master/projects/util-linux/project.yaml. I should add that non-gmail addresses can only be used to get email notifications. To log in to their bug tracker and to oss-fuzz.com gmail addresses should be used unfortunately.

@kerolasa
Copy link
Member Author

kerolasa commented Aug 8, 2020

@evverx I have no idea what to expect with OSS-Fuzz but I am sure the reports themselves will educate me how to use them. My addresses are kerolasa(at)iki.fi and kerolasa(at)gmail.com. Thank you Evgeny, really nice to see another active contributor working to get util-linux better.

kerolasa added a commit to kerolasa/util-linux that referenced this pull request Aug 8, 2020
With these tests coverage is about 89%.

The ts_run is added to ensure ASAN_OPTIONS and UBSAN_OPTIONS are set
correctly when the tests run.

Reference: util-linux#1115 (comment)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
@evverx
Copy link
Member

evverx commented Aug 8, 2020

I have no idea what to expect with OSS-Fuzz

OSS-Fuzz has found two issues so far: https://bugs.chromium.org/p/oss-fuzz/issues/list?q=label%3AProj-util-linux&can=1. https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23861&q=label%3AProj-util-linux&can=1 seems to be a bug in the fuzz target though. Looks like I forgot to limit the number of bytes it's supposed to handle. I'll fix it next week.

My addresses are ...

I've just opened google/oss-fuzz#4287.

kerolasa added a commit to kerolasa/util-linux that referenced this pull request Aug 9, 2020
With these tests coverage is about 89%.

The ts_run is added to ensure ASAN_OPTIONS and UBSAN_OPTIONS are set
correctly when the tests run.

Reference: util-linux#1115 (comment)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
@kerolasa
Copy link
Member Author

kerolasa commented Aug 9, 2020

Hopefully last fix. The col io test "exit sane" is now discarding error message about invalid multibyte because linux and macos does not share the same error message string.

@kerolasa
Copy link
Member Author

Really weird, why MacOS is adding newline?

https://travis-ci.org/github/karelzak/util-linux/jobs/716341634#L3804

kerolasa added a commit to kerolasa/util-linux that referenced this pull request Aug 19, 2020
With these tests coverage is about 89%.

The ts_run is added to ensure ASAN_OPTIONS and UBSAN_OPTIONS are set
correctly when the tests run.

Reference: util-linux#1115 (comment)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
@kerolasa
Copy link
Member Author

The part of test that upset macos is removed.

kerolasa added a commit to kerolasa/util-linux that referenced this pull request Aug 28, 2020
With these tests coverage is about 89%.

The ts_run is added to ensure ASAN_OPTIONS and UBSAN_OPTIONS are set
correctly when the tests run.

Reference: util-linux#1115 (comment)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
text-utils/col.c Outdated
{
errx(EXIT_FAILURE, _("write error"));
if (putwchar(ch) == WEOF)
errx(EXIT_FAILURE, _("write error"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be better to use _("write failed") as we have in other tools? Would be possible to use err() to get details about the error?

Copy link
Member Author

Choose a reason for hiding this comment

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

Text is fixed in 3375fd9, and I checked the err() is used not the errx().

text-utils/col.c Outdated
}
nb /= 2;
for (i = nb; --i >= 0;)
ctl->nblank_lines /= 2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it correct? It seems you modify global ctl->nblank_lines, but the original code uses a local variable and it does not refresh the original global setting -- nblank_lines is unmodified by this function in original code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I removed the commit that had ill thought variable removal.

text-utils/col.c Outdated
@@ -104,19 +104,20 @@ struct line_str {
CHAR *l_line; /* characters on the line */
LINE *l_prev; /* previous line */
LINE *l_next; /* next line */
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice by a separate patch to remove all the typedefs and LINE and CHAR, and use struct col_line and struct col_char. The typedef makes sense for simple opaque types (like some numbers etc.), otherwise typedef is evil.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, typedefs are removed in 2446db1.

text-utils/col.c Outdated
@@ -173,7 +176,7 @@ static void __attribute__((__noreturn__)) usage(void)
static inline void col_putchar(wchar_t ch)
{
if (putwchar(ch) == WEOF)
errx(EXIT_FAILURE, _("write error"));
err(EXIT_FAILURE, _("write error"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, yes, err() -- thanks.

@@ -651,5 +682,6 @@ int main(int argc, char **argv)
/* missing a \n on the last line? */
ctl.nblank_lines = 2;
flush_blanks(&ctl);
free_line_allocations(ctl.alloc_root);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we can use some #ifdef to call free_line_allocations() only to make LeakSanitizer happy :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Lets see if 3252914 works as expected. I added #if defined(__SANITIZE_ADDRESS__) around code that is performing these pointless at exit free's.

With these tests coverage is about 89%.

The ts_run is added to ensure ASAN_OPTIONS and UBSAN_OPTIONS are set
correctly when the tests run.

Reference: util-linux#1115 (comment)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Mark --tabs and --spaces mutually exclusive in same go.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Left side is always smaller or equal to right side.  This makes reading code
quicker when not having to constantly swap where is the greater value.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
kerolasa added a commit to kerolasa/util-linux that referenced this pull request Sep 12, 2020
Karel Zak said; typedef is evil, see reference.  I don't know are they evil,
but it is fair comment structs without hiding what is the data type is
easier and quicker understand when reading the code.

Reference: util-linux#1115 (comment)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Clean up before exit to satisfy LeakSanitizer tests run by travis.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Karel Zak said; typedef is evil, see reference.  I don't know are they evil,
but it is fair comment structs without hiding what is the data type is
easier and quicker understand when reading the code.

Reference: util-linux#1115 (comment)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
@karelzak karelzak merged commit 18b96d7 into util-linux:master Sep 29, 2020
@karelzak
Copy link
Collaborator

Thanks! I did tiny changes to the code too.

@kerolasa kerolasa deleted the col-refactor branch September 29, 2020 19:49
karelzak added a commit that referenced this pull request Sep 30, 2020
The macro FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION does not have to
enabled in all cases (e.g. default travis-ci, local tests, ...). It
seems more robust also check for __SANITIZE_ADDRESS__ too.

Addresses: #1115
Signed-off-by: Karel Zak <kzak@redhat.com>
@kerolasa kerolasa mentioned this pull request Oct 18, 2020
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.

3 participants