2002-02-20 21:31:14

by Ren

[permalink] [raw]
Subject: [PATCH] 2.5.4-dj3 fix some uses of strsep

Dave,

patch below fixes four cases where a s/strtok(/strsep(\&/ is not
sufficient to properly eliminate strtok. The problem arrises
because strsep modifies the pointer it is given while strtok did
not.

The atari file doesn't compile without this patch, because a char
array is mistreated as char pointer. The rest are cases where the
destroyed char pointer is used afterwards.

There may be more errors of that kind, I didn't check (yet). Patch
is untested but should make things "righter". ;)

Ren?



diff -ur linux-2.5.4-dj3/arch/alpha/kernel/setup.c linux/arch/alpha/kernel/setup.c
--- linux-2.5.4-dj3/arch/alpha/kernel/setup.c Wed Feb 20 20:01:21 2002
+++ linux/arch/alpha/kernel/setup.c Wed Feb 20 22:08:43 2002
@@ -472,6 +472,7 @@
struct percpu_struct *cpu;
char *type_name, *var_name, *p;
void *kernel_end = _end; /* end of kernel */
+ char *args = command_line;

hwrpb = (struct hwrpb_struct*) __va(INIT_HWRPB->phys_addr);
boot_cpuid = hard_smp_processor_id();
@@ -509,7 +510,7 @@
/*
* Process command-line arguments.
*/
- while ((p = strsep(&command_line, " \t")) != NULL) {
+ while ((p = strsep(&args, " \t")) != NULL) {
if (!*p) continue;
if (strncmp(p, "alpha_mv=", 9) == 0) {
vec = get_sysvec_byname(p+9);
diff -ur linux-2.5.4-dj3/arch/m68k/atari/config.c linux/arch/m68k/atari/config.c
--- linux-2.5.4-dj3/arch/m68k/atari/config.c Wed Feb 20 20:01:24 2002
+++ linux/arch/m68k/atari/config.c Wed Feb 20 22:06:51 2002
@@ -205,6 +205,7 @@
char switches[len+1];
char *p;
int ovsc_shift;
+ char *args = switches;

/* copy string to local array, strsep works destructively... */
strncpy( switches, str, len );
@@ -212,7 +213,7 @@
atari_switches = 0;

/* parse the options */
- while ((p = strsep(&switches, ",")) != NULL) {
+ while ((p = strsep(&args, ",")) != NULL) {
if (!*p) continue;
ovsc_shift = 0;
if (strncmp( p, "ov_", 3 ) == 0) {
diff -ur linux-2.5.4-dj3/fs/fat/inode.c linux/fs/fat/inode.c
--- linux-2.5.4-dj3/fs/fat/inode.c Wed Feb 20 20:02:11 2002
+++ linux/fs/fat/inode.c Wed Feb 20 22:02:34 2002
@@ -203,6 +203,7 @@
char *this_char,*value,save,*savep;
char *p;
int ret = 1, len;
+ char *args = options;

opts->name_check = 'n';
opts->conversion = 'b';
@@ -221,7 +222,7 @@
goto out;
save = 0;
savep = NULL;
- while ((this_char = strsep(&options,",")) != NULL) {
+ while ((this_char = strsep(&args,",")) != NULL) {
if ((value = strchr(this_char,'=')) != NULL) {
save = *value;
savep = value;
diff -ur linux-2.5.4-dj3/fs/vfat/namei.c linux/fs/vfat/namei.c
--- linux-2.5.4-dj3/fs/vfat/namei.c Wed Feb 20 20:02:15 2002
+++ linux/fs/vfat/namei.c Wed Feb 20 22:01:28 2002
@@ -99,6 +99,7 @@
{
char *this_char,*value,save,*savep;
int ret, val;
+ char *args = options;

opts->unicode_xlate = opts->posixfs = 0;
opts->numtail = 1;
@@ -115,7 +116,7 @@
save = 0;
savep = NULL;
ret = 1;
- while ((this_char = strsep(&options,",")) != NULL) {
+ while ((this_char = strsep(&args,",")) != NULL) {
if ((value = strchr(this_char,'=')) != NULL) {
save = *value;
savep = value;