Skip to content

Commit 05bfe3b

Browse files
committed
memset buffers
1 parent db69d85 commit 05bfe3b

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

nvram.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ int libinject_nvram_close(void) {
258258
}
259259

260260
int libinject_nvram_list_add(const char *key, const char *val) {
261+
memset(temp, 0, BUFFER_SIZE);
261262
char *pos;
262263

263264
PRINT_MSG("%s = %s + %s\n", val, temp, key);
@@ -293,6 +294,7 @@ int libinject_nvram_list_add(const char *key, const char *val) {
293294
}
294295

295296
char *libinject_nvram_list_exist(const char *key, const char *val, int magic) {
297+
memset(temp, 0, BUFFER_SIZE);
296298
char *pos = NULL;
297299

298300
if (libinject_nvram_get_buf(key, temp, BUFFER_SIZE) != E_SUCCESS) {
@@ -315,6 +317,7 @@ char *libinject_nvram_list_exist(const char *key, const char *val, int magic) {
315317
}
316318

317319
int libinject_nvram_list_del(const char *key, const char *val) {
320+
memset(temp, 0, BUFFER_SIZE);
318321
char *pos;
319322

320323
if (libinject_nvram_get_buf(key, temp, BUFFER_SIZE) != E_SUCCESS) {
@@ -345,6 +348,7 @@ char *libinject_nvram_get(const char *key) {
345348
asm ("move %0, $a1" :"=r"(key));
346349
}
347350
#endif
351+
memset(temp, 0, BUFFER_SIZE);
348352
return (libinject_nvram_get_buf(key, temp, BUFFER_SIZE) == E_SUCCESS) ? strndup(temp, BUFFER_SIZE) : NULL;
349353
}
350354

@@ -370,6 +374,8 @@ char *libinject_nvram_default_get(const char *key, const char *val) {
370374
}
371375

372376
int libinject_nvram_get_buf(const char *key, char *buf, size_t sz) {
377+
memset(buf, 0, sz);
378+
373379
char path[PATH_MAX] = MOUNT_POINT;
374380
FILE *f;
375381
int dirfd;
@@ -711,15 +717,15 @@ int libinject_nvram_unset(const char *key) {
711717
}
712718

713719
int libinject_nvram_safe_unset(const char *key) {
714-
// If we have a value for this key, unset it. Otherwise no-op
715-
// Always return E_SUCCESS(?)
720+
memset(temp, 0, BUFFER_SIZE);
716721
if (libinject_nvram_get_buf(key, temp, BUFFER_SIZE) == E_SUCCESS) {
717722
libinject_nvram_unset(key);
718723
}
719724
return E_SUCCESS;
720725
}
721726

722727
int libinject_nvram_match(const char *key, const char *val) {
728+
memset(temp, 0, BUFFER_SIZE);
723729
if (!key) {
724730
PRINT_MSG("%s\n", "NULL key!");
725731
return E_FAILURE;
@@ -835,7 +841,7 @@ char *libinject_nvram_nget(const char *fmt, ...) {
835841

836842
int libinject_nvram_nset(const char *val, const char *fmt, ...) {
837843
va_list va;
838-
844+
memset(temp, 0, BUFFER_SIZE);
839845
va_start(va, fmt);
840846
vsnprintf(temp, BUFFER_SIZE, fmt, va);
841847
va_end(va);
@@ -845,7 +851,7 @@ int libinject_nvram_nset(const char *val, const char *fmt, ...) {
845851

846852
int libinject_nvram_nset_int(const int val, const char *fmt, ...) {
847853
va_list va;
848-
854+
memset(temp, 0, BUFFER_SIZE);
849855
va_start(va, fmt);
850856
vsnprintf(temp, BUFFER_SIZE, fmt, va);
851857
va_end(va);
@@ -855,7 +861,7 @@ int libinject_nvram_nset_int(const int val, const char *fmt, ...) {
855861

856862
int libinject_nvram_nmatch(const char *val, const char *fmt, ...) {
857863
va_list va;
858-
864+
memset(temp, 0, BUFFER_SIZE);
859865
va_start(va, fmt);
860866
vsnprintf(temp, BUFFER_SIZE, fmt, va);
861867
va_end(va);
@@ -866,7 +872,7 @@ int libinject_nvram_nmatch(const char *val, const char *fmt, ...) {
866872
/* Realtek */
867873
int libinject_apmib_get(const int key, void *buf) {
868874
int res;
869-
875+
memset(temp, 0, BUFFER_SIZE);
870876
snprintf(temp, BUFFER_SIZE, "%d", key);
871877
if ((res = libinject_nvram_get_int(temp))) {
872878
(*(int32_t *) buf) = res;
@@ -876,6 +882,7 @@ int libinject_apmib_get(const int key, void *buf) {
876882
}
877883

878884
int libinject_apmib_set(const int key, void *buf) {
885+
memset(temp, 0, BUFFER_SIZE);
879886
snprintf(temp, BUFFER_SIZE, "%d", key);
880887
return libinject_nvram_set_int(temp, ((int32_t *) buf)[0]);
881888
}
@@ -884,7 +891,7 @@ int libinject_apmib_set(const int key, void *buf) {
884891

885892
int libinject_WAN_ith_CONFIG_GET(char *buf, const char *fmt, ...) {
886893
va_list va;
887-
894+
memset(temp, 0, BUFFER_SIZE);
888895
va_start(va, fmt);
889896
vsnprintf(temp, BUFFER_SIZE, fmt, va);
890897
va_end(va);
@@ -958,7 +965,7 @@ int libinject_envram_set(const char *key, const char *val) {
958965

959966
int libinject_envram_setf(const char* key, const char* fmt, ...) {
960967
va_list va;
961-
968+
memset(temp, 0, BUFFER_SIZE);
962969
va_start(va, fmt);
963970
vsnprintf(temp, BUFFER_SIZE, fmt, va);
964971
va_end(va);

0 commit comments

Comments
 (0)