From 2496616b0a8d1c80cd1416b73a4847b59b9f969a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Tue, 6 Oct 2020 02:36:47 +0200 Subject: avoid using strok - eliminates use of hidden global variable function old new delta udhcp_str2optset 616 650 +34 setpriv_main 950 975 +25 switch_root_main 688 706 +18 parse 958 970 +12 getopt_main 622 628 +6 parse_resolvconf 302 306 +4 mpstat_main 1139 1142 +3 static.p 4 - -4 cdcmd 717 702 -15 strtok 148 - -148 ------------------------------------------------------------------------------ (add/remove: 0/3 grow/shrink: 7/1 up/down: 102/-167) Total: -65 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- libbb/kernel_version.c | 20 +++++++++++--------- libbb/update_passwd.c | 15 +++++++++------ 2 files changed, 20 insertions(+), 15 deletions(-) (limited to 'libbb') diff --git a/libbb/kernel_version.c b/libbb/kernel_version.c index 7769a091b..6bb32ce5f 100644 --- a/libbb/kernel_version.c +++ b/libbb/kernel_version.c @@ -19,15 +19,17 @@ int FAST_FUNC get_linux_version_code(void) { struct utsname name; char *t; - int i, r; + int r; uname(&name); /* never fails */ - t = name.release; - r = 0; - for (i = 0; i < 3; i++) { - t = strtok(t, "."); - r = r * 256 + (t ? atoi(t) : 0); - t = NULL; - } - return r; + t = name.release - 1; + r = 1; + do { + r <<= 8; + if (t) { + r += atoi(++t); + t = strchr(t, '.'); + } + } while (r < 0x1000000); + return r - 0x1000000; } diff --git a/libbb/update_passwd.c b/libbb/update_passwd.c index c605c4c64..7b67f30cd 100644 --- a/libbb/update_passwd.c +++ b/libbb/update_passwd.c @@ -18,17 +18,20 @@ #if ENABLE_SELINUX static void check_selinux_update_passwd(const char *username) { - security_context_t context; - char *seuser; + security_context_t seuser; + char *p; if (getuid() != (uid_t)0 || is_selinux_enabled() == 0) return; /* No need to check */ - if (getprevcon_raw(&context) < 0) + if (getprevcon_raw(&seuser) < 0) bb_simple_perror_msg_and_die("getprevcon failed"); - seuser = strtok(context, ":"); - if (!seuser) - bb_error_msg_and_die("invalid context '%s'", context); + + p = strchr(seuser, ':'); + if (!p) + bb_error_msg_and_die("invalid context '%s'", seuser); + *p = '\0'; + if (strcmp(seuser, username) != 0) { security_class_t tclass; access_vector_t av; -- cgit v1.2.3-55-g6feb