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

Fix notify silently fails #146

Merged
merged 2 commits into from Jun 10, 2022
Merged

Fix notify silently fails #146

merged 2 commits into from Jun 10, 2022

Conversation

parrasajad
Copy link
Contributor

  • set buffer to file size
  • split line into multiple chunks if line size is greater than char-limit

@parrasajad parrasajad linked an issue Jun 10, 2022 that may be closed by this pull request
internal/runner/util.go Outdated Show resolved Hide resolved
@sonarcloud
Copy link

sonarcloud bot commented Jun 10, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@justinsteven
Copy link
Contributor

@ehsandeep I'm having problems with this, I think it needs to be backed out.

Before this PR was landed:

% git log -n1
commit b947254064e6c09d18b56e1064cbcbabb0e21e72 (HEAD)
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Fri Jun 10 00:51:23 2022 +0530

    chore(deps): bump golang from 1.18.2-alpine to 1.18.3-alpine (#144)

    Bumps golang from 1.18.2-alpine to 1.18.3-alpine.

    ---
    updated-dependencies:
    - dependency-name: golang
      dependency-type: direct:production
      update-type: version-update:semver-patch
    ...

    Signed-off-by: dependabot[bot] <support@github.com>

    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

% go build .

% id | ./notify

             __  _ ___
  ___  ___  / /_(_) _/_ __
 / _ \/ _ \/ __/ / _/ // /
/_//_/\___/\__/_/_/ \_, / v1.0.2-dev
                   /___/

                projectdiscovery.io

Use with caution. You are responsible for your actions
Developers assume no liability and are not responsible for any misuse or damage.
Using default provider config: /home/justin/.config/notify/provider-config.yaml
uid=31337(justin) gid=31337(justin) groups=31337(justin),27(sudo)

% id | ./notify -bulk

             __  _ ___
  ___  ___  / /_(_) _/_ __
 / _ \/ _ \/ __/ / _/ // /
/_//_/\___/\__/_/_/ \_, / v1.0.2-dev
                   /___/

                projectdiscovery.io

Use with caution. You are responsible for your actions
Developers assume no liability and are not responsible for any misuse or damage.
Using default provider config: /home/justin/.config/notify/provider-config.yaml
uid=31337(justin) gid=31337(justin) groups=31337(justin),27(sudo)

% ./notify -i /etc/issue

             __  _ ___
  ___  ___  / /_(_) _/_ __
 / _ \/ _ \/ __/ / _/ // /
/_//_/\___/\__/_/_/ \_, / v1.0.2-dev
                   /___/

                projectdiscovery.io

Use with caution. You are responsible for your actions
Developers assume no liability and are not responsible for any misuse or damage.
Using default provider config: /home/justin/.config/notify/provider-config.yaml
Debian GNU/Linux 10 \n \l

% ./notify -i /etc/issue -bulk

             __  _ ___
  ___  ___  / /_(_) _/_ __
 / _ \/ _ \/ __/ / _/ // /
/_//_/\___/\__/_/_/ \_, / v1.0.2-dev
                   /___/

                projectdiscovery.io

Use with caution. You are responsible for your actions
Developers assume no liability and are not responsible for any misuse or damage.
Using default provider config: /home/justin/.config/notify/provider-config.yaml
Debian GNU/Linux 10 \n \l

File-based and stdin with bulk and non-bulk all work.

As of this PR being landed:

% id | ./notify

             __  _ ___
  ___  ___  / /_(_) _/_ __
 / _ \/ _ \/ __/ / _/ // /
/_//_/\___/\__/_/_/ \_, / v1.0.2-dev
                   /___/

                projectdiscovery.io

Use with caution. You are responsible for your actions
Developers assume no liability and are not responsible for any misuse or damage.
Using default provider config: /home/justin/.config/notify/provider-config.yaml

% id | ./notify -bulk

             __  _ ___
  ___  ___  / /_(_) _/_ __
 / _ \/ _ \/ __/ / _/ // /
/_//_/\___/\__/_/_/ \_, / v1.0.2-dev
                   /___/

                projectdiscovery.io

Use with caution. You are responsible for your actions
Developers assume no liability and are not responsible for any misuse or damage.
Using default provider config: /home/justin/.config/notify/provider-config.yaml

% ./notify -i /etc/issue

             __  _ ___
  ___  ___  / /_(_) _/_ __
 / _ \/ _ \/ __/ / _/ // /
/_//_/\___/\__/_/_/ \_, / v1.0.2-dev
                   /___/

                projectdiscovery.io

Use with caution. You are responsible for your actions
Developers assume no liability and are not responsible for any misuse or damage.
Using default provider config: /home/justin/.config/notify/provider-config.yaml
Debian GNU/Linux 10 \n \l

% ./notify -i /etc/issue -bulk

             __  _ ___
  ___  ___  / /_(_) _/_ __
 / _ \/ _ \/ __/ / _/ // /
/_//_/\___/\__/_/_/ \_, / v1.0.2-dev
                   /___/

                projectdiscovery.io

Use with caution. You are responsible for your actions
Developers assume no liability and are not responsible for any misuse or damage.
Using default provider config: /home/justin/.config/notify/provider-config.yaml

stdin is broken, and file-based bulk is broken

I can see that this PR is getting the size of the infile. I suspect this breaks for stdin, and for file-based it could cause memory pressure given a large infile.

I think we need to write a new bufio.SplitFunc similarly to that in #130, or tweak the one in #130 to also be usable in non-bulk mode (i.e. to split on newlines)

@ehsandeep
Copy link
Member

@justinsteven thanks for pointing it out, it should be addressed in #149

@justinsteven justinsteven mentioned this pull request Jun 11, 2022
justinsteven added a commit to justinsteven/notify that referenced this pull request Jun 12, 2022
ehsandeep pushed a commit that referenced this pull request Jun 13, 2022
* Revert "Fix notify silently fails (#146)"

This reverts commit 173f914.

* Emit logged lines to stdout, not stderr

Fixes #134 (this was previously fixed but got backed out in landing #130)

* Split lines as per CharLimit in non-bulk mode

Resolves #137

* Bubble up any Scanner errors

This surfaces the error that's causing #138:

'bufio.Scanner: token too long'

* Fix infinite loop with -char-limit <= len('...')

We're using '...' to indicate that a line has been truncated. If -char-limit
was less than the length of this ellipsis string, the scanner would never
terminate.

Raise an error if the charLimit given to a splitter is <= len('...')

* Ensure we never allow the Scanner buffer to fill

We know we never need more than CharLimit chars from the Scanner in one go

First of all, we ensure that the Scanner has a buffer which can hold at least
CharLimit chars.

Then we handle cases where the Scanner wants more data but we don't need it
to get more data. Thus it should never end up in a place where its internal
buffer is filled, and it should never return bufio.ErrToLong

Fixes #138

* fmt.print => gologger

Co-authored-by: mzack <marco.rivoli.nvh@gmail.com>
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.

notify silently fails given a line of more than 64KB
4 participants