[ZBX-6161] "vfs.file.contents" returns garbage for an empty file Created: 2013 Jan 21  Updated: 2017 May 30  Resolved: 2013 Jan 23

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Agent (G)
Affects Version/s: 2.0.5rc1
Fix Version/s: 2.0.5rc1, 2.1.0

Type: Incident report Priority: Critical
Reporter: Oleksii Zagorskyi Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: crash
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The bug originally observed in a forum thread https://www.zabbix.com/forum/showthread.php?p=125033#post125033

And I can confirm it:

  1. zabbix_get -s localhost -k vfs.file.contents[/tmp/ttt]
    ?u??$
  1. ls -la /tmp/ttt
    rw-rr- 1 root root 0 Jan 21 14:41 /tmp/ttt

The issue reproduced for agent under windows as well.

Some more details will be added as a comment.



 Comments   
Comment by Oleksii Zagorskyi [ 2013 Jan 21 ]

There is some strange thing that when I use "zabbix_agentd -t ..." in versions 2.0.0-2.0.4 I'm getting my hostname ("it0") as a value for the key vfs.file.contents
I'm not sure it will work so on other hosts.
On a WindowsXP host with v2.0.3 I'm getting a garbage (not its hostname).

Tests on my Linux host:

# ./2.0.4/zabbix_agentd_2.0.4 -t vfs.file.contents[/tmp/ttt]
vfs.file.contents[/tmp/ttt]                   [t|it0]

# ./2.0.4/zabbix_agentd_2.0.4 -V
Zabbix Agent (daemon) v2.0.4 (revision 32392) (08 December 2012)
Compilation time: Jan 21 2013 14:57:19
# ./zabbix20/zabbix_agentd20 -t vfs.file.contents[/tmp/ttt]
vfs.file.contents[/tmp/ttt][/tmp/ttt]         [t|�ef]

# ./zabbix20/zabbix_agentd20 -V
Zabbix Agent (daemon) v2.0.5rc1 (revision 32959) (08 December 2012)
Compilation time: Jan 21 2013 14:59:44

By zabbix_get:

# zabbix_get -s localhost -p 10060 -k agent.version
2.0.4
# zabbix_get -s localhost -p 10060 -k vfs.file.contents[/tmp/ttt]
��$�(

restarted agent current 2.0 HEAD:

# zabbix_get -s localhost -p 10060 -k agent.version
2.0.5rc1
# zabbix_get -s localhost -p 10060 -k vfs.file.contents[/tmp/ttt]
(�A
Comment by Alexander Vladishev [ 2013 Jan 22 ]

The same problem if zabbix doesn't have permissions to a file.

Comment by Andris Zeila [ 2013 Jan 22 ]

The file reading buffer was not initialized resulting in undefined data when empty file is read. So it could return anything (including garbage data or interface names).

However when trying to access file without read rights a 'not supported' error is always returned.

Fixed in svn://svn.zabbix.com/branches/dev/ZBX-6161

Comment by Oleksii Zagorskyi [ 2013 Jan 22 ]

Well, now (dev branch) for the empty file I'm getting a text "EOF"

We use currently this approach for "vfs.file.regexp[file,regexp,<encoding>]" key.

Hmmm, I personally not very sure that it's good to return EOF for "vfs.file.contents", need to get more opinions.

Why we cannot return just empty value "" if file is empty ?
Zabbix server 2.0+ support this for textual items.

And this should be added to doc, here https://www.zabbix.com/documentation/2.0/manual/config/items/itemtypes/zabbix_agent

Comment by richlv [ 2013 Jan 22 ]

it must be an empty value otherwise we can't differentiate between an empty file and file with contents "EOF"

zalex_ua and ... the same we can say about "vfs.file.regexp" key, and I'm also not very happy on this.
For the "vfs.file.regexp" we also could return an empty value, as 2.0 supports this. Of course ... backward compatibility ... heh
Maybe we could reconsider this ?

<richlv> agreed. not sure whether we can handle all that in this issue

zalex_ua if we will end up with the empty value instead of EOF for "vfs.file.contents", then we will create separate request for "vfs.file.regexp", addressed I suppose for next major release.

sasha richlv, zalex: It's a different issue. We can't change the behavior inside 2.0. You can open a new ZBXNEXT.

FYI: also "EOF" can return web.page.get and web.page.regexp.

CLOSED

Comment by richlv [ 2013 Jan 22 ]

just a sidenote - would be awesome to have some tests for this

Comment by Alexander Vladishev [ 2013 Jan 23 ]

Successfully tested!

Comment by Andris Zeila [ 2013 Jan 23 ]

Fixed in:
pre-2.0.5rc1 r33066
pre-2.1.0 r33067

Comment by Oleksii Zagorskyi [ 2013 Jan 23 ]

Heh, we need answers on comments above.
Also - documentation looks like not updated, disregarding on a comment above.

Sorry, REOPENED.

Comment by Andris Zeila [ 2013 Jan 23 ]

vfs.file.contents originally returned (or tried to) EOF for empty files. Only because of this bug the real empty files returned random garbage, while files containing only LF/CR characters were trimmed to empty contents and EOF was properly returned.

As no features were changed/added I don't see why documentation should be changed (unless it was wrong in the first case).

Regarding the idea itself of empty files returning EOF - I agree that it would be better to return empty string. But that would be a feature change, so I believe it must go as a new request.

Comment by Alexander Vladishev [ 2013 Jan 23 ]

I'm closing the issue.

Comment by Oleksii Zagorskyi [ 2013 Jan 23 ]

heh, thank you for explanation Andris and Alexander !

In any case this piece of information still has to be added to doc, and I've just did it:
"Contents of a file or EOF if it is empty or it contains only LF/CR characters."
to
https://www.zabbix.com/documentation/2.0/manual/config/items/itemtypes/zabbix_agent
https://www.zabbix.com/documentation/2.2/manual/config/items/itemtypes/zabbix_agent

You could review.

Comment by Andris Zeila [ 2013 Jan 23 ]

Maybe instead of "Contents of a file or EOF" it would be better to write "Contents of a file or a string 'EOF'" or something. Otherwise some people might think that -1 is returned.

The same is true about vfs.file.regexp description.

Comment by Oleksii Zagorskyi [ 2013 Jan 23 ]

The idea to return an empty value instead of EOF moved to ZBX-6171

Generated at Fri Apr 26 21:44:43 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.