On Tue, 2009-04-21 at 04:33 -0400, Chris Zimman wrote: > > > zw> @@ -8953,7 +8954,8 @@ > > > zw> const int cwd_len=2048; > > > zw> char *cwd=malloc(cwd_len); > > > zw> Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); > > > zw> - getcwd( cwd, cwd_len ); > > > zw> + cwd = getcwd( cwd, cwd_len ); > > > zw> + if (NULL == cwd) strcpy(cwd, "unknown"); > > > > > > this is bug. > > > when cwd is NULL, strcpy will cause segfault; > > > > > > if (! getcwd( cwd, cwd_len ) ) strcpy(cwd, "unknown"); > > > is better; > > > > *gasp* ... *blush* ... Done! > > Though technically correct, it is highly unlikely that if the first malloc() > failed that the equivalent call inside of getcwd() for the same length is > going to succeed. If malloc() fails for a sane size, it's usually pretty > much time to call it a day. > > I would propose: > > if(!cwd) > return JIM_ERROR; > > Because the call to Jim_AppendStrings() right after isn't going to be very > happy with a NULL cwd.
I am not an authority with the Jim code; I was simply trying to take defensive measures after finding myself berated by the compiler. My revised patch has already been committed, so a new patch is order. At this point, I would prefer it come from someone who knows the code. If you feel that could be you, then swing away. :) Cheers, Zach _______________________________________________ Openocd-development mailing list Openocd-development@lists.berlios.de https://lists.berlios.de/mailman/listinfo/openocd-development