commit:     d1efa4641f32952b40c48bb5ff7eebb1f3e79dd6
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 29 20:18:36 2025 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon Dec 29 20:18:36 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=d1efa464

*: fix glibc errors for write and open

- the result of write must be checked
- open with O_CREAT must have 3rd argument with file mode

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 q.c    | 11 +++++++----
 qpkg.c | 14 ++++++++------
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/q.c b/q.c
index c4a9e6a..91ac5ef 100644
--- a/q.c
+++ b/q.c
@@ -460,7 +460,8 @@ static int q_jobserver(char *path, int njobs)
        }
 
        for (i = 0; i < njobs; i++)
-               write(pipefds[1], "q", 1);
+               if (write(pipefds[1], "q", 1) != 1)
+                       i--;  /* this is close to impossible though */
 
        while (!q_js_shutdown)
                sleep(1);
@@ -865,7 +866,8 @@ int q_main(int argc, char **argv)
 
                        /* ensure we can actually write the new cache */
                        mkdir_p_at(t->tree_fd, "metadata", 0755);
-                       fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC);
+                       fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC,
+                                         S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH 
/* 0644 */);
 
                        a = archive_write_new();
                        archive_write_set_format_ustar(a);  /* GLEP-78, just to 
be safe */
@@ -1140,8 +1142,9 @@ int q_main(int argc, char **argv)
                                }
 
                                /* tell grandparent we've made it */
-                               write(fds[1], "OK:", 3);
-                               write(fds[1], jslink, strlen(jslink));
+                               if (write(fds[1], "OK:", 3) != 3 ||
+                                       write(fds[1], jslink, strlen(jslink)) 
!= strlen(jslink))
+                                       warnp("could not report success");
                                close(fds[1]);
                                /* close stdio streams */
                                close(0);

diff --git a/qpkg.c b/qpkg.c
index 291fdc7..29da9f7 100644
--- a/qpkg.c
+++ b/qpkg.c
@@ -210,7 +210,8 @@ write_hashes
                        " BLAKE2B %s", blak2b);
        len += snprintf(data + len, sizeof(data) - len, "\n");
 
-       write(fd, data, len);
+       if (write(fd, data, len) != len)
+               warnp("failed to write hash data");
 }
 
 static const char *
@@ -284,27 +285,28 @@ qgpkg_make(tree_pkg_ctx *pkg)
        fflush(stdout);
 
        snprintf(buf, sizeof(buf), "%s/Manifest", tmpdir);
-       mfd = open(buf, O_WRONLY | O_CREAT | O_TRUNC);
+       mfd = open(buf, O_WRONLY | O_CREAT | O_TRUNC,
+                          S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
        if (mfd < 0) {
                rmdir(tmpdir);
                printf("%sFAIL%s\n", RED, NORM);
                return -4;
        }
-       fchmod(mfd, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
 
        snprintf(buf, sizeof(buf), "%s/gpkg-1", tmpdir);
-       fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC);
+       fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC,
+                         S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
        if (mfd < 0) {
                close(mfd);
                rm_rf(tmpdir);
                printf("%sFAIL%s\n", RED, NORM);
                return -5;
        }
-       fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
        /* contractually we don't have to put anything in here, but we drop
         * our signature so it can be traced back to us */
        len = snprintf(ename, sizeof(ename), "portage-utils-%s", VERSION);
-       write(fd, ename, len);
+       if (write(fd, ename, len) != len)
+               warnp("could not write self-identifier");
        close(fd);
        write_hashes(buf, "DATA", mfd);
 

Reply via email to