On Tue, 2009-04-21 at 13:53 +0900, Hiroshi Ito wrote:
> zw> Index: src/helper/jim.c
> zw> ===================================================================
> zw> --- src/helper/jim.c (revision 1478)
> zw> +++ src/helper/jim.c (working copy)
> zw> @@ -133,7 +133,8 @@
> zw> buf[sizeof(buf)-1] = 0;
> zw> #else
> zw> char *buf;
> int result;
>
> zw> - vasprintf( &buf, fmt, ap );
> zw> + int result = vasprintf( &buf, fmt, ap );
> result = vasprintf( &buf, fmt, ap );
>
> If you want to change, above is better to do.
> but it is not necessary to do.
Done, though it is not my wont; gcc/glibc put me up to it.
> zw> + if (result < 0) exit(-1);
> zw> #endif
> zw> return buf;
> zw> }
> 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!
Revised patch attached.
Thanks,
Zach
Index: src/helper/jim.c
===================================================================
--- src/helper/jim.c (revision 1478)
+++ src/helper/jim.c (working copy)
@@ -133,7 +133,9 @@
buf[sizeof(buf)-1] = 0;
#else
char *buf;
- vasprintf( &buf, fmt, ap );
+ int result;
+ result = vasprintf( &buf, fmt, ap );
+ if (result < 0) exit(-1);
#endif
return buf;
}
@@ -8953,7 +8955,7 @@
const int cwd_len=2048;
char *cwd=malloc(cwd_len);
Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
- getcwd( cwd, cwd_len );
+ if (!getcwd( cwd, cwd_len )) strcpy(cwd, "unknown");
Jim_AppendStrings(interp, Jim_GetResult(interp),
"Error loading script \"", filename, "\"",
" cwd: ", cwd,
_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development