Skip to content

Commit 6e774ba

Browse files
committed
parse_line: allow -1 for apexes and sdk libraries.
Since we're in much worse trouble if `/data/system/packages.list` is attacker-controlled, there doesn't seem like much benefit to having the little bit of [incomplete] range checking we had on the uid field (by using a wider type than `uid_t` actually is), and apparently we're now abusing `-1` to mean "apex or sdk library", despite `uid_t` being an unsigned type. Bug: http://b/336659478 Change-Id: I7a270eea937d21fc1d7fcda8654054210cf631fe
1 parent 6f52052 commit 6e774ba

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

libpackagelistparser/include/packagelistparser/packagelistparser.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ typedef struct pkg_info {
3333
/** Package name like "com.android.blah". */
3434
char* name;
3535

36-
/** Package uid like 10014. */
36+
/**
37+
* Package uid like 10014.
38+
* Note that apexes and SDK libraries may have a bogus 0xffffffff value.
39+
*/
3740
uid_t uid;
3841

3942
/** Package's AndroidManifest.xml debuggable flag. */

libpackagelistparser/packagelistparser.cpp

+4-12
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,13 @@ static bool parse_gids(const char* path, size_t line_number, const char* gids, p
6363
}
6464

6565
static bool parse_line(const char* path, size_t line_number, const char* line, pkg_info* info) {
66-
unsigned long uid;
6766
int debuggable;
6867
char* gid_list;
6968
int profileable_from_shell = 0;
70-
7169
int fields =
72-
sscanf(line, "%ms %lu %d %ms %ms %ms %d %ld", &info->name, &uid, &debuggable, &info->data_dir,
73-
&info->seinfo, &gid_list, &profileable_from_shell, &info->version_code);
70+
sscanf(line, "%ms %u %d %ms %ms %ms %d %ld", &info->name, &info->uid,
71+
&debuggable, &info->data_dir, &info->seinfo, &gid_list,
72+
&profileable_from_shell, &info->version_code);
7473

7574
// Handle the more complicated gids field and free the temporary string.
7675
bool gids_okay = parse_gids(path, line_number, gid_list, info);
@@ -84,14 +83,7 @@ static bool parse_line(const char* path, size_t line_number, const char* line, p
8483
return false;
8584
}
8685

87-
// Extra validation.
88-
if (uid > UID_MAX) {
89-
ALOGE("%s:%zu: uid %lu > UID_MAX", path, line_number, uid);
90-
return false;
91-
}
92-
info->uid = uid;
93-
94-
// Integer to bool conversions.
86+
// Convert integers to bools.
9587
info->debuggable = debuggable;
9688
info->profileable_from_shell = profileable_from_shell;
9789

0 commit comments

Comments
 (0)