Skip to content

Commit

Permalink
keyring: catch key decode errors
Browse files Browse the repository at this point in the history
Return EINVAL on decoding errors.

Other decode_base64() callers are already guarded.

Fixes: ceph#2124
Signed-off-by: Sage Weil <[email protected]>
  • Loading branch information
Sage Weil committed May 5, 2012
1 parent 6812309 commit ae0ca7b
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/auth/KeyRing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ int KeyRing::from_ceph_context(CephContext *cct, KeyRing **pkeyring)

if (!conf->key.empty()) {
EntityAuth ea;
ea.key.decode_base64(conf->key);
keyring->add(conf->name, ea);
found_key = true;
try {
ea.key.decode_base64(conf->key);
keyring->add(conf->name, ea);
found_key = true;
}
catch (buffer::error& e) {
lderr(cct) << "KeyRing::from_ceph_context: failed to decode key " << conf->key << dendl;
return -EINVAL;
}
}

if (!conf->keyfile.empty()) {
Expand All @@ -80,9 +86,15 @@ int KeyRing::from_ceph_context(CephContext *cct, KeyRing **pkeyring)
else {
string k = buf;
EntityAuth ea;
ea.key.decode_base64(k);
keyring->add(conf->name, ea);
found_key = true;
try {
ea.key.decode_base64(k);
keyring->add(conf->name, ea);
found_key = true;
}
catch (buffer::error& e) {
lderr(cct) << "KeyRing::from_ceph_context: failed to decode key " << k << dendl;
return -EINVAL;
}
}
fclose(fp);
} else {
Expand Down

0 comments on commit ae0ca7b

Please sign in to comment.