diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2022-04-27 17:20:43 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2022-04-27 17:20:43 +0200 |
commit | 401356511c5de3b5a88fdd3ac4977e19b82babf5 (patch) | |
tree | fe73944c41d4cc00482bb3e09f300f3d3eb0ec01 | |
parent | 6da9947358276d989e002c3c5c8ff2e33676ae21 (diff) | |
download | busybox-w32-401356511c5de3b5a88fdd3ac4977e19b82babf5.tar.gz busybox-w32-401356511c5de3b5a88fdd3ac4977e19b82babf5.tar.bz2 busybox-w32-401356511c5de3b5a88fdd3ac4977e19b82babf5.zip |
seedrng: remove unnecessary zero-filling of local variables
function old new delta
seedrng_main 1292 1273 -19
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | util-linux/seedrng.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/util-linux/seedrng.c b/util-linux/seedrng.c index c762e9ecd..dd082ea90 100644 --- a/util-linux/seedrng.c +++ b/util-linux/seedrng.c | |||
@@ -54,20 +54,23 @@ | |||
54 | #define CREDITABLE_SEED_NAME "seed.credit" | 54 | #define CREDITABLE_SEED_NAME "seed.credit" |
55 | #define NON_CREDITABLE_SEED_NAME "seed.no-credit" | 55 | #define NON_CREDITABLE_SEED_NAME "seed.no-credit" |
56 | 56 | ||
57 | enum seedrng_lengths { | 57 | enum { |
58 | MIN_SEED_LEN = SHA256_OUTSIZE, | 58 | MIN_SEED_LEN = SHA256_OUTSIZE, |
59 | MAX_SEED_LEN = 512 | 59 | MAX_SEED_LEN = 512 |
60 | }; | 60 | }; |
61 | 61 | ||
62 | static size_t determine_optimal_seed_len(void) | 62 | static size_t determine_optimal_seed_len(void) |
63 | { | 63 | { |
64 | char poolsize_str[11] = { 0 }; | 64 | char poolsize_str[12]; |
65 | unsigned long poolsize; | 65 | unsigned poolsize; |
66 | int n; | ||
66 | 67 | ||
67 | if (open_read_close("/proc/sys/kernel/random/poolsize", poolsize_str, sizeof(poolsize_str) - 1) < 0) { | 68 | n = open_read_close("/proc/sys/kernel/random/poolsize", poolsize_str, sizeof(poolsize_str) - 1); |
69 | if (n < 0) { | ||
68 | bb_perror_msg("unable to determine pool size, assuming %u bits", MIN_SEED_LEN * 8); | 70 | bb_perror_msg("unable to determine pool size, assuming %u bits", MIN_SEED_LEN * 8); |
69 | return MIN_SEED_LEN; | 71 | return MIN_SEED_LEN; |
70 | } | 72 | } |
73 | poolsize_str[n] = '\0'; | ||
71 | poolsize = (bb_strtoul(poolsize_str, NULL, 10) + 7) / 8; | 74 | poolsize = (bb_strtoul(poolsize_str, NULL, 10) + 7) / 8; |
72 | return MAX(MIN(poolsize, MAX_SEED_LEN), MIN_SEED_LEN); | 75 | return MAX(MIN(poolsize, MAX_SEED_LEN), MIN_SEED_LEN); |
73 | } | 76 | } |
@@ -159,7 +162,7 @@ static int seed_from_file_if_exists(const char *filename, int dfd, bool credit, | |||
159 | int seedrng_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE; | 162 | int seedrng_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE; |
160 | int seedrng_main(int argc UNUSED_PARAM, char *argv[]) | 163 | int seedrng_main(int argc UNUSED_PARAM, char *argv[]) |
161 | { | 164 | { |
162 | const char *seed_dir = DEFAULT_SEED_DIR, *creditable_seed, *non_creditable_seed; | 165 | const char *seed_dir, *creditable_seed, *non_creditable_seed; |
163 | int fd, dfd, program_ret = 0; | 166 | int fd, dfd, program_ret = 0; |
164 | uint8_t new_seed[MAX_SEED_LEN]; | 167 | uint8_t new_seed[MAX_SEED_LEN]; |
165 | size_t new_seed_len; | 168 | size_t new_seed_len; |
@@ -178,10 +181,8 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[]) | |||
178 | ; | 181 | ; |
179 | #endif | 182 | #endif |
180 | 183 | ||
184 | seed_dir = DEFAULT_SEED_DIR; | ||
181 | skip_credit = getopt32long(argv, "d:n", longopts, &seed_dir) & OPT_n; | 185 | skip_credit = getopt32long(argv, "d:n", longopts, &seed_dir) & OPT_n; |
182 | creditable_seed = concat_path_file(seed_dir, CREDITABLE_SEED_NAME); | ||
183 | non_creditable_seed = concat_path_file(seed_dir, NON_CREDITABLE_SEED_NAME); | ||
184 | |||
185 | umask(0077); | 186 | umask(0077); |
186 | if (getuid()) | 187 | if (getuid()) |
187 | bb_simple_error_msg_and_die(bb_msg_you_must_be_root); | 188 | bb_simple_error_msg_and_die(bb_msg_you_must_be_root); |
@@ -200,6 +201,8 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[]) | |||
200 | clock_gettime(CLOCK_BOOTTIME, ×tamp); | 201 | clock_gettime(CLOCK_BOOTTIME, ×tamp); |
201 | sha256_hash(&hash, ×tamp, sizeof(timestamp)); | 202 | sha256_hash(&hash, ×tamp, sizeof(timestamp)); |
202 | 203 | ||
204 | creditable_seed = concat_path_file(seed_dir, CREDITABLE_SEED_NAME); | ||
205 | non_creditable_seed = concat_path_file(seed_dir, NON_CREDITABLE_SEED_NAME); | ||
203 | for (int i = 1; i < 3; ++i) { | 206 | for (int i = 1; i < 3; ++i) { |
204 | if (seed_from_file_if_exists(i == 1 ? non_creditable_seed : creditable_seed, | 207 | if (seed_from_file_if_exists(i == 1 ? non_creditable_seed : creditable_seed, |
205 | dfd, i == 1 ? false : !skip_credit, &hash) < 0) | 208 | dfd, i == 1 ? false : !skip_credit, &hash) < 0) |