]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Update processing of LimitRequestBody, MaxLogSize, and MaxRequestSize to support...
authorMichael R Sweet <msweet@msweet.org>
Mon, 13 Apr 2026 17:18:29 +0000 (13:18 -0400)
committerMichael R Sweet <msweet@msweet.org>
Mon, 13 Apr 2026 17:18:29 +0000 (13:18 -0400)
scheduler/conf.c
scheduler/conf.h

index 03a132797ada04935ce7c7e9a1cf8ddccd8c6b7e..70376fd572e8fe0dbd3a230f976b2b7c263c5069 100644 (file)
@@ -43,6 +43,7 @@
 typedef enum
 {
   CUPSD_VARTYPE_INTEGER,               /* Integer option */
+  CUPSD_VARTYPE_SIZE,                  /* Size option */
   CUPSD_VARTYPE_TIME,                  /* Time interval option */
   CUPSD_VARTYPE_NULLSTRING,            /* String option or NULL/empty string */
   CUPSD_VARTYPE_STRING,                        /* String option */
@@ -94,7 +95,7 @@ static const cupsd_var_t      cupsd_vars[] =
 #ifdef HAVE_LAUNCHD
   { "LaunchdTimeout",          &IdleExitTimeout,       CUPSD_VARTYPE_TIME },
 #endif /* HAVE_LAUNCHD */
-  { "LimitRequestBody",                &MaxRequestSize,        CUPSD_VARTYPE_INTEGER },
+  { "LimitRequestBody",                &MaxRequestSize,        CUPSD_VARTYPE_SIZE },
   { "LogDebugHistory",         &LogDebugHistory,       CUPSD_VARTYPE_INTEGER },
   { "MaxActiveJobs",           &MaxActiveJobs,         CUPSD_VARTYPE_INTEGER },
   { "MaxClients",              &MaxClients,            CUPSD_VARTYPE_INTEGER },
@@ -107,8 +108,8 @@ static const cupsd_var_t    cupsd_vars[] =
   { "MaxJobsPerUser",          &MaxJobsPerUser,        CUPSD_VARTYPE_INTEGER },
   { "MaxJobTime",              &MaxJobTime,            CUPSD_VARTYPE_TIME },
   { "MaxLeaseDuration",                &MaxLeaseDuration,      CUPSD_VARTYPE_TIME },
-  { "MaxLogSize",              &MaxLogSize,            CUPSD_VARTYPE_INTEGER },
-  { "MaxRequestSize",          &MaxRequestSize,        CUPSD_VARTYPE_INTEGER },
+  { "MaxLogSize",              &MaxLogSize,            CUPSD_VARTYPE_SIZE },
+  { "MaxRequestSize",          &MaxRequestSize,        CUPSD_VARTYPE_SIZE },
   { "MaxSubscriptions",                &MaxSubscriptions,      CUPSD_VARTYPE_INTEGER },
   { "MaxSubscriptionsPerJob",  &MaxSubscriptionsPerJob,        CUPSD_VARTYPE_INTEGER },
   { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter,  CUPSD_VARTYPE_INTEGER },
@@ -2806,54 +2807,80 @@ parse_variable(
     case CUPSD_VARTYPE_INTEGER :
        if (!value)
        {
-         cupsdLogMessage(CUPSD_LOG_ERROR,
-                         "Missing integer value for %s on line %d of %s.",
-                         line, linenum, filename);
+         cupsdLogMessage(CUPSD_LOG_ERROR, "Missing integer value for %s on line %d of %s.", line, linenum, filename);
           return (0);
        }
        else if (!isdigit(*value & 255))
        {
-         cupsdLogMessage(CUPSD_LOG_ERROR,
-                         "Bad integer value for %s on line %d of %s.",
-                         line, linenum, filename);
+         cupsdLogMessage(CUPSD_LOG_ERROR, "Bad integer value for %s on line %d of %s.", line, linenum, filename);
+          return (0);
+       }
+       else
+       {
+         long  n;              /* Number */
+         char  *ptr;           /* Remaining text */
+
+         n = strtol(value, &ptr, 0);
+
+         if (n < 0 || n > INT_MAX || (ptr && *ptr))
+         {
+           cupsdLogMessage(CUPSD_LOG_ERROR, "Bad integer value for %s on line %d of %s.", line, linenum, filename);
+           return (0);
+         }
+         else
+         {
+           *((int *)var->ptr) = (int)n;
+         }
+       }
+       break;
+
+    case CUPSD_VARTYPE_SIZE :
+       if (!value)
+       {
+         cupsdLogMessage(CUPSD_LOG_ERROR, "Missing size value for %s on line %d of %s.", line, linenum, filename);
+          return (0);
+       }
+       else if (!isdigit(*value & 255))
+       {
+         cupsdLogMessage(CUPSD_LOG_ERROR, "Bad size value for %s on line %d of %s.", line, linenum, filename);
           return (0);
        }
        else
        {
-         int   n;              /* Number */
-         char  *units;         /* Units */
+         double        n;              /* Number */
+         char          *units;         /* Units */
 
-         n = (int)strtol(value, &units, 0);
+         n = _cupsStrScand(value, &units, localeconv());
 
          if (units && *units)
          {
            if (tolower(units[0] & 255) == 'g')
-             n *= 1024 * 1024 * 1024;
+           {
+             n *= 1024.0 * 1024.0 * 1024.0;
+           }
            else if (tolower(units[0] & 255) == 'm')
-             n *= 1024 * 1024;
+           {
+             n *= 1024.0 * 1024.0;
+           }
            else if (tolower(units[0] & 255) == 'k')
-             n *= 1024;
-           else if (tolower(units[0] & 255) == 't')
-             n *= 262144;
+           {
+             n *= 1024.0;
+           }
            else
            {
-             cupsdLogMessage(CUPSD_LOG_ERROR,
-                             "Unknown integer value for %s on line %d of %s.",
-                             line, linenum, filename);
+             cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown size units for %s on line %d of %s.", line, linenum, filename);
              return (0);
            }
          }
 
-         if (n < 0)
+         if (n < 0 || n > (double)OFF_MAX)
          {
-           cupsdLogMessage(CUPSD_LOG_ERROR,
-                           "Bad negative integer value for %s on line %d of "
-                           "%s.", line, linenum, filename);
+           cupsdLogMessage(CUPSD_LOG_ERROR, "Bad size value for %s on line %d of %s.", line, linenum, filename);
            return (0);
          }
          else
          {
-           *((int *)var->ptr) = n;
+           *((off_t *)var->ptr) = (off_t)n;
          }
        }
        break;
index 19dfdb1340e7f4f16a72533a9bac2b7986cf50e9..553d1f95563068129777365d795108eeb2774081 100644 (file)
@@ -193,13 +193,13 @@ VAR int                   MaxClients              VALUE(100),
                                        /* Maximum number of clients */
                        MaxClientsPerHost       VALUE(0),
                                        /* Maximum number of clients per host */
-                       MaxCopies               VALUE(CUPS_DEFAULT_MAX_COPIES),
+                       MaxCopies               VALUE(CUPS_DEFAULT_MAX_COPIES);
                                        /* Maximum number of copies per job */
-                       MaxLogSize              VALUE(1024 * 1024),
+VAR off_t              MaxLogSize              VALUE(1024 * 1024),
                                        /* Maximum size of log files */
-                       MaxRequestSize          VALUE(0),
+                       MaxRequestSize          VALUE(0);
                                        /* Maximum size of IPP requests */
-                       HostNameLookups         VALUE(FALSE),
+VAR int                        HostNameLookups         VALUE(FALSE),
                                        /* Do we do reverse lookups? */
                        Timeout                 VALUE(DEFAULT_TIMEOUT),
                                        /* Timeout during requests */