Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] Coverity: quad cannot escape its nature #13828

Closed
p5pRT opened this issue May 13, 2014 · 5 comments
Closed

[PATCH] Coverity: quad cannot escape its nature #13828

p5pRT opened this issue May 13, 2014 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented May 13, 2014

Migrated from rt.perl.org#121859 (status was 'resolved')

Searchable as RT121859$

@p5pRT
Copy link
Author

p5pRT commented May 13, 2014

From @jhi

A quad (or uquad) cannot be less than the (u)quad minimum or greater
than the (u)quad maximum.

Patch attached.

@p5pRT
Copy link
Author

p5pRT commented May 13, 2014

From @jhi

0001-Quad_t-and-Uquad_t-cannot-unpack-as-NVs.patch
From c669f8bd8f0851eff59d5c9551c6e0dda64f65a5 Mon Sep 17 00:00:00 2001
From: Jarkko Hietaniemi <jhi@iki.fi>
Date: Tue, 6 May 2014 12:50:55 -0400
Subject: [PATCH] Quad_t and Uquad_t cannot unpack as NVs.

If IVSIZE >= 8, a Quad_t is always >= IV_MIN, and <= IV_MAX, and an
Uquad_t is always (>= 0 aka UV_MIN and) <= UV_MAX; they cannot escape
their quadness and be NVs.  (This logic may fail if Quad_t is not 8
bytes, but then other things would no doubt fail.)

Also tighten the logic by adding HAS_QUAD, also for the pack case.

Fix for Coverity perl5 CID 28942.
---
 pp_pack.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/pp_pack.c b/pp_pack.c
index 3aa7a73..e4211b1 100644
--- a/pp_pack.c
+++ b/pp_pack.c
@@ -1632,14 +1632,13 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, const char *s, const char *strbeg, const c
 		PUSHs(newSVpvn_flags(aptr, len, SVs_TEMP));
 	    }
 	    break;
-#if IVSIZE >= 8
+#if defined(HAS_QUAD) && IVSIZE >= 8
 	case 'q':
 	    while (len-- > 0) {
 		Quad_t aquad;
                 SHIFT_VAR(utf8, s, strend, aquad, datumtype, needs_swap);
 		if (!checksum)
-                    mPUSHs(aquad >= IV_MIN && aquad <= IV_MAX ?
-			   newSViv((IV)aquad) : newSVnv((NV)aquad));
+                    mPUSHs(newSViv((IV)aquad));
 		else if (checksum > bits_in_uv)
 		    cdouble += (NV)aquad;
 		else
@@ -1651,8 +1650,7 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, const char *s, const char *strbeg, const c
 		Uquad_t auquad;
                 SHIFT_VAR(utf8, s, strend, auquad, datumtype, needs_swap);
 		if (!checksum)
-		    mPUSHs(auquad <= UV_MAX ?
-			   newSVuv((UV)auquad) : newSVnv((NV)auquad));
+		    mPUSHs(newSVuv((UV)auquad));
 		else if (checksum > bits_in_uv)
 		    cdouble += (NV)auquad;
 		else
@@ -2982,7 +2980,7 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist )
                 PUSH32(utf8, cur, &ai32, needs_swap);
 	    }
 	    break;
-#if IVSIZE >= 8
+#if defined(HAS_QUAD) && IVSIZE >= 8
 	case 'Q':
 	    while (len-- > 0) {
 		Uquad_t auquad;
-- 
1.9.2

@p5pRT
Copy link
Author

p5pRT commented May 29, 2014

From @tonycoz

On Tue May 13 08​:43​:36 2014, jhi wrote​:

A quad (or uquad) cannot be less than the (u)quad minimum or greater
than the (u)quad maximum.

Patch attached.

Thanks, applied as c174bf3.

Tony

@p5pRT
Copy link
Author

p5pRT commented May 29, 2014

The RT System itself - Status changed from 'new' to 'open'

@p5pRT p5pRT closed this as completed May 29, 2014
@p5pRT
Copy link
Author

p5pRT commented May 29, 2014

@tonycoz - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant