@@ -2309,10 +2309,14 @@ char *origbuf;
2309
2309
int len ;
2310
2310
boolean retval = TRUE;
2311
2311
2312
+ while (* origbuf == ' ' || * origbuf == '\t' ) /* skip leading whitespace */
2313
+ ++ origbuf ; /* (caller probably already did this) */
2314
+ (void ) strncpy (buf , origbuf , sizeof buf - 1 );
2315
+ buf [sizeof buf - 1 ] = '\0' ; /* strncpy not guaranteed to NUL terminate */
2312
2316
/* convert any tab to space, condense consecutive spaces into one,
2313
2317
remove leading and trailing spaces (exception: if there is nothing
2314
2318
but spaces, one of them will be kept even though it leads/trails) */
2315
- mungspaces (strcpy ( buf , origbuf ) );
2319
+ mungspaces (buf );
2316
2320
2317
2321
/* find the '=' or ':' */
2318
2322
bufp = find_optparam (buf );
@@ -3034,7 +3038,11 @@ boolean
3034
3038
proc_wizkit_line (buf )
3035
3039
char * buf ;
3036
3040
{
3037
- struct obj * otmp = readobjnam (buf , (struct obj * ) 0 );
3041
+ struct obj * otmp ;
3042
+
3043
+ if (strlen (buf ) >= BUFSZ )
3044
+ buf [BUFSZ - 1 ] = '\0' ;
3045
+ otmp = readobjnam (buf , (struct obj * ) 0 );
3038
3046
3039
3047
if (otmp ) {
3040
3048
if (otmp != & zeroobj )
@@ -3142,22 +3150,23 @@ boolean FDECL((*proc), (char *));
3142
3150
3143
3151
/* merge now read line with previous ones, if necessary */
3144
3152
if (!ignoreline ) {
3145
- len = (int ) strlen (inbuf ) + 1 ;
3153
+ len = (int ) strlen (ep ) + 1 ; /* +1: final '\0' */
3146
3154
if (buf )
3147
- len += (int ) strlen (buf );
3155
+ len += (int ) strlen (buf ) + 1 ; /* +1: space */
3148
3156
tmpbuf = (char * ) alloc (len );
3157
+ * tmpbuf = '\0' ;
3149
3158
if (buf ) {
3150
- Sprintf ( tmpbuf , "%s %s" , buf , inbuf );
3159
+ Strcat ( strcpy ( tmpbuf , buf ), " " );
3151
3160
free (buf );
3152
- } else
3153
- Strcpy (tmpbuf , inbuf );
3154
- buf = tmpbuf ;
3161
+ }
3162
+ buf = strcat (tmpbuf , ep );
3163
+ buf [ sizeof inbuf - 1 ] = '\0' ;
3155
3164
}
3156
3165
3157
3166
if (morelines || (ignoreline && !oldline ))
3158
3167
continue ;
3159
3168
3160
- if (handle_config_section (ep )) {
3169
+ if (handle_config_section (buf )) {
3161
3170
free (buf );
3162
3171
buf = (char * ) 0 ;
3163
3172
continue ;
@@ -3179,11 +3188,11 @@ boolean FDECL((*proc), (char *));
3179
3188
}
3180
3189
bufp ++ ;
3181
3190
if (config_section_chosen )
3182
- free (config_section_chosen );
3191
+ free (config_section_chosen ), config_section_chosen = 0 ;
3183
3192
section = choose_random_part (bufp , ',' );
3184
- if (section )
3193
+ if (section ) {
3185
3194
config_section_chosen = dupstr (section );
3186
- else {
3195
+ } else {
3187
3196
config_error_add ("No config section to choose" );
3188
3197
rv = FALSE;
3189
3198
}
@@ -3300,6 +3309,8 @@ int which_set;
3300
3309
struct symparse * symp ;
3301
3310
char * bufp , * commentp , * altp ;
3302
3311
3312
+ if (strlen (buf ) >= BUFSZ )
3313
+ buf [BUFSZ - 1 ] = '\0' ;
3303
3314
/* convert each instance of whitespace (tabs, consecutive spaces)
3304
3315
into a single space; leading and trailing spaces are stripped */
3305
3316
mungspaces (buf );
0 commit comments