cvs commit: ALFS/nALFS/src/handlers remove.c textdump.c

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Mon Mar 1 22:54:11 PST 2004


kpfleming    04/03/01 23:54:11

  Modified:    nALFS/src/handlers remove.c textdump.c
  Log:
  ensure strtok usage is always on a temporary copy of data
  
  Revision  Changes    Path
  1.25      +4 -1      ALFS/nALFS/src/handlers/remove.c
  
  Index: remove.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/remove.c,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- remove.c	2 Mar 2004 06:17:50 -0000	1.24
  +++ remove.c	2 Mar 2004 06:54:11 -0000	1.25
  @@ -192,11 +192,13 @@
   	struct remove_data *data = (struct remove_data *) element->handler_data;
   	int status = 0;
   	char *tok;
  +	char *tmp;
          
   	if (change_current_dir("/"))
   		return -1;
   
  -	for (tok = strtok(data->content, WHITE_SPACE); tok; tok = strtok(NULL, WHITE_SPACE)) {
  +	tmp = xstrdup(data->content);
  +	for (tok = strtok(tmp, WHITE_SPACE); tok; tok = strtok(NULL, WHITE_SPACE)) {
   		Nprint_h("Removing %s.", tok);
   		warn_if_doesnt_exist(tok);
   		if ((status = execute_command(element, "rm -fr %s", tok))) {
  @@ -204,6 +206,7 @@
   			break;
   		}
   	}
  +	xfree(tmp);
   
   	return status;
   }
  
  
  
  1.23      +4 -1      ALFS/nALFS/src/handlers/textdump.c
  
  Index: textdump.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/textdump.c,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- textdump.c	2 Mar 2004 05:18:06 -0000	1.22
  +++ textdump.c	2 Mar 2004 06:54:11 -0000	1.23
  @@ -193,6 +193,7 @@
   	struct textdump_data *data = (struct textdump_data *) element->handler_data;
   	char *tok;
   	FILE *fp;
  +	char *tmp;
   
   	if (change_to_base_dir(element, data->base, 1))
   		return -1;
  @@ -211,9 +212,11 @@
   		return -1;
   	}
   
  -	for (tok = strtok(data->content, "\n"); tok; tok = strtok(NULL, "\n")) {
  +	tmp = xstrdup(data->content);
  +	for (tok = strtok(tmp, "\n"); tok; tok = strtok(NULL, "\n")) {
   		fprintf(fp, "%s\n", ++tok);
   	}
  +	xfree(tmp);
   
   	fclose(fp);
   	
  
  
  



More information about the alfs-log mailing list