Skip to content

Commit 9c24c49

Browse files
authored
Avoid segfault for anonymous clients with macaroons (#39)
Don't dereference a null sentryPtr
1 parent a5e309c commit 9c24c49

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/UserSentry.hh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public:
7676
std::string username;
7777
auto got_token = client->eaAPI->Get("request.name", username);
7878
if (!got_token && (!client->name || !client->name[0])) {
79-
log.Emsg("UserSentry", "Anonymous client; no user set, cannot change FS UIDs");
80-
m_is_anonymous = true;
79+
// Anonymous client; no user set
80+
this->Init("", log);
8181
return;
8282
}
8383

@@ -141,6 +141,12 @@ public:
141141

142142
int retval;
143143

144+
if (username.empty()) {
145+
log.Emsg("UserSentry", "Anonymous client; no user set, cannot change FS UIDs");
146+
m_is_anonymous = true;
147+
return;
148+
}
149+
144150
do {
145151
retval = getpwnam_r(username.c_str(), &pwd, &buf[0], buflen, &result);
146152
if ((result == nullptr) && (retval == ERANGE)) {

src/multiuser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ class MultiuserChecksum : public XrdCksWrapper
246246
if (username) {
247247
return new UserSentry(username, *m_log);
248248
} else {
249-
return nullptr;
249+
// Anonymous requests will not have a request.name
250+
return new UserSentry("", *m_log);
250251
}
251252
}
252253
}

0 commit comments

Comments
 (0)