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 potential buffer underflow and inefficient copy using fnmatch. #261

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions libappstream-glib/as-app.c
Original file line number Diff line number Diff line change
Expand Up @@ -6219,7 +6219,9 @@ as_app_parse_appdata_guess_project_group (AsApp *app)
static int
as_utils_fnmatch (const gchar *pattern, const gchar *text, gsize text_sz, gint flags)
{
if (text_sz != -1 && text[text_sz-1] != '\0') {
if (text_sz == 0)
return FNM_NOMATCH;
if (text[text_sz-1] != '\0') {
Copy link
Owner

Choose a reason for hiding this comment

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

Why not just?

	if (text_sz != 0 && text[text_sz-1] != '\0') {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because a zero length buffer might not be nul terminated.

g_autofree gchar *text_with_nul = g_strndup (text, text_sz);
return fnmatch (pattern, text_with_nul, flags);
}
Expand Down Expand Up @@ -6334,7 +6336,9 @@ as_app_parse_appdata_file (AsApp *app,
filename, error_local->message);
return FALSE;
}
data = g_bytes_new_take (g_steal_pointer (&data_raw), len);
/* Note it is len + 1 - this is the contents of the file and the nul character
* that g_file_get_contents automatically appends */
data = g_bytes_new_take (g_steal_pointer (&data_raw), len + 1);
robert-ancell marked this conversation as resolved.
Show resolved Hide resolved
if (!as_app_parse_data (app, data, flags, &error_local)) {
g_set_error (error,
AS_APP_ERROR,
Expand Down