Fix macOS's package inventory not parsing info correctly#3035
Merged
chemamartinez merged 4 commits into3.9from Apr 10, 2019
Merged
Fix macOS's package inventory not parsing info correctly#3035chemamartinez merged 4 commits into3.9from
chemamartinez merged 4 commits into3.9from
Conversation
added 3 commits
April 4, 2019 13:41
…oviding a way to get the app's name from its corresponding folder.
chemamartinez
suggested changes
Apr 10, 2019
| #if defined(__MACH__) | ||
|
|
||
| char* sys_parse_pkg(const char * app_folder, const char * timestamp, int random_id); | ||
| char* sys_parse_pkg(const char * app_folder, const char * folder_name, const char * timestamp, int random_id); |
Contributor
There was a problem hiding this comment.
Yo don't need to pass to sys_parse_pkg the folder name, it is included in the app_folder variable.
| int void_file=1; | ||
| while(fgets(read_buff, OS_MAXSTR - 1, fp) != NULL) { | ||
|
|
||
|
|
Contributor
There was a problem hiding this comment.
Why this new line here?
| } | ||
| } | ||
| } | ||
| if(void_file==0){ |
Contributor
There was a problem hiding this comment.
You can specify the location and the source of the package even though the parse of the rest of the fields failed.
| cJSON_AddItemToObject(object, "program", package); | ||
| cJSON_AddStringToObject(package, "format", "pkg"); | ||
|
|
||
| int void_file=1; |
Contributor
There was a problem hiding this comment.
Here we should check if the Info.plist file is valid to be parsed, not when looking for the name program inside the file.
| } | ||
| cJSON_AddStringToObject(package, "location", app_folder); | ||
| } | ||
| else{ |
Contributor
There was a problem hiding this comment.
It is better to not include version, group and description when the file cannot be parsed because we cannot control what contain these fields.
chemamartinez
approved these changes
Apr 10, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is aimed at solving issue #2922.
Description
Info.plistfiles with a different internal format, and it produced data that was empty or filled with garbage while trying. Now it can read files using both vertical and horizontal labels, and when they use a different format that it doesn't know how to parse, it at least tries to read the package's name from its folder and then empties the rest of the fields.Use case
VirtualBox's Info.plist file por example has a format such as follows:
syscollector wasn't ready to read labels horizontally, so it resulted in wrong data being collected, like this:
1880543464|2019/04/05 10:16:16|pkg|VirtualBox||||||CFBundleGetInfoString||||CFBundleName||0Now syscollector can read the file, producing the desired outcome:
1901203817|2019/04/05 12:05:03|pkg|VirtualBox||||||6.0.4|||applications|org.virtualbox.app.VirtualBox|/Applications/VirtualBox.app|0If the file coulnd't be read anyways (because of it having a not supported format or it being corrupted), it would collect its name from the
/Applications/VirtualBox.appand leave the remaining fields empty, like this:115170242|2019/04/05 11:01:57|pkg|VirtualBox||||||||||||0Testing
The previous changes have been tested with the previously problematic package VirtualBox.