From: Volker Lendecke Date: Wed, 14 Jan 2026 07:18:15 +0000 (+0100) Subject: smbd: Replace dfree command output parsing with sscanf X-Git-Tag: tdb-1.4.15~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bb5e3dd55df2e781108e10f556f75ce08fcc6d7;p=thirdparty%2Fsamba.git smbd: Replace dfree command output parsing with sscanf No need to do manual parsing with STR_TO_SMB_BIG_UINT and manually skipping whitespace Signed-off-by: Volker Lendecke Reviewed-by: Anoop C S --- diff --git a/source3/smbd/dfree.c b/source3/smbd/dfree.c index fef0313b9d2..c046bdda916 100644 --- a/source3/smbd/dfree.c +++ b/source3/smbd/dfree.c @@ -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; }