diff options
author | Jorgen Lundman <[email protected]> | 2020-06-08 03:42:12 +0900 |
---|---|---|
committer | GitHub <[email protected]> | 2020-06-07 11:42:12 -0700 |
commit | c9e319faae9677aa0dddfbf9973b9e8fc3feb06c (patch) | |
tree | 3d6677913e5f26d91b7f35bcb62b9b354287db61 /module/lua | |
parent | 60265072e02049be708f74cf0865eba2434a2d85 (diff) |
Replace sprintf()->snprintf() and strcpy()->strlcpy()
The strcpy() and sprintf() functions are deprecated on some platforms.
Care is needed to ensure correct size is used. If some platforms
miss snprintf, we can add a #define to sprintf, likewise strlcpy().
The biggest change is adding a size parameter to zfs_id_to_fuidstr().
The various *_impl_get() functions are only used on linux and have
not yet been updated.
Reviewed by: Sean Eric Fagan <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Jorgen Lundman <[email protected]>
Closes #10400
Diffstat (limited to 'module/lua')
-rw-r--r-- | module/lua/lstrlib.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/module/lua/lstrlib.c b/module/lua/lstrlib.c index 49ba70faf..12027757b 100644 --- a/module/lua/lstrlib.c +++ b/module/lua/lstrlib.c @@ -853,9 +853,9 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { else if (*s == '\0' || iscntrl(uchar(*s))) { char buff[10]; if (!isdigit(uchar(*(s+1)))) - sprintf(buff, "\\%d", (int)uchar(*s)); + snprintf(buff, sizeof(buff), "\\%d", (int)uchar(*s)); else - sprintf(buff, "\\%03d", (int)uchar(*s)); + snprintf(buff, sizeof(buff), "\\%03d", (int)uchar(*s)); luaL_addstring(b, buff); } else @@ -890,11 +890,11 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { /* ** add length modifier into formats */ -static void addlenmod (char *form, const char *lenmod) { +static void addlenmod (char *form, const char *lenmod, size_t size) { size_t l = strlen(form); size_t lm = strlen(lenmod); char spec = form[l - 1]; - strcpy(form + l - 1, lenmod); + strlcpy(form + l - 1, lenmod, size - (l - 1)); form[l + lm - 1] = spec; form[l + lm] = '\0'; } @@ -931,7 +931,7 @@ static int str_format (lua_State *L) { lua_Number diff = n - (lua_Number)ni; luaL_argcheck(L, -1 < diff && diff < 1, arg, "not a number in proper range"); - addlenmod(form, LUA_INTFRMLEN); + addlenmod(form, LUA_INTFRMLEN, MAX_FORMAT); nb = str_sprintf(buff, form, ni); break; } @@ -941,7 +941,7 @@ static int str_format (lua_State *L) { lua_Number diff = n - (lua_Number)ni; luaL_argcheck(L, -1 < diff && diff < 1, arg, "not a non-negative number in proper range"); - addlenmod(form, LUA_INTFRMLEN); + addlenmod(form, LUA_INTFRMLEN, MAX_FORMAT); nb = str_sprintf(buff, form, ni); break; } @@ -951,7 +951,7 @@ static int str_format (lua_State *L) { case 'a': case 'A': #endif case 'g': case 'G': { - addlenmod(form, LUA_FLTFRMLEN); + addlenmod(form, LUA_FLTFRMLEN, MAX_FORMAT); nb = str_sprintf(buff, form, (LUA_FLTFRM_T)luaL_checknumber(L, arg)); break; } |