mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-09-29 21:04:22 +00:00
nmtui: handle write() errors correctly in nmt_newt_edit_string
It might happen that write() returns -1, but the errno is not EINTR.
In that case, the length would be incremented by 1, and the data pointer
to the data being written would be moved back by 1 byte on every error.
Make it so that the function exits with an error if it indicates an error.
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1971
Fixes: 3bda3fb60c
('nmtui: initial import of nmtui')
This commit is contained in:
parent
4b66f9fe71
commit
13317bd536
|
@ -416,9 +416,18 @@ nmt_newt_edit_string(const char *data)
|
|||
|
||||
len = data ? strlen(data) : 0;
|
||||
while (len) {
|
||||
do
|
||||
nwrote = write(fd, data, len);
|
||||
while (nwrote == -1 && errno == EINTR);
|
||||
nwrote = write(fd, data, len);
|
||||
|
||||
if (nwrote == -1) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nmt_newt_message_dialog(_("Could not write to temporary file: %s"),
|
||||
nm_strerror_native(errno));
|
||||
nm_close(fd);
|
||||
goto done;
|
||||
}
|
||||
|
||||
len -= nwrote;
|
||||
data += nwrote;
|
||||
|
|
Loading…
Reference in a new issue