]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Minor fixes for cat xlat
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 20 Jun 2025 21:36:12 +0000 (17:36 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 20 Jun 2025 21:36:12 +0000 (17:36 -0400)
src/lib/unlang/xlat_builtin.c

index 0bfe45065a6a2f58204ebc9004232a069bc6238f..9d200bd3b40e7c553befd9461b42eef4aa97d417 100644 (file)
@@ -713,7 +713,7 @@ done:
 static xlat_arg_parser_t const xlat_func_file_cat_args[] = {
        { .required = true,  .concat = true, .type = FR_TYPE_STRING,
          .func = filename_xlat_escape, .safe_for = FR_FILENAME_SAFE_FOR, .always_escape = true },
-       { .required = true, .type = FR_TYPE_UINT32, .single = true },
+       { .required = true, .type = FR_TYPE_SIZE, .single = true },
        XLAT_ARG_PARSER_TERMINATOR
 };
 
@@ -732,19 +732,19 @@ static xlat_action_t xlat_func_file_cat(TALLOC_CTX *ctx, fr_dcursor_t *out,
        fr_assert(vb->type == FR_TYPE_STRING);
        filename = vb->vb_strvalue;
 
-       if (stat(filename, &buf) < 0) {
-               RPERROR("Failed checking file %s - %s", filename, fr_syserror(errno));
+       fd = open(filename, O_RDONLY);
+       if (fd < 0) {
+               RPERROR("Failed opening file %s - %s", filename, fr_syserror(errno));
                return XLAT_ACTION_FAIL;
        }
 
-       if (buf.st_size > max_size->vb_uint32) {
-               RPERROR("File larger than specified maximum (%"PRIu64" vs %d)", buf.st_size, max_size->vb_uint32);
+       if (fstat(fd, &buf) < 0) {
+               RPERROR("Failed checking file %s - %s", filename, fr_syserror(errno));
                return XLAT_ACTION_FAIL;
        }
 
-       fd = open(filename, O_RDONLY);
-       if (fd < 0) {
-               RPERROR("Failed opening file %s - %s", filename, fr_syserror(errno));
+       if ((size_t)buf.st_size > max_size->vb_size) {
+               RPERROR("File larger than specified maximum (%"PRIu64" vs %zu)", buf.st_size, max_size->vb_size);
                return XLAT_ACTION_FAIL;
        }