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

client: fix potential buffer overflow #12515

Merged
merged 2 commits into from Jan 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/client/SyntheticClient.cc
Expand Up @@ -1004,8 +1004,8 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only)
UserPerm perms = client->pick_my_perms();
t.start();

char buf[1024];
char buf2[1024];
string buf;
string buf2;

utime_t start = ceph_clock_now(client->cct);

Expand Down
16 changes: 8 additions & 8 deletions src/client/Trace.cc
Expand Up @@ -52,22 +52,22 @@ void Trace::start()
_line = 1;
}

const char *Trace::peek_string(char *buf, const char *prefix)
const char *Trace::peek_string(string &buf, const char *prefix)
{
//if (prefix) cout << "prefix '" << prefix << "' line '" << line << "'" << std::endl;
if (prefix &&
strstr(line.c_str(), "/prefix") == line.c_str()) {
strcpy(buf, prefix);
strcpy(buf + strlen(prefix),
line.c_str() + strlen("/prefix"));
buf.clear();
buf.append(prefix);
buf.append(line.c_str() + strlen("/prefix"));
} else {
strcpy(buf, line.c_str());
buf = line;
}
return buf;
return buf.c_str();
}


const char *Trace::get_string(char *buf, const char *prefix)
const char *Trace::get_string(string &buf, const char *prefix)
{
peek_string(buf, prefix);

Expand All @@ -77,5 +77,5 @@ const char *Trace::get_string(char *buf, const char *prefix)
getline(*fs, line);
//cout << "next line is " << line << std::endl;

return buf;
return buf.c_str();
}
6 changes: 3 additions & 3 deletions src/client/Trace.h
Expand Up @@ -51,11 +51,11 @@ class Trace {

void start();

const char *peek_string(char *buf, const char *prefix);
const char *get_string(char *buf, const char *prefix);
const char *peek_string(string &buf, const char *prefix);
const char *get_string(string &buf, const char *prefix);

int64_t get_int() {
char buf[20];
string buf;
return atoll(get_string(buf, 0));
}
bool end() {
Expand Down