Convert most strlcat() calls to use destination bound from sizeof()
authorMichael Rash <mbr@cipherdyne.org>
Sun, 28 Apr 2013 00:41:12 +0000 (20:41 -0400)
committerMichael Rash <mbr@cipherdyne.org>
Sun, 28 Apr 2013 00:41:12 +0000 (20:41 -0400)
This commit helps to ensure correctness of strlcat() calls in support of fixing
issue #2.

client/fwknop.c
server/config_init.c

index e691216..6763d76 100644 (file)
@@ -1117,10 +1117,10 @@ save_args(int argc, char **argv, const char * const args_save_file)
                 fprintf(stderr, "argument string too long, exiting.\n");
                 exit(EXIT_FAILURE);
             }
-            strlcat(args_str, argv[i], MAX_PATH_LEN);
-            strlcat(args_str, " ", MAX_PATH_LEN);
+            strlcat(args_str, argv[i], sizeof(args_str));
+            strlcat(args_str, " ", sizeof(args_str));
         }
-        strlcat(args_str, "\n", MAX_PATH_LEN);
+        strlcat(args_str, "\n", sizeof(args_str));
         if(write(args_file_fd, args_str, strlen(args_str))
                 != strlen(args_str)) {
             fprintf(stderr,
index a401a99..202df8b 100644 (file)
@@ -323,9 +323,9 @@ validate_options(fko_srv_options_t *opts)
         strlcpy(tmp_path, opts->config[CONF_FWKNOP_RUN_DIR], sizeof(tmp_path));
 
         if(tmp_path[strlen(tmp_path)-1] != '/')
-            strlcat(tmp_path, "/", MAX_PATH_LEN);
+            strlcat(tmp_path, "/", sizeof(tmp_path));
 
-        strlcat(tmp_path, DEF_PID_FILENAME, MAX_PATH_LEN);
+        strlcat(tmp_path, DEF_PID_FILENAME, sizeof(tmp_path));
 
         set_config_entry(opts, CONF_FWKNOP_PID_FILE, tmp_path);
     }
@@ -339,14 +339,14 @@ validate_options(fko_srv_options_t *opts)
         strlcpy(tmp_path, opts->config[CONF_FWKNOP_RUN_DIR], sizeof(tmp_path));
 
         if(tmp_path[strlen(tmp_path)-1] != '/')
-            strlcat(tmp_path, "/", MAX_PATH_LEN);
+            strlcat(tmp_path, "/", sizeof(tmp_path));
 
 
 #if USE_FILE_CACHE
-        strlcat(tmp_path, DEF_DIGEST_CACHE_FILENAME, MAX_PATH_LEN);
+        strlcat(tmp_path, DEF_DIGEST_CACHE_FILENAME, sizeof(tmp_path));
         set_config_entry(opts, CONF_DIGEST_FILE, tmp_path);
 #else
-        strlcat(tmp_path, DEF_DIGEST_CACHE_DB_FILENAME, MAX_PATH_LEN);
+        strlcat(tmp_path, DEF_DIGEST_CACHE_DB_FILENAME, sizeof(tmp_path));
         set_config_entry(opts, CONF_DIGEST_DB_FILE, tmp_path);
 #endif
     }