Răsfoiți Sursa

totemconfig: Ensure strncpy is always terminated

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse 4 ani în urmă
părinte
comite
a95b3df953
1 a modificat fișierele cu 8 adăugiri și 3 ștergeri
  1. 8 3
      exec/totemconfig.c

+ 8 - 3
exec/totemconfig.c

@@ -619,9 +619,14 @@ static int totem_get_crypto(struct totem_config *totem_config, icmap_map_t map,
 		totem_config->crypto_changed = 1;
 	    }
 
-	strncpy(totem_config->crypto_cipher_type, tmp_cipher, CONFIG_STRING_LEN_MAX);
-	strncpy(totem_config->crypto_hash_type, tmp_hash, CONFIG_STRING_LEN_MAX);
-	strncpy(totem_config->crypto_model, tmp_model, CONFIG_STRING_LEN_MAX);
+	strncpy(totem_config->crypto_cipher_type, tmp_cipher, CONFIG_STRING_LEN_MAX - 1);
+	totem_config->crypto_cipher_type[CONFIG_STRING_LEN_MAX - 1] = '\0';
+
+	strncpy(totem_config->crypto_hash_type, tmp_hash, CONFIG_STRING_LEN_MAX - 1);
+	totem_config->crypto_hash_type[CONFIG_STRING_LEN_MAX - 1] = '\0';
+
+	strncpy(totem_config->crypto_model, tmp_model, CONFIG_STRING_LEN_MAX - 1);
+	totem_config->crypto_model[CONFIG_STRING_LEN_MAX - 1] = '\0';
 
 out_free_crypto_model_str:
 	free(crypto_model_str);