Closed Bug 8112 Opened 27 years ago Closed 25 years ago

Lack of thread-safety with JS Math routines

Categories

(Core :: JavaScript Engine, defect, P3)

x86
Windows NT
defect

Tracking

()

VERIFIED FIXED
mozilla0.9

People

(Reporter: fur, Assigned: beard)

References

Details

Attachments

(2 files)

The variable 'errno' is not protected against thread races even when JS_THREADSAFE is defined. errno is used in jsnum.c, jsdtoa.c, and fdlibm/*.c. This might cause Math errors on one thread to be inappropriately visible to another thread.
Severity: normal → minor
*** Bug 7066 has been marked as a duplicate of this bug. ***
Status: NEW → ASSIGNED
Assignee: fur → mccabe
Status: ASSIGNED → NEW
mang ducked out on this bug and gave it to me - it looks like you inherit it now
Ducking out as well. Roger, you're the lucky one.
Assignee: mccabe → rogerl
Setting all Javacript bugs to rginda QA Contact.
QA Contact: cbegle → rginda
Reassigning to Patrick as per meeting -
Assignee: rogerl → beard
Status: NEW → ASSIGNED
QA Contact: rginda → pschwartau
Reassigning to mitesh.
Assignee: beard → mitesh
Status: ASSIGNED → NEW
In jsnum.c, the variable 'errno' is used to check the overflow during the js_strtod call. Instead of using the global variable we can pass a variable to the function JS_strtod (defined in jsdtoa.c line: 1079). Since it's JS_FRIEND_API function, does anyone think that we can change the function interface?
Status: NEW → ASSIGNED
As per the discussions, JS_strdtoa is JS_FRIEND_API so we can add one parameter to rport overflow and get rid of global variable errno altogether. Regarding k_standard.c, instead of reporting error through errno, we can use use fputs to communicate the error to the user. Now the only place remaining is jsscan.c where we report an error encounterd during fopen call using the errno. In the worst case, the error reported would not be true (if another thread sets the errno to some different value). I recommend, instead of using the strerror(errno), we can put a static string "No such file of directory" message.
> Regarding k_standard.c, instead of reporting error through errno, > we can use use fputs to communicate the error to the user. I don't think this is appropriate for an embedded engine; it would be best to communicate failure through the calling mechanism and let the caller work around it or register a javascript exception. Using a static string in the file case sounds fine to me.
That's a good suggestion. Which is basically the same solution as jsnum.c. Patrick also suggested the same way. Callers of __kernel_standard function are not actually checking the return value of errno but the changes will be helpful in the future if it is required.
Retargeting to 0.8.1.
Assignee: mitesh → rginda
Status: ASSIGNED → NEW
Target Milestone: --- → mozilla0.8.1
Target Milestone: mozilla0.8.1 → mozilla0.9
I think this missed the 0.8.1 train. lets to it early in 0.9
Let's get some reviewers, it's a really simple change.
Some funky indentation (tab expansion? good if so) and stylistic violations (int err=0; is not how JS code initializes vars -- spaces on each side of = are more the ticket). Other than that, looks good to me. Who will check this in? /be
I would be happy to clean up and check in the patch.
OK, I think you have r=beard and sr=me on mitesh's patch, with cleanups. /be
Fix checked in.
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
Marking Verified -
Status: RESOLVED → VERIFIED
Strange: I can compile the JS shell on WinNT now, but not on Linux: gcc -o Linux_All_DBG.OBJ/k_standard.o -c -Wall -Wno-format -DGCC_OPT_BUG -DXP_UNIX -g -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DX86_LINUX -DDEBUG -DDEBUG_pschwartau -I.. -I../Linux_All_DBG.OBJ -DJSFILE -D_IEEE_LIBM k_standard.c k_standard.c:125: conflicting types for `__kernel_standard' fdlibm.h:264: previous declaration of `__kernel_standard' make[1]: *** [Linux_All_DBG.OBJ/k_standard.o] Error 1 make[1]: Leaving directory `/data/phil/JS_TRUNK/mozilla/js/src/fdlibm' make: *** [all] Error 2 In js/src/fdlibm/k_standard.c ------------------------------------------------------------------ #ifdef __STDC__ double __kernel_standard(double x, double y, int type) #else double __kernel_standard(x,y,type) double x,y; int type; #endif ------------------------------------------------------------------ In js/src/fdlibm/fdlibm.h ------------------------------------------------------------------ /* fdlibm kernel function */ extern double __kernel_standard __P((double,double,int)); ------------------------------------------------------------------ I'm running egcs-2.91.66. I've had weird problems lately compiling on my Linux box lately. Is that the likely cause here, or is gcc right to error on this?
I'm seeing the same problem, and it sure looks like a bug to me. I can't understand how the tinderboxes don't see it. Can we get a fix for this? (Reopening.)
Status: VERIFIED → REOPENED
Resolution: FIXED → ---
Index: fdlibm.h =================================================================== RCS file: /cvsroot/mozilla/js/src/fdlibm/fdlibm.h,v retrieving revision 1.8 diff -u -r1.8 fdlibm.h --- fdlibm.h 2001/03/09 04:07:15 1.8 +++ fdlibm.h 2001/04/19 15:20:27 @@ -261,7 +261,7 @@ #endif /* fdlibm kernel function */ -extern double __kernel_standard __P((double,double,int)); +extern double __kernel_standard __P((double,double,int,int *)); extern double __kernel_sin __P((double,double,int)); extern double __kernel_cos __P((double,double)); extern double __kernel_tan __P((double,double,int)); This WORKSFORME. For 0.9 to fix a build blocker? Please?
Keywords: mozilla0.9
Yes, let's fix this in the trunk, now (0.9). I failed to test the patches here. Beard, how did this work on any platform? OTOH, k_standard.c doesn't seem to be compiled when I build js as part of Mozilla. It's in fdlibm/Makefile.ref's list of C source files, but not in fdlibm/Makefile.in's list. So this seems to be only a JSRef issue. /be
Assignee: rginda → beard
Status: REOPENED → NEW
This patch looks good. I verified that Makefile.ref builds with it. r=beard
sr=brendan@mozilla.org (nit: no space between int and * in that final parameter type, to match the ugly prevailing style). I think I can a= this too, it should not affect non-ref builds. I'll just check it in, if that's ok with everyone. /be
I agree, check it in.
Fix is in. /be
Status: NEW → RESOLVED
Closed: 25 years ago25 years ago
Resolution: --- → FIXED
Verified - I can now compile the JS shell on both WinNT and Linux.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: