Commit c1ad0f8f authored by Andrey Vagin's avatar Andrey Vagin Committed by Andrei Vagin

unit: don't check ui->ue->name.len twice in bind_unix_sk()

Acked-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 3347c6ef
......@@ -1349,51 +1349,49 @@ static int bind_unix_sk(int sk, struct unix_sk_info *ui)
addr.sun_family = AF_UNIX;
memcpy(&addr.sun_path, ui->name, ui->ue->name.len);
if (ui->ue->name.len) {
if (ui->name[0] && prep_unix_sk_cwd(ui, &cwd_fd, NULL, &ns_fd))
return -1;
if (ui->name[0] && prep_unix_sk_cwd(ui, &cwd_fd, NULL, &ns_fd))
return -1;
ret = bind(sk, (struct sockaddr *)&addr,
sizeof(addr.sun_family) + ui->ue->name.len);
if (ret < 0) {
if (ui->ue->has_deleted && ui->ue->deleted && errno == EADDRINUSE) {
if (bind_deleted_unix_sk(sk, ui, &addr))
goto done;
} else {
pr_perror("Can't bind socket");
ret = bind(sk, (struct sockaddr *)&addr,
sizeof(addr.sun_family) + ui->ue->name.len);
if (ret < 0) {
if (ui->ue->has_deleted && ui->ue->deleted && errno == EADDRINUSE) {
if (bind_deleted_unix_sk(sk, ui, &addr))
goto done;
}
} else {
pr_perror("Can't bind socket");
goto done;
}
}
if (*ui->name && ui->ue->file_perms) {
FilePermsEntry *perms = ui->ue->file_perms;
char fname[PATH_MAX];
if (ui->ue->name.len >= sizeof(fname)) {
pr_err("The file name is too long\n");
goto done;
}
if (*ui->name && ui->ue->file_perms) {
FilePermsEntry *perms = ui->ue->file_perms;
char fname[PATH_MAX];
memcpy(fname, ui->name, ui->ue->name.len);
fname[ui->ue->name.len] = '\0';
if (ui->ue->name.len >= sizeof(fname)) {
pr_err("The file name is too long\n");
goto done;
}
if (fchownat(AT_FDCWD, fname, perms->uid, perms->gid, 0) == -1) {
pr_perror("Unable to change file owner and group");
goto done;
}
memcpy(fname, ui->name, ui->ue->name.len);
fname[ui->ue->name.len] = '\0';
if (fchmodat(AT_FDCWD, fname, perms->mode, 0) == -1) {
pr_perror("Unable to change file mode bits");
goto done;
}
if (fchownat(AT_FDCWD, fname, perms->uid, perms->gid, 0) == -1) {
pr_perror("Unable to change file owner and group");
goto done;
}
if (ui->ue->deleted && unlink((char *)ui->ue->name.data) < 0) {
pr_perror("failed to unlink %s", ui->ue->name.data);
if (fchmodat(AT_FDCWD, fname, perms->mode, 0) == -1) {
pr_perror("Unable to change file mode bits");
goto done;
}
}
if (ui->ue->deleted && unlink((char *)ui->ue->name.data) < 0) {
pr_perror("failed to unlink %s", ui->ue->name.data);
goto done;
}
if (ui->ue->state != TCP_LISTEN) {
ui->bound = 1;
wake_connected_sockets(ui);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment