diff options
| author | Nick Clifton <nickc@redhat.com> | 2026-08-11 11:15:17 +0100 |
|---|---|---|
| committer | Nick Clifton <nickc@redhat.com> | 2026-08-11 11:15:17 +0100 |
| commit | 2a01c2ef59ad01acdf64a3d1dcb424a1deca8eb8 (patch) | |
| tree | 612e7cbf67ae3c0dd40da4831308e1cc91fdd08a | |
| parent | Fix a few code readability issues reported by clang-tidy (diff) | |
| -rw-r--r-- | annocheck/annocheck.c | 95 | ||||
| -rwxr-xr-x | configure | 2 | ||||
| -rw-r--r-- | configure.ac | 2 | ||||
| -rw-r--r-- | meson.build | 2 |
4 files changed, 66 insertions, 35 deletions
diff --git a/annocheck/annocheck.c b/annocheck/annocheck.c index 2086495..02faba2 100644 --- a/annocheck/annocheck.c +++ b/annocheck/annocheck.c | |||
| @@ -628,32 +628,45 @@ itoa (uint lev) | |||
| 628 | static bool | 628 | static bool |
| 629 | extract_rpm_into_dir (const char * rpm, const char * dirname) | 629 | extract_rpm_into_dir (const char * rpm, const char * dirname) |
| 630 | { | 630 | { |
| 631 | /* These should never trigger, but better safe than sorry. */ | ||
| 632 | if (! is_safe_path (dirname)) | ||
| 633 | return afinfo (WARN, dirname, "Suspicious characeter(s) in directory path"); | ||
| 634 | if (! is_safe_path (rpm)) | ||
| 635 | return afinfo (WARN, rpm, "Suspicious characeter(s) in rpm name"); | ||
| 636 | |||
| 637 | /* If filename is a relative path, convert it to an absolute one so | ||
| 638 | that it can be found once we change into the temporary directory. */ | ||
| 639 | |||
| 631 | char * fname; | 640 | char * fname; |
| 632 | char * cwd = getcwd (NULL, 0); | ||
| 633 | 641 | ||
| 634 | /* If filename is a relative path, convert it to an absolute one | ||
| 635 | so that it can be found once we change into the temporary directory. */ | ||
| 636 | if (rpm[0] != '/') | 642 | if (rpm[0] != '/') |
| 637 | fname = concat (cwd, "/", rpm, NULL); | 643 | { |
| 644 | char * cwd = getcwd (NULL, 0); | ||
| 645 | if (cwd == NULL) | ||
| 646 | return einfo (SYS_ERROR, "Unable to retrieve the current working directory"); | ||
| 647 | |||
| 648 | fname = concat (cwd, "/", rpm, NULL); | ||
| 649 | free (cwd); | ||
| 650 | } | ||
| 638 | else | 651 | else |
| 639 | /* This is just so that we can safely call free(fname) at the end. */ | 652 | /* This is just so that we can safely call free(fname) at the end. */ |
| 640 | fname = concat (rpm, NULL); | 653 | fname = concat (rpm, NULL); |
| 641 | 654 | ||
| 642 | if (access (rpm, F_OK) == -1) | 655 | /* This should never happen, but better safe than sorry. */ |
| 656 | if (! is_safe_path (fname)) | ||
| 643 | { | 657 | { |
| 644 | afinfo (SYS_ERROR, fname, "Error reading rpm file"); | 658 | afinfo (WARN, fname, "Suspicious characeter(s) in computed file name path"); |
| 645 | free (cwd); | ||
| 646 | free (fname); | 659 | free (fname); |
| 647 | return false; | 660 | return false; |
| 648 | } | 661 | } |
| 649 | 662 | ||
| 650 | /* This should never happen, but better safe than sorry. */ | 663 | if (access (fname, F_OK) == -1) |
| 651 | if (! is_safe_path (dirname) || ! is_safe_path (fname)) | ||
| 652 | { | 664 | { |
| 665 | afinfo (SYS_ERROR, fname, "Unable to access rpm file"); | ||
| 653 | free (fname); | 666 | free (fname); |
| 654 | return afinfo (WARN, NULL, "Suspicious characeter(s) in paths"); | 667 | return false; |
| 655 | } | 668 | } |
| 656 | 669 | ||
| 657 | char * command; | 670 | char * command; |
| 658 | command = concat (/* Change into the temporary directory. */ | 671 | command = concat (/* Change into the temporary directory. */ |
| 659 | "cd ", dirname, | 672 | "cd ", dirname, |
| @@ -665,22 +678,18 @@ extract_rpm_into_dir (const char * rpm, const char * dirname) | |||
| 665 | " && cd ..", | 678 | " && cd ..", |
| 666 | NULL); | 679 | NULL); |
| 667 | 680 | ||
| 681 | free (fname); | ||
| 682 | |||
| 668 | afinfo (VERBOSE2, NULL, "Running rpm extractor command sequence: %s", command); | 683 | afinfo (VERBOSE2, NULL, "Running rpm extractor command sequence: %s", command); |
| 669 | fflush (stdin); | 684 | fflush (stdin); |
| 670 | 685 | ||
| 671 | if (system (command)) | 686 | if (system (command)) |
| 672 | { | 687 | { |
| 673 | afinfo (WARN, rpm, "Failed to extract rpm file"); | ||
| 674 | free (command); | 688 | free (command); |
| 675 | free (cwd); | 689 | return afinfo (WARN, rpm, "Failed to extract rpm file"); |
| 676 | free (fname); | ||
| 677 | return false; | ||
| 678 | } | 690 | } |
| 679 | 691 | ||
| 680 | free (command); | 692 | free (command); |
| 681 | free (cwd); | ||
| 682 | free (fname); | ||
| 683 | |||
| 684 | return afinfo (VERBOSE2, rpm, "extracted into %s", dirname); | 693 | return afinfo (VERBOSE2, rpm, "extracted into %s", dirname); |
| 685 | } | 694 | } |
| 686 | 695 | ||
| @@ -730,10 +739,18 @@ extract_debug_rpm_files (void) | |||
| 730 | using_tmpdir = true; | 739 | using_tmpdir = true; |
| 731 | 740 | ||
| 732 | char * cwd = getcwd (NULL, 0); | 741 | char * cwd = getcwd (NULL, 0); |
| 733 | const char * tmp = concat ("--debug-dir=", cwd, "/", tmp_debug_dir, NULL); | 742 | if (cwd == NULL) |
| 743 | { | ||
| 744 | einfo (SYS_ERROR, "Unable to retrieve the current working directory"); | ||
| 745 | free ((void *) tmp_debug_dir); | ||
| 746 | return NULL; | ||
| 747 | } | ||
| 748 | |||
| 749 | #define DEBUG_DIR_OPTION "--debug-dir=" | ||
| 750 | const char * tmp = concat (DEBUG_DIR_OPTION, cwd, "/", tmp_debug_dir, NULL); | ||
| 734 | 751 | ||
| 735 | /* This should never happen, but let's be paranoid. */ | 752 | /* This should never happen, but let's be paranoid. */ |
| 736 | if (! is_safe_path (tmp)) | 753 | if (! is_safe_path (tmp + strlen (DEBUG_DIR_OPTION))) |
| 737 | { | 754 | { |
| 738 | afinfo (ERROR, tmp, "Path to temporary debug dir contains suspicious characters"); | 755 | afinfo (ERROR, tmp, "Path to temporary debug dir contains suspicious characters"); |
| 739 | free ((void *) tmp_debug_dir); | 756 | free ((void *) tmp_debug_dir); |
| @@ -1923,10 +1940,12 @@ process_ar (const char * filename, int fd, Elf * elf) | |||
| 1923 | Returns false otherwise. */ | 1940 | Returns false otherwise. */ |
| 1924 | 1941 | ||
| 1925 | static bool | 1942 | static bool |
| 1926 | unpack_and_process (const char * filename, const char * tmp_dir, | 1943 | unpack_and_process (const char * filename, |
| 1927 | const char * extraction_tool1, const char * extraction_tool2) | 1944 | const char * tmp_dir, |
| 1945 | const char * extraction_tool1, | ||
| 1946 | const char * extraction_tool2) | ||
| 1928 | { | 1947 | { |
| 1929 | char * dirname; | 1948 | char * dirname = NULL; |
| 1930 | 1949 | ||
| 1931 | /* Paranoia. */ | 1950 | /* Paranoia. */ |
| 1932 | if (filename == NULL || filename[0] == 0 | 1951 | if (filename == NULL || filename[0] == 0 |
| @@ -1934,11 +1953,10 @@ unpack_and_process (const char * filename, const char * tmp_dir, | |||
| 1934 | || extraction_tool1 == NULL || extraction_tool1[0] == 0) | 1953 | || extraction_tool1 == NULL || extraction_tool1[0] == 0) |
| 1935 | /* It is OK for extraction_tool2 to be NULL. */ | 1954 | /* It is OK for extraction_tool2 to be NULL. */ |
| 1936 | return afinfo (WARN, filename, "unpack_and_process called with invalid arguments"); | 1955 | return afinfo (WARN, filename, "unpack_and_process called with invalid arguments"); |
| 1937 | 1956 | ||
| 1938 | if (asprintf (& dirname, "%s%s", tmp_dir, "XXXXXX") < 8) | 1957 | if (asprintf (& dirname, "%s%s", tmp_dir, "XXXXXX") < 8) |
| 1939 | { | 1958 | { |
| 1940 | if (dirname != NULL) | 1959 | free (dirname); |
| 1941 | free (dirname); | ||
| 1942 | return afinfo (WARN, filename, "unable to allocate temporary directory name"); | 1960 | return afinfo (WARN, filename, "unable to allocate temporary directory name"); |
| 1943 | } | 1961 | } |
| 1944 | 1962 | ||
| @@ -1955,6 +1973,11 @@ unpack_and_process (const char * filename, const char * tmp_dir, | |||
| 1955 | char * pname; | 1973 | char * pname; |
| 1956 | char * command; | 1974 | char * command; |
| 1957 | char * cwd = getcwd (NULL, 0); | 1975 | char * cwd = getcwd (NULL, 0); |
| 1976 | if (cwd == NULL) | ||
| 1977 | { | ||
| 1978 | free (dirname); | ||
| 1979 | return afinfo (SYS_ERROR, NULL, "Unable to retrieve the current working directory"); | ||
| 1980 | } | ||
| 1958 | 1981 | ||
| 1959 | /* If necessary convert FILENAME into an absolute path. */ | 1982 | /* If necessary convert FILENAME into an absolute path. */ |
| 1960 | if (filename[0] != '/') | 1983 | if (filename[0] != '/') |
| @@ -2638,6 +2661,12 @@ create_tmpdir (void) | |||
| 2638 | } | 2661 | } |
| 2639 | 2662 | ||
| 2640 | const char * cwd = getcwd (NULL, 0); | 2663 | const char * cwd = getcwd (NULL, 0); |
| 2664 | if (cwd == NULL) | ||
| 2665 | { | ||
| 2666 | afinfo (SYS_ERROR, NULL, "Unable to retrieve the current working directory"); | ||
| 2667 | return NULL; | ||
| 2668 | } | ||
| 2669 | |||
| 2641 | tmpdir = concat (cwd, "/", tmpdir, NULL); | 2670 | tmpdir = concat (cwd, "/", tmpdir, NULL); |
| 2642 | free ((void *) cwd); | 2671 | free ((void *) cwd); |
| 2643 | 2672 | ||
| @@ -2881,15 +2910,16 @@ save_file_arg (const char * parameter, file_option updating) | |||
| 2881 | const char * home = getenv ("HOME"); | 2910 | const char * home = getenv ("HOME"); |
| 2882 | 2911 | ||
| 2883 | if (home == NULL) | 2912 | if (home == NULL) |
| 2884 | { | 2913 | return afinfo (SYS_WARN, NULL, "HOME environment variable is not set, unable to expand ~ in path"); |
| 2885 | einfo (WARN, "HOME environment variable is not set, unable to expand ~ in path"); | ||
| 2886 | return false; | ||
| 2887 | } | ||
| 2888 | cwd = concat (home, NULL); | 2914 | cwd = concat (home, NULL); |
| 2889 | parameter += 2; | 2915 | parameter += 2; |
| 2890 | } | 2916 | } |
| 2891 | else | 2917 | else |
| 2892 | cwd = getcwd (NULL, 0); | 2918 | { |
| 2919 | cwd = getcwd (NULL, 0); | ||
| 2920 | if (cwd == NULL) | ||
| 2921 | return afinfo (SYS_WARN, NULL, "Unable to retrieve current working directory"); | ||
| 2922 | } | ||
| 2893 | 2923 | ||
| 2894 | parameter = concat (cwd, "/", parameter, NULL); | 2924 | parameter = concat (cwd, "/", parameter, NULL); |
| 2895 | 2925 | ||
| @@ -3258,7 +3288,8 @@ process_command_line (uint argc, const char * argv[]) | |||
| 3258 | afinfo (VERBOSE2, test, "Possible associated debuginfo rpm"); | 3288 | afinfo (VERBOSE2, test, "Possible associated debuginfo rpm"); |
| 3259 | 3289 | ||
| 3260 | if (is_safe_path (test) | 3290 | if (is_safe_path (test) |
| 3261 | && stat (test, & statbuf) == 0 && S_ISREG (statbuf.st_mode)) | 3291 | && stat (test, & statbuf) == 0 |
| 3292 | && S_ISREG (statbuf.st_mode)) | ||
| 3262 | { | 3293 | { |
| 3263 | if (save_file_arg (test, Debug_rpm)) | 3294 | if (save_file_arg (test, Debug_rpm)) |
| 3264 | afinfo (WARN, test, "Unable to save in debug rpm list"); | 3295 | afinfo (WARN, test, "Unable to save in debug rpm list"); |
| @@ -2703,7 +2703,7 @@ ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. | |||
| 2703 | # also update VERSION in the PROJECT section of meson.build. | 2703 | # also update VERSION in the PROJECT section of meson.build. |
| 2704 | # Also note that the number after the decimal point is limited | 2704 | # Also note that the number after the decimal point is limited |
| 2705 | # to two digits due to various assumptions in the code. | 2705 | # to two digits due to various assumptions in the code. |
| 2706 | ANNOBIN_VERSION=13.28 | 2706 | ANNOBIN_VERSION=13.29 |
| 2707 | 2707 | ||
| 2708 | 2708 | ||
| 2709 | # Make sure we can run config.sub. | 2709 | # Make sure we can run config.sub. |
diff --git a/configure.ac b/configure.ac index 1f1a340..22f6323 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -12,7 +12,7 @@ AC_CONFIG_SRCDIR([annobin-global.h.in]) | |||
| 12 | # also update VERSION in the PROJECT section of meson.build. | 12 | # also update VERSION in the PROJECT section of meson.build. |
| 13 | # Also note that the number after the decimal point is limited | 13 | # Also note that the number after the decimal point is limited |
| 14 | # to two digits due to various assumptions in the code. | 14 | # to two digits due to various assumptions in the code. |
| 15 | ANNOBIN_VERSION=13.28 | 15 | ANNOBIN_VERSION=13.29 |
| 16 | AC_SUBST(ANNOBIN_VERSION) | 16 | AC_SUBST(ANNOBIN_VERSION) |
| 17 | 17 | ||
| 18 | AC_CANONICAL_SYSTEM | 18 | AC_CANONICAL_SYSTEM |
diff --git a/meson.build b/meson.build index efe9e90..62b1e45 100644 --- a/meson.build +++ b/meson.build | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | project( | 7 | project( |
| 8 | 'annobin', | 8 | 'annobin', |
| 9 | ['c', 'cpp'], | 9 | ['c', 'cpp'], |
| 10 | version: '13.28', | 10 | version: '13.29', |
| 11 | meson_version: '>=0.59' | 11 | meson_version: '>=0.59' |
| 12 | ) | 12 | ) |
| 13 | 13 | ||
