@@ -2309,10 +2309,14 @@ char *origbuf;
23092309 int len ;
23102310 boolean retval = TRUE;
23112311
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 */
23122316 /* convert any tab to space, condense consecutive spaces into one,
23132317 remove leading and trailing spaces (exception: if there is nothing
23142318 but spaces, one of them will be kept even though it leads/trails) */
2315- mungspaces (strcpy ( buf , origbuf ) );
2319+ mungspaces (buf );
23162320
23172321 /* find the '=' or ':' */
23182322 bufp = find_optparam (buf );
@@ -3034,7 +3038,11 @@ boolean
30343038proc_wizkit_line (buf )
30353039char * buf ;
30363040{
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 );
30383046
30393047 if (otmp ) {
30403048 if (otmp != & zeroobj )
@@ -3142,22 +3150,23 @@ boolean FDECL((*proc), (char *));
31423150
31433151 /* merge now read line with previous ones, if necessary */
31443152 if (!ignoreline ) {
3145- len = (int ) strlen (inbuf ) + 1 ;
3153+ len = (int ) strlen (ep ) + 1 ; /* +1: final '\0' */
31463154 if (buf )
3147- len += (int ) strlen (buf );
3155+ len += (int ) strlen (buf ) + 1 ; /* +1: space */
31483156 tmpbuf = (char * ) alloc (len );
3157+ * tmpbuf = '\0' ;
31493158 if (buf ) {
3150- Sprintf ( tmpbuf , "%s %s" , buf , inbuf );
3159+ Strcat ( strcpy ( tmpbuf , buf ), " " );
31513160 free (buf );
3152- } else
3153- Strcpy (tmpbuf , inbuf );
3154- buf = tmpbuf ;
3161+ }
3162+ buf = strcat (tmpbuf , ep );
3163+ buf [ sizeof inbuf - 1 ] = '\0' ;
31553164 }
31563165
31573166 if (morelines || (ignoreline && !oldline ))
31583167 continue ;
31593168
3160- if (handle_config_section (ep )) {
3169+ if (handle_config_section (buf )) {
31613170 free (buf );
31623171 buf = (char * ) 0 ;
31633172 continue ;
@@ -3179,11 +3188,11 @@ boolean FDECL((*proc), (char *));
31793188 }
31803189 bufp ++ ;
31813190 if (config_section_chosen )
3182- free (config_section_chosen );
3191+ free (config_section_chosen ), config_section_chosen = 0 ;
31833192 section = choose_random_part (bufp , ',' );
3184- if (section )
3193+ if (section ) {
31853194 config_section_chosen = dupstr (section );
3186- else {
3195+ } else {
31873196 config_error_add ("No config section to choose" );
31883197 rv = FALSE;
31893198 }
@@ -3300,6 +3309,8 @@ int which_set;
33003309 struct symparse * symp ;
33013310 char * bufp , * commentp , * altp ;
33023311
3312+ if (strlen (buf ) >= BUFSZ )
3313+ buf [BUFSZ - 1 ] = '\0' ;
33033314 /* convert each instance of whitespace (tabs, consecutive spaces)
33043315 into a single space; leading and trailing spaces are stripped */
33053316 mungspaces (buf );
0 commit comments