From: Érico Rolim Date: Mon, 2 Nov 2020 01:49:46 +0000 (-0300) Subject: Switch from numerical to defined constants for permissions. X-Git-Tag: elfutils-0.183~102 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ced66615bd8c3671c50252cba254fb939b04e362;p=thirdparty%2Felfutils.git Switch from numerical to defined constants for permissions. Use defined constants for permission values. Also add fallback definitions for them in system.h, to allow for compatibility with systems that don't provide these macros. Include system.h in all tests/ files that required it. Signed-off-by: Érico Rolim Signed-off-by: Mark Wielaard --- diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index 5b743d761..a02643e17 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -1,3 +1,8 @@ +2020-11-01 Érico N. Rolim + + * debuginfod-client.c (debuginfod_init_cache): Use ACCESSPERMS for + mkdir, DEFFILEMODE for open with O_CREAT. + 2020-11-01 Érico N. Rolim * debuginfod.cxx: include libintl.h. diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c index 0e5177bc6..ce1d819b9 100644 --- a/debuginfod/debuginfod-client.c +++ b/debuginfod/debuginfod-client.c @@ -212,13 +212,13 @@ debuginfod_init_cache (char *cache_path, char *interval_path, char *maxage_path) return 0; /* Create the cache and config files as necessary. */ - if (stat(cache_path, &st) != 0 && mkdir(cache_path, 0777) < 0) + if (stat(cache_path, &st) != 0 && mkdir(cache_path, ACCESSPERMS) < 0) return -errno; int fd = -1; /* init cleaning interval config file. */ - fd = open(interval_path, O_CREAT | O_RDWR, 0666); + fd = open(interval_path, O_CREAT | O_RDWR, DEFFILEMODE); if (fd < 0) return -errno; @@ -227,7 +227,7 @@ debuginfod_init_cache (char *cache_path, char *interval_path, char *maxage_path) /* init max age config file. */ if (stat(maxage_path, &st) != 0 - && (fd = open(maxage_path, O_CREAT | O_RDWR, 0666)) < 0) + && (fd = open(maxage_path, O_CREAT | O_RDWR, DEFFILEMODE)) < 0) return -errno; if (dprintf(fd, "%ld", cache_default_max_unused_age_s) < 0) diff --git a/lib/ChangeLog b/lib/ChangeLog index f4ab6d48b..663a7aa58 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,9 @@ +2020-11-01 Érico N. Rolim + + * system.h (ACCESSPERMS): Define macro if it doesn't exist. + (ALLPERMS): Likewise. + (DEFFILEMODE): Likewise. + 2020-06-11 Mark Wielaaard * printversion.c (print_version): Update copyright year. diff --git a/lib/system.h b/lib/system.h index 292082bdb..7b650f11f 100644 --- a/lib/system.h +++ b/lib/system.h @@ -85,6 +85,18 @@ __res; }) #endif +#ifndef ACCESSPERMS +#define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */ +#endif + +#ifndef ALLPERMS +#define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO) /* 07777 */ +#endif + +#ifndef DEFFILEMODE +#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666 */ +#endif + static inline ssize_t __attribute__ ((unused)) pwrite_retry (int fd, const void *buf, size_t len, off_t off) { diff --git a/src/ChangeLog b/src/ChangeLog index ab7ae3f61..668b18b0f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2020-11-01 Érico N. Rolim + + * unstrip.c (make_directories): Use ACCESSPERMS for mkdir. + (handle_file): Use DEFFILEMODE for open with O_CREAT for ET_REL + files, ACCESSPERMS otherwise. + 2020-11-01 Érico N. Rolim * Makefile.am (nm_LDADD): Add obstack_LIBS. diff --git a/src/unstrip.c b/src/unstrip.c index 0257d9cc3..231b941d2 100644 --- a/src/unstrip.c +++ b/src/unstrip.c @@ -315,7 +315,7 @@ make_directories (const char *path) if (dir == NULL) error(EXIT_FAILURE, errno, _("memory exhausted")); - while (mkdir (dir, 0777) < 0 && errno != EEXIST) + while (mkdir (dir, ACCESSPERMS) < 0 && errno != EEXIST) { if (errno == ENOENT) make_directories (dir); @@ -2192,7 +2192,8 @@ DWARF data in '%s' not adjusted for prelinking bias; consider prelink -u"), /* Copy the unstripped file and then modify it. */ int outfd = open (output_file, O_RDWR | O_CREAT, - stripped_ehdr->e_type == ET_REL ? 0666 : 0777); + (stripped_ehdr->e_type == ET_REL + ? DEFFILEMODE : ACCESSPERMS)); if (outfd < 0) error (EXIT_FAILURE, errno, _("cannot open '%s'"), output_file); Elf *outelf = elf_begin (outfd, ELF_C_WRITE, NULL); diff --git a/tests/ChangeLog b/tests/ChangeLog index 57fc4c8e1..f7b78c83f 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,18 @@ +2020-11-01 Érico N. Rolim + Mark Wielaard + + * alldts.c (main): Use DEFFILEMODE for open with O_CREAT. + * arextract.c (main): Likewise. + * ecp.c (main): Likewise for creat. + * elfstrtab.c (check_elf): Use DEFFILEMODE for open with O_CREAT, + remove mode from open calls without O_CREAT. + * emptyfile.c (check_elf): Likewise. + * fillfile.c (check_elf): Likewise. + * vendorelf.c (check_elf): Likewise. + * newdata.c (checkelf): Use DEFFILEMODE for open with O_CREAT. + * update{1,2,3,4}.c (main): Likewise. + * + 2020-10-31 Mark Wielaard * dwfl-proc-attach.c (dlopen): New external function override. diff --git a/tests/alldts.c b/tests/alldts.c index 28b3063c9..3e9f9fe69 100644 --- a/tests/alldts.c +++ b/tests/alldts.c @@ -32,6 +32,7 @@ #include #include #include +#include "system.h" int @@ -68,7 +69,7 @@ main (void) (void) __fsetlocking (stdout, FSETLOCKING_BYCALLER); /* Open the file. */ - int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666); + int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE); if (fd == -1) { printf ("cannot open `%s': %m\n", fname); diff --git a/tests/arextract.c b/tests/arextract.c index 2c4dc7583..936d7f55c 100644 --- a/tests/arextract.c +++ b/tests/arextract.c @@ -95,7 +95,7 @@ Failed to get base address for the archive element: %s\n", } /* Open the output file. */ - outfd = open (argv[3], O_CREAT | O_TRUNC | O_RDWR, 0666); + outfd = open (argv[3], O_CREAT | O_TRUNC | O_RDWR, DEFFILEMODE); if (outfd == -1) { printf ("cannot open output file: %m"); diff --git a/tests/ecp.c b/tests/ecp.c index 1df40a326..44a7bda25 100644 --- a/tests/ecp.c +++ b/tests/ecp.c @@ -43,7 +43,7 @@ main (int argc, char *argv[]) error (EXIT_FAILURE, 0, "problems opening '%s' as ELF file: %s", argv[1], elf_errmsg (-1)); - int outfd = creat (argv[2], 0666); + int outfd = creat (argv[2], DEFFILEMODE); if (outfd == -1) error (EXIT_FAILURE, errno, "cannot open output file '%s'", argv[2]); diff --git a/tests/elfstrtab.c b/tests/elfstrtab.c index c27d6cfb4..5fae37e03 100644 --- a/tests/elfstrtab.c +++ b/tests/elfstrtab.c @@ -26,6 +26,7 @@ #include #include #include +#include "system.h" #include ELFUTILS_HEADER(elf) #include @@ -134,7 +135,7 @@ check_elf (const char *fname, int class, int use_mmap) printf ("\nfname: %s\n", fname); stridx = 0; - int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666); + int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE); if (fd == -1) { printf ("cannot open `%s': %s\n", fname, strerror (errno)); @@ -280,7 +281,7 @@ check_elf (const char *fname, int class, int use_mmap) close (fd); /* Read the ELF from disk now. */ - fd = open (fname, O_RDWR, 0666); + fd = open (fname, O_RDWR); if (fd == -1) { printf ("cannot open `%s' read-only: %s\n", fname, strerror (errno)); @@ -349,7 +350,7 @@ check_elf (const char *fname, int class, int use_mmap) close (fd); // And read it in one last time. - fd = open (fname, O_RDONLY, 0666); + fd = open (fname, O_RDONLY); if (fd == -1) { printf ("cannot open `%s' read-only: %s\n", fname, strerror (errno)); diff --git a/tests/emptyfile.c b/tests/emptyfile.c index 6d086246e..9124c3975 100644 --- a/tests/emptyfile.c +++ b/tests/emptyfile.c @@ -27,6 +27,7 @@ #include #include #include +#include "system.h" #include ELFUTILS_HEADER(elf) #include @@ -67,7 +68,7 @@ check_elf (const char *fname, int class, int use_mmap) printf ("\nfname: %s\n", fname); stridx = 0; // Reset strtab strings index - int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666); + int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE); if (fd == -1) { printf ("cannot open `%s': %s\n", fname, strerror (errno)); @@ -125,7 +126,7 @@ check_elf (const char *fname, int class, int use_mmap) close (fd); /* Reread the ELF from disk now. */ - fd = open (fname, O_RDWR, 0666); + fd = open (fname, O_RDWR); if (fd == -1) { printf ("cannot (re)open `%s': %s\n", fname, strerror (errno)); @@ -208,7 +209,7 @@ check_elf (const char *fname, int class, int use_mmap) close (fd); // And read it in one last time. - fd = open (fname, O_RDONLY, 0666); + fd = open (fname, O_RDONLY); if (fd == -1) { printf ("cannot open `%s' read-only: %s\n", fname, strerror (errno)); diff --git a/tests/fillfile.c b/tests/fillfile.c index 915e249d1..7f6225360 100644 --- a/tests/fillfile.c +++ b/tests/fillfile.c @@ -27,6 +27,7 @@ #include #include #include +#include "system.h" #include ELFUTILS_HEADER(elf) #include @@ -201,7 +202,7 @@ check_elf (const char *fname, int class, int use_mmap) printf ("\nfname: %s\n", fname); stridx = 0; // Reset strtab strings index - int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666); + int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE); if (fd == -1) { printf ("cannot open `%s': %s\n", fname, strerror (errno)); @@ -266,7 +267,7 @@ check_elf (const char *fname, int class, int use_mmap) /* Reread the ELF from disk now. */ printf ("Rereading %s\n", fname); - fd = open (fname, O_RDWR, 0666); + fd = open (fname, O_RDWR); if (fd == -1) { printf ("cannot (re)open `%s': %s\n", fname, strerror (errno)); @@ -347,7 +348,7 @@ check_elf (const char *fname, int class, int use_mmap) // And read it in one last time. printf ("Rereading %s again\n", fname); - fd = open (fname, O_RDONLY, 0666); + fd = open (fname, O_RDONLY); if (fd == -1) { printf ("cannot open `%s' read-only: %s\n", fname, strerror (errno)); diff --git a/tests/newdata.c b/tests/newdata.c index 9af99564e..fcf26acf8 100644 --- a/tests/newdata.c +++ b/tests/newdata.c @@ -26,6 +26,7 @@ #include #include #include +#include "system.h" #include ELFUTILS_HEADER(elf) #include @@ -243,7 +244,7 @@ check_elf (int class, int use_mmap) printf ("\ncheck_elf: %s\n", fname); - int fd = open (fname, O_RDWR|O_CREAT|O_TRUNC, 00666); + int fd = open (fname, O_RDWR|O_CREAT|O_TRUNC, DEFFILEMODE); if (fd == -1) { printf ("cannot create `%s': %s\n", fname, strerror (errno)); diff --git a/tests/update1.c b/tests/update1.c index f4c147537..b7be4e5f8 100644 --- a/tests/update1.c +++ b/tests/update1.c @@ -27,6 +27,7 @@ #include #include #include +#include "system.h" int @@ -38,7 +39,7 @@ main (int argc, char *argv[] __attribute__ ((unused))) Elf32_Ehdr *ehdr; int i; - fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666); + fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE); if (fd == -1) { printf ("cannot open `%s': %s\n", fname, strerror (errno)); diff --git a/tests/update2.c b/tests/update2.c index 5805163d8..714556337 100644 --- a/tests/update2.c +++ b/tests/update2.c @@ -27,6 +27,7 @@ #include #include #include +#include "system.h" int @@ -39,7 +40,7 @@ main (int argc, char *argv[] __attribute__ ((unused))) Elf32_Phdr *phdr; int i; - fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666); + fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE); if (fd == -1) { printf ("cannot open `%s': %s\n", fname, strerror (errno)); diff --git a/tests/update3.c b/tests/update3.c index 7a4224ddd..62f67f74f 100644 --- a/tests/update3.c +++ b/tests/update3.c @@ -27,6 +27,7 @@ #include #include #include +#include "system.h" #include ELFUTILS_HEADER(dwelf) @@ -46,7 +47,7 @@ main (int argc, char *argv[] __attribute__ ((unused))) Dwelf_Strent *shstrtabse; int i; - fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666); + fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE); if (fd == -1) { printf ("cannot open `%s': %s\n", fname, strerror (errno)); diff --git a/tests/update4.c b/tests/update4.c index a9bd4bf96..a703b592b 100644 --- a/tests/update4.c +++ b/tests/update4.c @@ -27,6 +27,7 @@ #include #include #include +#include "system.h" #include ELFUTILS_HEADER(dwelf) @@ -50,7 +51,7 @@ main (int argc, char *argv[] __attribute__ ((unused))) Dwelf_Strent *shstrtabse; int i; - fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666); + fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE); if (fd == -1) { printf ("cannot open `%s': %s\n", fname, strerror (errno)); diff --git a/tests/vendorelf.c b/tests/vendorelf.c index bc13cce31..8ce1e5ece 100644 --- a/tests/vendorelf.c +++ b/tests/vendorelf.c @@ -27,6 +27,7 @@ #include #include #include +#include "system.h" #include ELFUTILS_HEADER(elf) #include @@ -36,7 +37,7 @@ check_elf (const char *fname, int class, int use_mmap) { printf ("\nfname: %s\n", fname); - int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666); + int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE); if (fd == -1) { printf ("cannot open `%s': %s\n", fname, strerror (errno)); @@ -124,7 +125,7 @@ check_elf (const char *fname, int class, int use_mmap) close (fd); /* Reread the ELF from disk now. */ - fd = open (fname, O_RDONLY, 0666); + fd = open (fname, O_RDONLY); if (fd == -1) { printf ("cannot open `%s' read-only: %s\n", fname, strerror (errno));