4646typedef enum
4747{
4848 CUPSD_VARTYPE_INTEGER , /* Integer option */
49+ CUPSD_VARTYPE_SIZE , /* Size option */
4950 CUPSD_VARTYPE_TIME , /* Time interval option */
5051 CUPSD_VARTYPE_NULLSTRING , /* String option or NULL/empty string */
5152 CUPSD_VARTYPE_STRING , /* String option */
@@ -101,7 +102,7 @@ static const cupsd_var_t cupsd_vars[] =
101102#ifdef HAVE_LAUNCHD
102103 { "LaunchdTimeout" , & IdleExitTimeout , CUPSD_VARTYPE_TIME },
103104#endif /* HAVE_LAUNCHD */
104- { "LimitRequestBody" , & MaxRequestSize , CUPSD_VARTYPE_INTEGER },
105+ { "LimitRequestBody" , & MaxRequestSize , CUPSD_VARTYPE_SIZE },
105106 { "LogDebugHistory" , & LogDebugHistory , CUPSD_VARTYPE_INTEGER },
106107 { "MaxActiveJobs" , & MaxActiveJobs , CUPSD_VARTYPE_INTEGER },
107108 { "MaxClients" , & MaxClients , CUPSD_VARTYPE_INTEGER },
@@ -114,8 +115,8 @@ static const cupsd_var_t cupsd_vars[] =
114115 { "MaxJobsPerUser" , & MaxJobsPerUser , CUPSD_VARTYPE_INTEGER },
115116 { "MaxJobTime" , & MaxJobTime , CUPSD_VARTYPE_TIME },
116117 { "MaxLeaseDuration" , & MaxLeaseDuration , CUPSD_VARTYPE_TIME },
117- { "MaxLogSize" , & MaxLogSize , CUPSD_VARTYPE_INTEGER },
118- { "MaxRequestSize" , & MaxRequestSize , CUPSD_VARTYPE_INTEGER },
118+ { "MaxLogSize" , & MaxLogSize , CUPSD_VARTYPE_SIZE },
119+ { "MaxRequestSize" , & MaxRequestSize , CUPSD_VARTYPE_SIZE },
119120 { "MaxSubscriptions" , & MaxSubscriptions , CUPSD_VARTYPE_INTEGER },
120121 { "MaxSubscriptionsPerJob" , & MaxSubscriptionsPerJob , CUPSD_VARTYPE_INTEGER },
121122 { "MaxSubscriptionsPerPrinter" ,& MaxSubscriptionsPerPrinter , CUPSD_VARTYPE_INTEGER },
@@ -2725,54 +2726,80 @@ parse_variable(
27252726 case CUPSD_VARTYPE_INTEGER :
27262727 if (!value )
27272728 {
2728- cupsdLogMessage (CUPSD_LOG_ERROR ,
2729- "Missing integer value for %s on line %d of %s." ,
2730- line , linenum , filename );
2729+ cupsdLogMessage (CUPSD_LOG_ERROR , "Missing integer value for %s on line %d of %s." , line , linenum , filename );
27312730 return (0 );
27322731 }
27332732 else if (!isdigit (* value & 255 ))
27342733 {
2735- cupsdLogMessage (CUPSD_LOG_ERROR ,
2736- "Bad integer value for %s on line %d of %s." ,
2737- line , linenum , filename );
2734+ cupsdLogMessage (CUPSD_LOG_ERROR , "Bad integer value for %s on line %d of %s." , line , linenum , filename );
2735+ return (0 );
2736+ }
2737+ else
2738+ {
2739+ long n ; /* Number */
2740+ char * ptr ; /* Remaining text */
2741+
2742+ n = strtol (value , & ptr , 0 );
2743+
2744+ if (n < 0 || n > INT_MAX || (ptr && * ptr ))
2745+ {
2746+ cupsdLogMessage (CUPSD_LOG_ERROR , "Bad integer value for %s on line %d of %s." , line , linenum , filename );
2747+ return (0 );
2748+ }
2749+ else
2750+ {
2751+ * ((int * )var -> ptr ) = (int )n ;
2752+ }
2753+ }
2754+ break ;
2755+
2756+ case CUPSD_VARTYPE_SIZE :
2757+ if (!value )
2758+ {
2759+ cupsdLogMessage (CUPSD_LOG_ERROR , "Missing size value for %s on line %d of %s." , line , linenum , filename );
2760+ return (0 );
2761+ }
2762+ else if (!isdigit (* value & 255 ))
2763+ {
2764+ cupsdLogMessage (CUPSD_LOG_ERROR , "Bad size value for %s on line %d of %s." , line , linenum , filename );
27382765 return (0 );
27392766 }
27402767 else
27412768 {
2742- int n ; /* Number */
2743- char * units ; /* Units */
2769+ double n ; /* Number */
2770+ char * units ; /* Units */
27442771
2745- n = ( int ) strtol ( value , & units , 0 );
2772+ n = _cupsStrScand ( value , & units , localeconv () );
27462773
27472774 if (units && * units )
27482775 {
27492776 if (tolower (units [0 ] & 255 ) == 'g' )
2750- n *= 1024 * 1024 * 1024 ;
2777+ {
2778+ n *= 1024.0 * 1024.0 * 1024.0 ;
2779+ }
27512780 else if (tolower (units [0 ] & 255 ) == 'm' )
2752- n *= 1024 * 1024 ;
2781+ {
2782+ n *= 1024.0 * 1024.0 ;
2783+ }
27532784 else if (tolower (units [0 ] & 255 ) == 'k' )
2754- n *= 1024 ;
2755- else if ( tolower ( units [ 0 ] & 255 ) == 't' )
2756- n *= 262144 ;
2785+ {
2786+ n *= 1024.0 ;
2787+ }
27572788 else
27582789 {
2759- cupsdLogMessage (CUPSD_LOG_ERROR ,
2760- "Unknown integer value for %s on line %d of %s." ,
2761- line , linenum , filename );
2790+ cupsdLogMessage (CUPSD_LOG_ERROR , "Unknown size units for %s on line %d of %s." , line , linenum , filename );
27622791 return (0 );
27632792 }
27642793 }
27652794
2766- if (n < 0 )
2795+ if (n < 0 || n > ( double ) OFF_MAX )
27672796 {
2768- cupsdLogMessage (CUPSD_LOG_ERROR ,
2769- "Bad negative integer value for %s on line %d of "
2770- "%s." , line , linenum , filename );
2797+ cupsdLogMessage (CUPSD_LOG_ERROR , "Bad size value for %s on line %d of %s." , line , linenum , filename );
27712798 return (0 );
27722799 }
27732800 else
27742801 {
2775- * ((int * )var -> ptr ) = n ;
2802+ * ((off_t * )var -> ptr ) = ( off_t ) n ;
27762803 }
27772804 }
27782805 break ;
0 commit comments