clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -O3 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name machine-id-util-linux.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/__w/nvme-cli/nvme-cli/.build-ci -fcoverage-compilation-dir=/__w/nvme-cli/nvme-cli/.build-ci -resource-dir /usr/bin/../lib/clang/22 -include /__w/nvme-cli/nvme-cli/.build-ci/nvme-config.h -I shared/libshared.a.p -I shared -I ../shared -I ccan -I ../ccan -D _FILE_OFFSET_BITS=64 -D _GNU_SOURCE -U NDEBUG -internal-isystem /usr/bin/../lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=gnu11 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-opt-analyze-headers -analyzer-output=html -faddrsig -fdwarf2-cfi-asm -o /__w/nvme-cli/nvme-cli/.build-ci/scan-results/2026-09-23-073103-589-1 -x c ../shared/machine-id-util-linux.c
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | #include <errno.h> |
| 10 | #include <stdio.h> |
| 11 | #include <string.h> |
| 12 | |
| 13 | #include "cleanup-util.h" |
| 14 | #include "machine-id-util.h" |
| 15 | #include "sha256-util.h" |
| 16 | |
| 17 | #define MACHINE_ID_LEN_STRING 32 |
| 18 | |
| 19 | static int parse_hex_digit(char c) |
| 20 | { |
| 21 | if (c >= '0' && c <= '9') |
| 22 | return c - '0'; |
| 23 | if (c >= 'a' && c <= 'f') |
| 24 | return c - 'a' + 10; |
| 25 | if (c >= 'A' && c <= 'F') |
| 26 | return c - 'A' + 10; |
| 27 | |
| 28 | return -EINVAL; |
| 29 | } |
| 30 | |
| 31 | static int read_machine_id(const char *path, unsigned char id[SHR_UUID_LEN]) |
| 32 | { |
| 33 | char buf[MACHINE_ID_LEN_STRING + 2] = {}; |
| 34 | __cleanup_file FILE *f = NULL; |
| 35 | bool all_zero = true; |
| 36 | size_t len, i; |
| 37 | |
| 38 | f = fopen(path, "re"); |
| |
| 7 | | Assuming that 'fopen' is successful | |
|
| 39 | if (!f) |
| |
| 40 | return -errno; |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | len = fread(buf, 1, sizeof(buf) - 1, f); |
| 9 | | Opened stream never closed. Potential resource leak |
|
| 47 | if (len < MACHINE_ID_LEN_STRING) |
| 48 | return -EINVAL; |
| 49 | |
| 50 | for (i = 0; i < SHR_UUID_LEN; i++) { |
| 51 | int hi = parse_hex_digit(buf[i * 2]); |
| 52 | int lo = parse_hex_digit(buf[i * 2 + 1]); |
| 53 | |
| 54 | if (hi < 0 || lo < 0) |
| 55 | return -EINVAL; |
| 56 | |
| 57 | id[i] = (hi << 4) | lo; |
| 58 | if (id[i]) |
| 59 | all_zero = false; |
| 60 | } |
| 61 | |
| 62 | return all_zero ? -EINVAL : 0; |
| 63 | } |
| 64 | |
| 65 | int shr_machine_id_app_specific(const char *path, |
| 66 | const unsigned char app_id[SHR_UUID_LEN], |
| 67 | unsigned char out[SHR_UUID_LEN]) |
| 68 | { |
| 69 | unsigned char hmac[SHR_SHA256_DIGEST_SIZE]; |
| 70 | unsigned char id[SHR_UUID_LEN]; |
| 71 | int ret; |
| 72 | |
| 73 | if (!path || !app_id || !out) |
| 1 | Assuming 'path' is non-null | |
|
| 2 | | Assuming 'app_id' is non-null | |
|
| 3 | | Assuming 'out' is non-null | |
|
| |
| 74 | return -EINVAL; |
| 75 | |
| 76 | ret = read_machine_id(path, id); |
| 5 | | Calling 'read_machine_id' | |
|
| 77 | if (ret) |
| 78 | return ret; |
| 79 | |
| 80 | shr_hmac_sha256_raw(id, sizeof(id), app_id, SHR_UUID_LEN, hmac); |
| 81 | |
| 82 | |
| 83 | memcpy(out, hmac, SHR_UUID_LEN); |
| 84 | |
| 85 | |
| 86 | out[6] = (out[6] & 0x0f) | 0x40; |
| 87 | out[8] = (out[8] & 0x3f) | 0x80; |
| 88 | |
| 89 | return 0; |
| 90 | } |