Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/zncPublic
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Fix double-prefixing in log module when using explicit relative path with -d#1591

Open
TheWug wants to merge1 commit intoznc:master
base:master
Choose a base branch
Loading
fromTheWug:fix-double-path-prefixing

Conversation

TheWug
Copy link
Contributor

CDir::CheckPathPrefix is called twice, both in OnLoad, and again in PutLog. Normally
the second is a no-op, but if the module path is explicitly relative (e.g. to "."),
It will incorrectly add the prefix twice.

…ive path with -dCDir::CheckPathPrefix is called twice, both in OnLoad, and again in PutLog. Normallythe second is a no-op, but if the module path is explicitly relative (e.g. to "."),It will incorrectly add the prefix twice.
@codecov
Copy link

codecovbot commentedAug 3, 2018
edited
Loading

Codecov Report

Merging#1591 intomaster willincrease coverage by0.03%.
The diff coverage isn/a.

Impacted file tree graph

@@            Coverage Diff             @@##           master    #1591      +/-   ##==========================================+ Coverage   37.44%   37.48%   +0.03%==========================================  Files         127      127                Lines       31023    31022       -1       Branches       93       93              ==========================================+ Hits        11617    11628      +11+ Misses      19357    19345      -12  Partials       49       49
Impacted FilesCoverage Δ
modules/log.cpp2.53% <ø> (ø)⬆️
src/FileUtils.cpp49.75% <0%> (-0.5%)⬇️
src/Utils.cpp68.81% <0%> (+2.2%)⬆️

Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last updatee2a9647...6f961ad. Read thecomment docs.

@DarthGandalf
Copy link
Member

What if I'm talking to.. ?

@TheWug
Copy link
ContributorAuthor

ZNC handles.. poorly with or without the patch.

Without the patch, sPath on :295 has the value:
./users/WugTest/moddata/log/users/WugTest/moddata/log/2018-08-15.log

With the patch, sPath has the values:
./users/WugTest/moddata/log/TestNetwork/../2018-08-15.log

These are both using the default logpath for user modules,$NETWORK/$WINDOW/%Y-%m-%d.log.
The only difference between ordinary behavior and this special case is that CheckPathPrefix elides the .. path element by removing it and the prior one, it doesn't stop the undesirable filesystem traversal.

I can patch this too while I'm here. I propose "." and ".." be substituted with "log.dot" and "log.dotdot" if they appear by themselves in a path element.

  • if they aren't by themselves, they'll be left alone
  • $WINDOW's replacement contains a literal dot to prevent collision with nicknames, which never do

@DarthGandalf
Copy link
Member

DarthGandalf commentedAug 15, 2018 via email

If the problem is with relative path in -d, other parts of ZNC can behavepoorly with such path. In that case not log module should be fixed, but -dflag: it should convert relative path to absolute path upon startup.2018-08-15 14:55 GMT+01:00 Ryan <notifications@github.com>:
ZNC handles .. poorly with or without the patch. Without the patch, sPath on :295 has the value: ./users/WugTest/moddata/log/users/WugTest/moddata/log/2018-08-15.log With the patch, sPath has the values: ./users/WugTest/moddata/log/TestNetwork/../2018-08-15.log These are both using the default logpath for user modules, $NETWORK/$WINDOW/%Y-%m-%d.log. The only difference between ordinary behavior and this special case is that CheckPathPrefix elides the .. path element by removing it and the prior one, it doesn't stop the undesirable filesystem traversal. I can patch this too while I'm here. I propose "." and ".." be substituted with "log.dot" and "log.dotdot" if they appear by themselves in a path element. - if they aren't by themselves, they'll be left alone - $WINDOW's replacement contains a literal dot to prevent collision with nicknames, which never do — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#1591 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAT15OjmjmVnHcAnuBCDGKCO8CbjY1uuks5uRChQgaJpZM4VuTkY> .

@TheWug
Copy link
ContributorAuthor

I disagree. If something behaves badly when you give it a relative path, then I think ensuring all paths are absolute just masks possible bugs.

I think CDir::CheckPathPrefix is poorly named, poorly documented, and its implementation very inelegant. If a function like that were included now in a pull request, you would surely reject it. I think a much better solution would be to replace it with a new function whose behavior is more strongly defined.

@DarthGandalf
Copy link
Member

DarthGandalf commentedAug 15, 2018 via email

Well, both. -d should be fixed, and CDir::CheckPathPrefix should be fixed.2018-08-15 15:37 GMT+01:00 Ryan <notifications@github.com>:
I disagree. If something behaves badly when you give it a relative path, then I think ensuring all paths are absolute just masks possible bugs.
Are you willing to provide test cases for every possible ZNC codepath whichhappens to use file paths? Ensuring all paths are absolute is moreself-contained change which fixes not only issue you discovered, but alsofuture issues with relative paths.
I think CDir::CheckPathPrefix is poorly named, poorly documented, and its implementation very inelegant. If a function like that were included now in a pull request, you would surely reject it. I think a much better solution would be to replace it with a new function whose behavior is more strongly defined. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#1591 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAT15NIUyHje4k-s7qrGRbdg2bqDzdzHks5uRDIPgaJpZM4VuTkY> .

@TheWug
Copy link
ContributorAuthor

Are you willing to provide test cases for every possible ZNC codepath which
happens to use file paths? Ensuring all paths are absolute is more
self-contained change which fixes not only issue you discovered, but also
future issues with relative paths.

I've been thinking about it and looking into the impact. This particular issue is pretty self contained because unlike all of the other callsites (of which there are only 5), CheckPathPrefix is called in the following way:

sPath = CheckPathPrefix(GetSavePath(), CheckPathPrefix(GetSavePath(), ...))

ChangeDir handles two relative paths by appending them (into a new relative path), thus the doubling. A more complete solution would be to change CheckPathPrefix to check the prefix before calling ChangeDir, but then the second CheckPathPrefix call in log.cpp is always a no-op so it should still be removed.

@TheWug
Copy link
ContributorAuthor

I have a build now that replaces CDir::CheckPathPrefix with 2 new functions, CFile::GetRelativeFile and CFile::Contains, that do the same thing, but generalized to relative paths. CFile::GetRelativeFile in conjunction with another new function CFile::Canonize can also probably replace CDir::ChangeDir. The only thing I'm not sure about is whether to kill them completely, or leave them around but deprecated, since the python and perl bindings use them, and removing them will break any python/perl scripts that depend on them. I'll clean it up and push it to a new branch tonight.

@DarthGandalf
Copy link
Member

I'll clean it up and push it to a new branch tonight.

Any progress?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@TheWug@DarthGandalf

[8]ページ先頭

©2009-2025 Movatter.jp