zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh workers <zsh-workers@zsh.org>
Subject: PATCH: allow for atoi() returning a negative number
Date: Wed, 15 May 2019 23:55:54 +0200	[thread overview]
Message-ID: <76181-1557957354.693068@l7O-.SUn1.6KOq> (raw)

Given that a couple of the issues from fuzzing the shell amounted
to not allowing for atoi() returning a negative number when given
a number bigger than 2**31, I thought it would be worth checking
for other cases. This patch handles two cases: a width field in
strftime output of nanoseconds and the width for parameters.

For the parameter width, this is fairly minimal in that there are
further variables that perhaps ought to be unsigned (or size_t).
Such changes have a tendency to cascade. This is enough that it
doesn't crash while doing the 2G of padding. I'd actually have
thought an unsigned short would be sufficient for the width (and
base) in struct param.

Oliver

diff --git a/Src/exec.c b/Src/exec.c
index 6ac852112..60ab0acf8 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2535,7 +2535,7 @@ setunderscore(char *str)
 {
     queue_signals();
     if (str && *str) {
-	int l = strlen(str) + 1, nl = (l + 31) & ~31;
+	size_t l = strlen(str) + 1, nl = (l + 31) & ~31;
 
 	if (nl > underscorelen || (underscorelen - nl) > 64) {
 	    zfree(zunderscore, underscorelen);
diff --git a/Src/init.c b/Src/init.c
index 2d5c3296d..445cd3937 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -45,7 +45,10 @@ int noexitct = 0;
 char *zunderscore;
 
 /**/
-int underscorelen, underscoreused;
+size_t underscorelen;
+
+/**/
+int underscoreused;
 
 /* what level of sourcing we are at */
  
diff --git a/Src/params.c b/Src/params.c
index df031ab64..1859c7c12 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2201,10 +2201,10 @@ getstrvalue(Value v)
 
     if (v->flags & VALFLAG_SUBST) {
 	if (v->pm->node.flags & (PM_LEFT|PM_RIGHT_B|PM_RIGHT_Z)) {
-	    unsigned int fwidth = v->pm->width ? v->pm->width : MB_METASTRLEN(s);
+	    size_t fwidth = v->pm->width ? (unsigned int)v->pm->width : MB_METASTRLEN(s);
 	    switch (v->pm->node.flags & (PM_LEFT | PM_RIGHT_B | PM_RIGHT_Z)) {
 		char *t, *tend;
-		unsigned int t0;
+		size_t t0;
 
 	    case PM_LEFT:
 	    case PM_LEFT | PM_RIGHT_Z:
@@ -5858,7 +5858,7 @@ printparamnode(HashNode hn, int printflags)
 		    doneminus = 0;
 		}
 		if ((pmptr->flags & PMTF_USE_WIDTH) && p->width) {
-		    printf("%d ", p->width);
+		    printf("%u ", p->width);
 		    doneminus = 0;
 		}
 	    }
diff --git a/Src/utils.c b/Src/utils.c
index 32f600858..46cf7bcf6 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -3336,7 +3336,7 @@ morefmt:
 	    case '.':
 	    {
 		long fnsec = nsec;
-		if (digs > 9)
+		if (digs < 0 || digs > 9)
 		    digs = 9;
 		if (ztrftimebuf(&bufsize, digs))
 		    return -1;

                 reply	other threads:[~2019-05-15 21:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=76181-1557957354.693068@l7O-.SUn1.6KOq \
    --to=okiddle@yahoo.co.uk \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).