[1857] in Moira

home help back first fref pref prev next nref lref last post

Re: don't allow strings with control characters

daemon@ATHENA.MIT.EDU (Robert A Basch)
Wed Aug 22 18:35:24 2001

Message-Id: <200108222235.SAA08144@anhedonia.mit.edu>
To: Garry Zacheiss <zacheiss@MIT.EDU>
cc: moiradev@MIT.EDU
In-Reply-To: Your message of "Wed, 22 Aug 2001 16:12:43 EDT."
             <200108222012.QAA23067@brad-majors.mit.edu> 
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Date: Wed, 22 Aug 2001 18:35:21 -0400
From: Robert A Basch <rbasch@MIT.EDU>

> +  ret = strdup(str);
> +  while (*++ret)
> +    {
> +      if (iscntrl(*ret))
> +	{
> +	  mrcl_set_message("STRING \"%s\" contains control characters, "
> +			   "which are not allowed.", str);
> +	  free(ret);
> +	  return MRCL_REJECT;
> +	}
> +    }

I don't see why you need to strdup()/free() at all, but you're not freeing
the pointer as returned from strdup() above, and not freeing at all when it
does not fail here.

Also, the "while (*++ret)" statement skips checking the first character
in the string.

You should #include <ctype.h> for iscntrl().

Bob


home help back first fref pref prev next nref lref last post