14
14
* reserved.
15
15
* Copyright (c) 2018 Triad National Security, LLC. All rights
16
16
* reserved.
17
+ * Copyright (c) 2020 Cisco Systems, Inc. All rights reserved
17
18
* $COPYRIGHT$
18
19
*
19
20
* Additional copyrights may follow
@@ -276,7 +277,7 @@ static int save_param_name (void)
276
277
277
278
static int add_to_env_str (char * var , char * val )
278
279
{
279
- int sz , varsz , valsz , new_envsize ;
280
+ int sz , varsz = 0 , valsz = 0 , new_envsize ;
280
281
void * tmp ;
281
282
282
283
if (NULL == var ) {
@@ -286,22 +287,25 @@ static int add_to_env_str(char *var, char *val)
286
287
varsz = strlen (var );
287
288
if (NULL != val ) {
288
289
valsz = strlen (val );
289
- /* account for '=' */
290
+ /* If we have a value, it will be preceeded by a '=', so be
291
+ sure to account for that */
290
292
valsz += 1 ;
291
293
}
292
294
sz = 0 ;
293
295
if (NULL != env_str ) {
294
296
sz = strlen (env_str );
295
- /* account for ';' */
297
+ /* If we have a valid variable, the whole clause will be
298
+ terminated by a ';', so be sure to account for that */
296
299
sz += 1 ;
297
300
}
298
- /* add required new size incl NUL byte */
299
- sz += varsz + valsz + 1 ;
301
+ /* Sum the required new sizes, including space for a terminating
302
+ \0 byte */
303
+ sz += varsz + valsz + 1 ;
300
304
301
- /* make sure we have sufficient space */
305
+ /* Make sure we have sufficient space */
302
306
new_envsize = envsize ;
303
307
while (new_envsize <= sz ) {
304
- new_envsize *=2 ;
308
+ new_envsize *= 2 ;
305
309
}
306
310
307
311
if (NULL != env_str ) {
0 commit comments