Browse Source

Bugfix: miner: Ensure raise_fd_limits buffers are big enough for unsigned long values being printed into them

Luke Dashjr 4 years ago
parent
commit
b24bb943b3
2 changed files with 4 additions and 2 deletions
  1. 2 2
      miner.c
  2. 2 0
      util.h

+ 2 - 2
miner.c

@@ -12407,8 +12407,8 @@ static void raise_fd_limits(void)
 #ifdef HAVE_SETRLIMIT
 #ifdef HAVE_SETRLIMIT
 	struct rlimit fdlimit;
 	struct rlimit fdlimit;
 	rlim_t old_soft_limit;
 	rlim_t old_soft_limit;
-	char frombuf[0x10] = "unlimited";
-	char hardbuf[0x10] = "unlimited";
+	char frombuf[MAX_STR_UINT(unsigned long)] = "unlimited";
+	char hardbuf[MAX_STR_UINT(unsigned long)] = "unlimited";
 	
 	
 	if (getrlimit(RLIMIT_NOFILE, &fdlimit))
 	if (getrlimit(RLIMIT_NOFILE, &fdlimit))
 		applogr(, LOG_DEBUG, "setrlimit: Failed to getrlimit(RLIMIT_NOFILE)");
 		applogr(, LOG_DEBUG, "setrlimit: Failed to getrlimit(RLIMIT_NOFILE)");

+ 2 - 0
util.h

@@ -106,6 +106,8 @@ const char *bfg_json_obj_string(json_t *json, const char *key, const char *fail)
 
 
 extern const char *__json_array_string(json_t *, unsigned int entry);
 extern const char *__json_array_string(json_t *, unsigned int entry);
 
 
+#define MAX_STR_UINT(type)  ((sizeof(type) * CHAR_BIT + 2) / 3)
+
 #ifndef min
 #ifndef min
 #  define min(a, b)  ((a) < (b) ? (a) : (b))
 #  define min(a, b)  ((a) < (b) ? (a) : (b))
 #endif
 #endif