Skip to contentSkip to conversation

systemd: Fix format-overflow warning

PATCH In review Steve Dickson 1 participant 2 messages Feb 23, 2022 – Feb 28, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 systemd: Fix format-overflow warning

rpc-pipefs-generator.c:35:23: error: '%s' directive output between 0 and 2147483653 bytes may exceed minimum required size of 4095 [-Werror=format-overflow=]
35 | sprintf(path, "%s/%s", dirname, pipefs_unit);
| ^

---
 systemd/rpc-pipefs-generator.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
systemd/rpc-pipefs-generator.c +3 -2
index c24db56..7b2bb4f 100644
@@ -28,11 +28,12 @@ static int generate_mount_unit(const char *pipefs_path, const char *pipefs_unit,
 {
 	char	*path;
 	FILE	*f;
+	size_t size = (strlen(dirname) + 1 + strlen(pipefs_unit));
 
-	path = malloc(strlen(dirname) + 1 + strlen(pipefs_unit));
+	path = malloc(size);
 	if (!path)
 		return 1;
-	sprintf(path, "%s/%s", dirname, pipefs_unit);
+	snprintf(path, size, "%s/%s", dirname, pipefs_unit);
 	f = fopen(path, "w");
 	if (!f)
 	{
Signature · 1 line
2.35.1
#1 lore raw
Quoted 5 lines · Steve Dickson

rpc-pipefs-generator.c:35:23: error: '%s' directive output between 0 and 2147483653 bytes may exceed minimum required size of 4095 [-Werror=format-overflow=]

    35 |         sprintf(path, "%s/%s", dirname, pipefs_unit);
       |                       ^

Committed... (tag: nfs-utils-2-6-2-rc3)

steved.

Quoted 23 lines
---
  systemd/rpc-pipefs-generator.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
systemd/rpc-pipefs-generator.c +3 -2
index c24db56..7b2bb4f 100644
@@ -28,11 +28,12 @@ static int generate_mount_unit(const char *pipefs_path, const char *pipefs_unit,
  {
  	char	*path;
  	FILE	*f;
+	size_t size = (strlen(dirname) + 1 + strlen(pipefs_unit));
 
-	path = malloc(strlen(dirname) + 1 + strlen(pipefs_unit));
+	path = malloc(size);
  	if (!path)
  		return 1;
-	sprintf(path, "%s/%s", dirname, pipefs_unit);
+	snprintf(path, size, "%s/%s", dirname, pipefs_unit);
  	f = fopen(path, "w");
  	if (!f)
  	{