[pkg-opensc-commit] [opensc] 20/295: added parameter checking to `sc_right_trim`

Eric Dorland eric at moszumanska.debian.org
Sat Jun 24 21:11:12 UTC 2017


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository opensc.

commit 050c62f7dfa0b6d76c0c57fbc0e41efba5864079
Author: Frank Morgner <frankmorgner at gmail.com>
Date:   Sun Jun 5 21:18:38 2016 +0200

    added parameter checking to `sc_right_trim`
    
    fixes conversion from 'size_t' to 'long', possible loss of data
---
 src/libopensc/sc.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/libopensc/sc.c b/src/libopensc/sc.c
index b4db30d..0dfe5c0 100644
--- a/src/libopensc/sc.c
+++ b/src/libopensc/sc.c
@@ -126,15 +126,20 @@ int sc_bin_to_hex(const u8 *in, size_t in_len, char *out, size_t out_len,
  */
 size_t sc_right_trim(u8 *buf, size_t len) {
 
-	long i;
+	size_t i;
+
+	if (!buf)
+		return 0;
 
-	for(i=len-1; i >=0; i--) {
-		if(!isprint(buf[i])) {
-			buf[i] = '\0';
-			len--;
-			continue;
+	if (len > 0) {
+		for(i = len-1; i > 0; i--) {
+			if(!isprint(buf[i])) {
+				buf[i] = '\0';
+				len--;
+				continue;
+			}
+			break;
 		}
-		break;
 	}
 	return len;
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/opensc.git



More information about the pkg-opensc-commit mailing list