From fe4599fb14f14b99a9713bad09502be068a614bf Mon Sep 17 00:00:00 2001 From: Doridian Date: Fri, 10 Jun 2022 12:29:18 -0700 Subject: [PATCH] Use snprintf in client/deps --- .../deps/hardnested/hardnested_bruteforce.c | 6 +-- client/deps/hardnested/hardnested_tables.c | 2 +- client/deps/liblua/lobject.c | 2 +- client/deps/liblua/lstrlib.c | 14 +++---- client/deps/liblua/luaconf.h | 2 +- client/deps/liblua/lvm.c | 2 +- client/deps/reveng/model.c | 42 +++++++++---------- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/client/deps/hardnested/hardnested_bruteforce.c b/client/deps/hardnested/hardnested_bruteforce.c index 11715609f..b5b36595c 100644 --- a/client/deps/hardnested/hardnested_bruteforce.c +++ b/client/deps/hardnested/hardnested_bruteforce.c @@ -173,8 +173,8 @@ crack_states_thread(void *x) { char progress_text[80]; char keystr[19]; - sprintf(keystr, "%012" PRIX64 " ", key); - sprintf(progress_text, "Brute force phase completed. Key found: " _GREEN_("%s"), keystr); + snprintf(keystr, sizeof(keystr), "%012" PRIX64 " ", key); + snprintf(progress_text, sizeof(progress_text), "Brute force phase completed. Key found: " _GREEN_("%s"), keystr); hardnested_print_progress(thread_arg->num_acquired_nonces, progress_text, 0.0, 0); break; } else if (keys_found) { @@ -182,7 +182,7 @@ crack_states_thread(void *x) { } else { if (!thread_arg->silent) { char progress_text[80]; - sprintf(progress_text, "Brute force phase: %6.02f%%\t", 100.0 * (float)num_keys_tested / (float)(thread_arg->maximum_states)); + snprintf(progress_text, sizeof(progress_text), "Brute force phase: %6.02f%%\t", 100.0 * (float)num_keys_tested / (float)(thread_arg->maximum_states)); float remaining_bruteforce = thread_arg->nonces[thread_arg->best_first_bytes[0]].expected_num_brute_force - (float)num_keys_tested / 2; hardnested_print_progress(thread_arg->num_acquired_nonces, progress_text, remaining_bruteforce, 5000); } diff --git a/client/deps/hardnested/hardnested_tables.c b/client/deps/hardnested/hardnested_tables.c index b124345d0..ce2f42cff 100644 --- a/client/deps/hardnested/hardnested_tables.c +++ b/client/deps/hardnested/hardnested_tables.c @@ -200,7 +200,7 @@ static inline uint32_t count_states(uint32_t *bitset) { static void write_bitflips_file(odd_even_t odd_even, uint16_t bitflip, int sum_a0, uint32_t *bitset, uint32_t count) { char filename[80]; - sprintf(filename, "bitflip_%d_%03" PRIx16 "_sum%d_states.bin", odd_even, bitflip, sum_a0); + snprintf(filename, sizeof(filename), "bitflip_%d_%03" PRIx16 "_sum%d_states.bin", odd_even, bitflip, sum_a0); FILE *outfile = fopen(filename, "wb"); fwrite(&count, 1, sizeof(count), outfile); fwrite(bitset, 1, sizeof(uint32_t) * (1 << 19), outfile); diff --git a/client/deps/liblua/lobject.c b/client/deps/liblua/lobject.c index 79ac0b5e6..d46790cf7 100644 --- a/client/deps/liblua/lobject.c +++ b/client/deps/liblua/lobject.c @@ -215,7 +215,7 @@ const char *luaO_pushvfstring(lua_State *L, const char *fmt, va_list argp) { } case 'p': { char buff[4 * sizeof(void *) + 8]; /* should be enough space for a `%p' */ - int l = sprintf(buff, "%p", va_arg(argp, void *)); + int l = snprintf(buff, sizeof(buff), "%p", va_arg(argp, void *)); pushstr(L, buff, l); break; } diff --git a/client/deps/liblua/lstrlib.c b/client/deps/liblua/lstrlib.c index 57b4ebc4b..ed6f1b7b7 100644 --- a/client/deps/liblua/lstrlib.c +++ b/client/deps/liblua/lstrlib.c @@ -879,9 +879,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 luaL_addchar(b, *s); @@ -947,7 +947,7 @@ static int str_format(lua_State *L) { strfrmt = scanformat(L, strfrmt, form); switch (*strfrmt++) { case 'c': { - nb = sprintf(buff, form, luaL_checkint(L, arg)); + nb = snprintf(buff, MAX_ITEM, form, luaL_checkint(L, arg)); break; } case 'd': @@ -958,7 +958,7 @@ static int str_format(lua_State *L) { luaL_argcheck(L, -1 < diff && diff < 1, arg, "not a number in proper range"); addlenmod(form, LUA_INTFRMLEN); - nb = sprintf(buff, form, ni); + nb = snprintf(buff, MAX_ITEM, form, ni); break; } case 'o': @@ -971,7 +971,7 @@ static int str_format(lua_State *L) { luaL_argcheck(L, -1 < diff && diff < 1, arg, "not a non-negative number in proper range"); addlenmod(form, LUA_INTFRMLEN); - nb = sprintf(buff, form, ni); + nb = snprintf(buff, MAX_ITEM, form, ni); break; } case 'e': @@ -984,7 +984,7 @@ static int str_format(lua_State *L) { case 'g': case 'G': { addlenmod(form, LUA_FLTFRMLEN); - nb = sprintf(buff, form, (LUA_FLTFRM_T)luaL_checknumber(L, arg)); + nb = snprintf(buff, MAX_ITEM, form, (LUA_FLTFRM_T)luaL_checknumber(L, arg)); break; } case 'q': { @@ -1000,7 +1000,7 @@ static int str_format(lua_State *L) { luaL_addvalue(&b); break; } else { - nb = sprintf(buff, form, s); + nb = snprintf(buff, MAX_ITEM, form, s); lua_pop(L, 1); /* remove result from 'luaL_tolstring' */ break; } diff --git a/client/deps/liblua/luaconf.h b/client/deps/liblua/luaconf.h index d1c8364ee..77445383f 100644 --- a/client/deps/liblua/luaconf.h +++ b/client/deps/liblua/luaconf.h @@ -408,7 +408,7 @@ */ #define LUA_NUMBER_SCAN "%lf" #define LUA_NUMBER_FMT "%.14g" -#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) +#define lua_number2str(s,l,n) snprintf((s), (l), LUA_NUMBER_FMT, (n)) #define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ diff --git a/client/deps/liblua/lvm.c b/client/deps/liblua/lvm.c index 14a03573c..0f295138b 100644 --- a/client/deps/liblua/lvm.c +++ b/client/deps/liblua/lvm.c @@ -49,7 +49,7 @@ int luaV_tostring(lua_State *L, StkId obj) { else { char s[LUAI_MAXNUMBER2STR]; lua_Number n = nvalue(obj); - int l = lua_number2str(s, n); + int l = lua_number2str(s, sizeof(s), n); setsvalue2s(L, obj, luaS_newlstr(L, s, l)); return 1; } diff --git a/client/deps/reveng/model.c b/client/deps/reveng/model.c index 297f638db..a4dc0358e 100644 --- a/client/deps/reveng/model.c +++ b/client/deps/reveng/model.c @@ -107,7 +107,7 @@ char *mtostr(const model_t *model) { checkstr = ptostr(model->check, P_RTJUST, 4); magicstr = ptostr(model->magic, P_RTJUST, 4); - sprintf(strbuf, "%lu", plen(model->spoly)); + snprintf(strbuf, sizeof(strbuf), "%lu", plen(model->spoly)); size = 82 + strlen(strbuf) @@ -120,26 +120,26 @@ char *mtostr(const model_t *model) { + (magicstr && *magicstr ? strlen(magicstr) : 6) + (model->name && *model->name ? 2 + strlen(model->name) : 6); if ((string = calloc(size, sizeof(uint8_t)))) { - sprintf(strbuf, "\"%s\"", model->name); - sprintf(string, - "width=%lu " - "poly=0x%s " - "init=0x%s " - "refin=%s " - "refout=%s " - "xorout=0x%s " - "check=0x%s " - "residue=0x%s " - "name=%s", - plen(model->spoly), - polystr && *polystr ? polystr : "(none)", - initstr && *initstr ? initstr : "(none)", - (model->flags & P_REFIN) ? "true" : "false", - (model->flags & P_REFOUT) ? "true" : "false", - xorotstr && *xorotstr ? xorotstr : "(none)", - checkstr && *checkstr ? checkstr : "(none)", - magicstr && *magicstr ? magicstr : "(none)", - (model->name && *model->name) ? strbuf : "(none)"); + snprintf(strbuf, sizeof(strbuf), "\"%s\"", model->name); + snprintf(string, size * sizeof(uint8_t), + "width=%lu " + "poly=0x%s " + "init=0x%s " + "refin=%s " + "refout=%s " + "xorout=0x%s " + "check=0x%s " + "residue=0x%s " + "name=%s", + plen(model->spoly), + polystr && *polystr ? polystr : "(none)", + initstr && *initstr ? initstr : "(none)", + (model->flags & P_REFIN) ? "true" : "false", + (model->flags & P_REFOUT) ? "true" : "false", + xorotstr && *xorotstr ? xorotstr : "(none)", + checkstr && *checkstr ? checkstr : "(none)", + magicstr && *magicstr ? magicstr : "(none)", + (model->name && *model->name) ? strbuf : "(none)"); } free(polystr); free(initstr);