]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Replace dfree command output parsing with sscanf
authorVolker Lendecke <vl@samba.org>
Wed, 14 Jan 2026 07:18:15 +0000 (08:18 +0100)
committerVolker Lendecke <vl@samba.org>
Tue, 20 Jan 2026 11:53:34 +0000 (11:53 +0000)
No need to do manual parsing with STR_TO_SMB_BIG_UINT and manually
skipping whitespace

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
source3/smbd/dfree.c

index fef0313b9d23034b6ff5340eb897601e6a7af826..c046bdda91610639e8cbf2b626760a0f1747daed 100644 (file)
@@ -61,10 +61,10 @@ static bool handle_dfree_command(connection_struct *conn,
                loadparm_s3_global_substitution();
        const char *dfree_command = NULL;
        char *path = fname->base_name;
-       const char *p = NULL;
        char **lines = NULL;
        char **argl = NULL;
        char *line = NULL;
+       int ret;
 
        dfree_command = lp_dfree_command(talloc_tos(), lp_sub, SNUM(conn));
        if (!dfree_command || !*dfree_command) {
@@ -98,27 +98,27 @@ static bool handle_dfree_command(connection_struct *conn,
 
        DBG_NOTICE("Read input from dfree, \"%s\"\n", line);
 
-       *dsize = STR_TO_SMB_BIG_UINT(line, &p);
-       while (p && *p && isspace(*p))
-               p++;
-       if (p && *p)
-               *dfree = STR_TO_SMB_BIG_UINT(p, &p);
-       while (p && *p && isspace(*p))
-               p++;
-       if (p && *p)
-               *bsize = STR_TO_SMB_BIG_UINT(p, NULL);
-       else
-               *bsize = 1024;
-       TALLOC_FREE(lines);
+       ret = sscanf(
+               line, "%" SCNu64 " %" SCNu64 " %" SCNu64, dsize, dfree, bsize);
 
-       DBG_NOTICE("Parsed output of dfree, dsize=%"PRIu64", "
-                  "dfree=%"PRIu64", bsize=%"PRIu64"\n",
-                  *dsize, *dfree, *bsize);
+       TALLOC_FREE(lines);
 
-       if (!*dsize)
-               *dsize = 2048;
-       if (!*dfree)
+       if (ret < 3) {
+               *bsize = 1024;
+       }
+       if (ret < 2) {
                *dfree = 1024;
+       }
+       if (ret < 1) {
+               *dsize = 2048;
+       }
+
+       DBG_NOTICE("Parsed output of dfree, ret=%d, dsize=%" PRIu64 ", "
+                  "dfree=%" PRIu64 ", bsize=%" PRIu64 "\n",
+                  ret,
+                  *dsize,
+                  *dfree,
+                  *bsize);
 
        return true;
 }