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) ...@@ -1349,51 +1349,49 @@ static int bind_unix_sk(int sk, struct unix_sk_info *ui)
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
memcpy(&addr.sun_path, ui->name, ui->ue->name.len); 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))
if (ui->name[0] && prep_unix_sk_cwd(ui, &cwd_fd, NULL, &ns_fd)) return -1;
return -1;
ret = bind(sk, (struct sockaddr *)&addr, ret = bind(sk, (struct sockaddr *)&addr,
sizeof(addr.sun_family) + ui->ue->name.len); sizeof(addr.sun_family) + ui->ue->name.len);
if (ret < 0) { if (ret < 0) {
if (ui->ue->has_deleted && ui->ue->deleted && errno == EADDRINUSE) { if (ui->ue->has_deleted && ui->ue->deleted && errno == EADDRINUSE) {
if (bind_deleted_unix_sk(sk, ui, &addr)) if (bind_deleted_unix_sk(sk, ui, &addr))
goto done;
} else {
pr_perror("Can't bind socket");
goto done; goto done;
} } else {
pr_perror("Can't bind socket");
goto done;
} }
}
if (*ui->name && ui->ue->file_perms) { if (*ui->name && ui->ue->file_perms) {
FilePermsEntry *perms = ui->ue->file_perms; FilePermsEntry *perms = ui->ue->file_perms;
char fname[PATH_MAX]; char fname[PATH_MAX];
if (ui->ue->name.len >= sizeof(fname)) {
pr_err("The file name is too long\n");
goto done;
}
memcpy(fname, ui->name, ui->ue->name.len); if (ui->ue->name.len >= sizeof(fname)) {
fname[ui->ue->name.len] = '\0'; pr_err("The file name is too long\n");
goto done;
}
if (fchownat(AT_FDCWD, fname, perms->uid, perms->gid, 0) == -1) { memcpy(fname, ui->name, ui->ue->name.len);
pr_perror("Unable to change file owner and group"); fname[ui->ue->name.len] = '\0';
goto done;
}
if (fchmodat(AT_FDCWD, fname, perms->mode, 0) == -1) { if (fchownat(AT_FDCWD, fname, perms->uid, perms->gid, 0) == -1) {
pr_perror("Unable to change file mode bits"); pr_perror("Unable to change file owner and group");
goto done; goto done;
}
} }
if (ui->ue->deleted && unlink((char *)ui->ue->name.data) < 0) { if (fchmodat(AT_FDCWD, fname, perms->mode, 0) == -1) {
pr_perror("failed to unlink %s", ui->ue->name.data); pr_perror("Unable to change file mode bits");
goto done; 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) { if (ui->ue->state != TCP_LISTEN) {
ui->bound = 1; ui->bound = 1;
wake_connected_sockets(ui); 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