diff options
author | Ron Yorston <rmy@pobox.com> | 2021-09-17 10:16:06 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-09-17 16:51:01 +0200 |
commit | 3a65435eaa845d45bbea176701726f27a88e8498 (patch) | |
tree | b2a3e7df81fffa718389ebad4fe7c90187f21198 | |
parent | 59ac467dc6429a48522ef7fbe40fcd819563e49a (diff) | |
download | busybox-w32-3a65435eaa845d45bbea176701726f27a88e8498.tar.gz busybox-w32-3a65435eaa845d45bbea176701726f27a88e8498.tar.bz2 busybox-w32-3a65435eaa845d45bbea176701726f27a88e8498.zip |
libbb: ensure mode_string is NUL terminated
If the mode_string array is no longer static we can't rely on
it being NUL terminated.
function old new delta
bb_mode_string 115 118 +3
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/mode_string.c | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/libbb/mode_string.c b/libbb/mode_string.c index 2b829016f..8c12b4684 100644 --- a/libbb/mode_string.c +++ b/libbb/mode_string.c | |||
@@ -66,10 +66,7 @@ char* FAST_FUNC bb_mode_string(char buf[12], mode_t mode) | |||
66 | i += 4; | 66 | i += 4; |
67 | } while (i < 12); | 67 | } while (i < 12); |
68 | 68 | ||
69 | /* Note: We don't bother with nul termination because bss initialization | 69 | buf[10] = '\0'; |
70 | * should have taken care of that for us. If the user scribbled in buf | ||
71 | * memory, they deserve whatever happens. But we'll at least assert. */ | ||
72 | assert(buf[10] == 0); | ||
73 | 70 | ||
74 | return buf; | 71 | return buf; |
75 | } | 72 | } |
@@ -79,7 +76,7 @@ char* FAST_FUNC bb_mode_string(char buf[12], mode_t mode) | |||
79 | /* The previous version used "0pcCd?bB-?l?s???". However, the '0', 'C', | 76 | /* The previous version used "0pcCd?bB-?l?s???". However, the '0', 'C', |
80 | * and 'B' types don't appear to be available on linux. So I removed them. */ | 77 | * and 'B' types don't appear to be available on linux. So I removed them. */ |
81 | static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???"; | 78 | static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???"; |
82 | /********************************** 0123456789abcdef */ | 79 | /***************************************** 0123456789abcdef */ |
83 | static const char mode_chars[7] ALIGN1 = "rwxSTst"; | 80 | static const char mode_chars[7] ALIGN1 = "rwxSTst"; |
84 | 81 | ||
85 | char* FAST_FUNC bb_mode_string(char buf[12], mode_t mode) | 82 | char* FAST_FUNC bb_mode_string(char buf[12], mode_t mode) |
@@ -107,10 +104,7 @@ char* FAST_FUNC bb_mode_string(char buf[12], mode_t mode) | |||
107 | } | 104 | } |
108 | } while (i < 3); | 105 | } while (i < 3); |
109 | 106 | ||
110 | /* Note: We don't bother with nul termination because bss initialization | 107 | buf[10] = '\0'; |
111 | * should have taken care of that for us. If the user scribbled in buf | ||
112 | * memory, they deserve whatever happens. But we'll at least assert. */ | ||
113 | assert(buf[10] == 0); | ||
114 | 108 | ||
115 | return buf; | 109 | return buf; |
116 | } | 110 | } |