Correctly check some non-checked return values

This commit is contained in:
Ben RUBSON 2017-10-03 16:19:26 +02:00 committed by GitHub
parent 44c7576f21
commit 42dc11e3b1
5 changed files with 61 additions and 28 deletions

View File

@ -520,20 +520,26 @@ int DirNode::mkdir(const char *plaintextPath, mode_t mode, uid_t uid,
int res = ::mkdir(cyName.c_str(), mode);
if (olduid >= 0) {
setfsuid(olduid);
}
if (oldgid >= 0) {
setfsgid(oldgid);
}
if (res == -1) {
int eno = errno;
RLOG(WARNING) << "mkdir error on " << cyName << " mode " << mode << ": "
<< strerror(eno);
res = -eno;
} else {
res = 0;
}
if (olduid >= 0) {
if(setfsuid(olduid) == -1) {
int eno = errno;
RLOG(DEBUG) << "setfsuid back error: " << strerror(eno);
// does not return error here as initial setfsuid worked
}
}
if (oldgid >= 0) {
if(setfsgid(oldgid) == -1) {
int eno = errno;
RLOG(DEBUG) << "setfsgid back error: " << strerror(eno);
// does not return error here as initial setfsgid worked
}
}
return res;

View File

@ -194,10 +194,18 @@ int FileNode::mknod(mode_t mode, dev_t rdev, uid_t uid, gid_t gid) {
}
if (olduid >= 0) {
setfsuid(olduid);
if(setfsuid(olduid) == -1) {
int eno = errno;
RLOG(DEBUG) << "setfsuid back error: " << strerror(eno);
// does not return error here as initial setfsuid worked
}
}
if (oldgid >= 0) {
setfsgid(oldgid);
if(setfsgid(oldgid) == -1) {
int eno = errno;
RLOG(DEBUG) << "setfsgid back error: " << strerror(eno);
// does not return error here as initial setfsgid worked
}
}
return res;

View File

@ -136,7 +136,7 @@ int RawFileIO::open(int flags) {
#warning O_LARGEFILE not supported
#endif
int eno;
int eno = 0;
int newFd = ::open(name.c_str(), finalFlags);
if (newFd < 0) {
eno = errno;

View File

@ -456,15 +456,33 @@ int encfs_symlink(const char *to, const char *from) {
int oldgid = -1;
if (ctx->publicFilesystem) {
fuse_context *context = fuse_get_context();
olduid = setfsuid(context->uid);
oldgid = setfsgid(context->gid);
if (oldgid == -1) {
int eno = errno;
RLOG(DEBUG) << "setfsgid error: " << strerror(eno);
return -EPERM;
}
olduid = setfsuid(context->uid);
if (olduid == -1) {
int eno = errno;
RLOG(DEBUG) << "setfsuid error: " << strerror(eno);
return -EPERM;
}
}
res = ::symlink(toCName.c_str(), fromCName.c_str());
if (olduid >= 0) {
setfsuid(olduid);
if(setfsuid(olduid) == -1) {
int eno = errno;
RLOG(DEBUG) << "setfsuid back error: " << strerror(eno);
// does not return error here as initial setfsuid worked
}
}
if (oldgid >= 0) {
setfsgid(oldgid);
if(setfsgid(oldgid) == -1) {
int eno = errno;
RLOG(DEBUG) << "setfsgid back error: " << strerror(eno);
// does not return error here as initial setfsgid worked
}
}
if (res == -1) {

View File

@ -125,22 +125,23 @@ restart:
memset(&oterm, 0, sizeof(oterm));
}
(void)write(output, prompt, strlen(prompt));
end = buf + bufsiz - 1;
for (p = buf; (nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r';) {
if (p < end) {
if ((flags & RPP_SEVENBIT) != 0) {
ch &= 0x7f;
}
if (isalpha(ch) != 0) {
if ((flags & RPP_FORCELOWER) != 0) {
ch = tolower(ch);
if (write(output, prompt, strlen(prompt)) != -1) {
end = buf + bufsiz - 1;
for (p = buf; (nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r';) {
if (p < end) {
if ((flags & RPP_SEVENBIT) != 0) {
ch &= 0x7f;
}
if ((flags & RPP_FORCEUPPER) != 0) {
ch = toupper(ch);
if (isalpha(ch) != 0) {
if ((flags & RPP_FORCELOWER) != 0) {
ch = tolower(ch);
}
if ((flags & RPP_FORCEUPPER) != 0) {
ch = toupper(ch);
}
}
*p++ = ch;
}
*p++ = ch;
}
}
*p = '\0';