@@ -116,9 +116,13 @@ ippFileDelete(ipp_file_t *file) // I - IPP data file
116116//
117117// 'ippFileExpandVars()' - Expand IPP data file and environment variables in a string.
118118//
119- // This function expands IPP data file variables of the form "$name" and
120- // environment variables of the form "$ENV[name]" in the source string to the
121- // destination string. The
119+ // This function expands IPP data file variables in "src" of the form "$name" or
120+ // "${name}" and environment variables of the form "$ENV[name]" in the source
121+ // string to the destination buffer. The destination buffer "dst" is filled up
122+ // to "dstsize - 1" bytes to allow for a trailing NUL character.
123+ //
124+ // The return value is the actual required size for all expansions regardless of
125+ // the value of "dstsize".
122126//
123127// @since CUPS 2.5@
124128//
@@ -160,49 +164,50 @@ ippFileExpandVars(ipp_file_t *file, // I - IPP data file
160164 }
161165 else if (!strncmp (src , "$ENV[" , 5 ))
162166 {
163- // Environment variable
164- cupsCopyString (temp , src + 5 , sizeof (temp ));
165-
166- for (tempptr = temp ; * tempptr ; tempptr ++ )
167+ // $ENV[name] - environment variable
168+ for (src += 5 , tempptr = temp ; * src && * src != ']' ; src ++ )
167169 {
168- if (* tempptr == ']' )
169- break ;
170+ // Copy the name to "temp"...
171+ if (tempptr < (temp + sizeof (temp ) - 1 ))
172+ * tempptr ++ = * src ;
170173 }
174+ * tempptr = '\0' ;
171175
172- if (* tempptr )
173- * tempptr ++ = '\0' ;
176+ if (* src ) // Skip "]"
177+ src ++ ;
174178
175179 value = getenv (temp );
176- src += tempptr - temp + 5 ;
177180 }
178181 else
179182 {
180- // $name or ${name}
183+ // $name or ${name} - file variable
181184 if (src [1 ] == '{' )
182185 {
183- src += 2 ;
184- cupsCopyString (temp , src , sizeof (temp ));
185- if ((tempptr = strchr (temp , '}' )) != NULL )
186- * tempptr = '\0' ;
187- else
188- tempptr = temp + strlen (temp );
186+ // ${name}
187+ for (src += 2 , tempptr = temp ; * src && * src != '}' ; src ++ )
188+ {
189+ // Copy the name to "temp"...
190+ if (tempptr < (temp + sizeof (temp ) - 1 ))
191+ * tempptr ++ = * src ;
192+ }
193+ * tempptr = '\0' ;
194+
195+ if (* src ) // Skip "}"
196+ src ++ ;
189197 }
190198 else
191199 {
192- cupsCopyString (temp , src + 1 , sizeof (temp ));
193-
194- for (tempptr = temp ; * tempptr ; tempptr ++ )
200+ // $name
201+ for (src ++ , tempptr = temp ; isalnum (* src & 255 ) || * src == '-' || * src == '_' ; src ++ )
195202 {
196- if (!isalnum (* tempptr & 255 ) && * tempptr != '-' && * tempptr != '_' )
197- break ;
203+ // Copy the name to "temp"...
204+ if (tempptr < (temp + sizeof (temp ) - 1 ))
205+ * tempptr ++ = * src ;
198206 }
199-
200- if (* tempptr )
201- * tempptr = '\0' ;
207+ * tempptr = '\0' ;
202208 }
203209
204210 value = ippFileGetVar (file , temp );
205- src += tempptr - temp + 1 ;
206211 }
207212
208213 if (value )
@@ -213,9 +218,13 @@ ippFileExpandVars(ipp_file_t *file, // I - IPP data file
213218 }
214219 }
215220 else if (dstptr < dstend )
221+ {
216222 * dstptr ++ = * src ++ ;
223+ }
217224 else
225+ {
218226 dstptr ++ ;
227+ }
219228 }
220229
221230 if (dstptr < dstend )
@@ -231,9 +240,7 @@ ippFileExpandVars(ipp_file_t *file, // I - IPP data file
231240// 'ippFileGetAttribute()' - Get a single named attribute from an IPP data file.
232241//
233242// This function finds the first occurence of a named attribute in the current
234- // IPP attributes in the specified data file. Unlike
235- // @link ippFileGetAttributes@, this function does not clear the attribute
236- // state.
243+ // IPP attributes in the specified data file.
237244//
238245// @since CUPS 2.5@
239246//
@@ -964,7 +971,7 @@ ippFileReadToken(ipp_file_t *file, // I - IPP data file
964971 * tokptr = '\0' ;
965972 DEBUG_printf ("1ippFileReadToken: Returning \"%s\" at EOF." , token );
966973
967- return (tokptr > token );
974+ return (tokptr > token && ! quote );
968975}
969976
970977
0 commit comments