Skip to content

Commit

Permalink
Fix vold vulnerability in FrameworkListener
Browse files Browse the repository at this point in the history
Modify FrameworkListener to ignore commands that exceed the maximum
buffer length and send an error message.

Bug: 29831647
Change-Id: I9e57d1648d55af2ca0191bb47868e375ecc26950
Signed-off-by: Connor O'Brien <connoro@google.com>
(cherry picked from commit baa126d)
  • Loading branch information
cobrien7 committed Aug 19, 2016
1 parent 23effb0 commit 470484d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/sysutils/FrameworkListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class FrameworkListener : public SocketListener {
int mCommandCount;
bool mWithSeq;
FrameworkCommandCollection *mCommands;
bool mSkipToNextNullByte;

public:
FrameworkListener(const char *socketName);
Expand Down
17 changes: 14 additions & 3 deletions libsysutils/src/FrameworkListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void FrameworkListener::init(const char *socketName, bool withSeq) {
errorRate = 0;
mCommandCount = 0;
mWithSeq = withSeq;
mSkipToNextNullByte = false;
}

bool FrameworkListener::onDataAvailable(SocketClient *c) {
Expand All @@ -52,22 +53,32 @@ bool FrameworkListener::onDataAvailable(SocketClient *c) {
if (len < 0) {
SLOGE("read() failed (%s)", strerror(errno));
return false;
} else if (!len)
} else if (!len) {
return false;
if(buffer[len-1] != '\0')
} else if (buffer[len-1] != '\0') {
SLOGW("String is not zero-terminated");
android_errorWriteLog(0x534e4554, "29831647");
c->sendMsg(500, "Command too large for buffer", false);
mSkipToNextNullByte = true;
return false;
}

int offset = 0;
int i;

for (i = 0; i < len; i++) {
if (buffer[i] == '\0') {
/* IMPORTANT: dispatchCommand() expects a zero-terminated string */
dispatchCommand(c, buffer + offset);
if (mSkipToNextNullByte) {
mSkipToNextNullByte = false;
} else {
dispatchCommand(c, buffer + offset);
}
offset = i + 1;
}
}

mSkipToNextNullByte = false;
return true;
}

Expand Down

0 comments on commit 470484d

Please sign in to comment.