zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Some more fixes for the attr module
Date: Sat, 7 Nov 2009 20:10:48 +0100	[thread overview]
Message-ID: <237967ef0911071110x7b95a7a0kba90923d0e1961c1@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 334 bytes --]

I ran clang 2.6 in analyze mode on zsh and it picked up some mistakes
I made with the error handling (patch attached). If anyone wants to
look at the rest i tarred up the reports and put them here, but most
of them are likely to be false positives (7.3MB packed)
http://mika.l3ib.org/zsh-clang-2009-11-06.tar.gz

-- 
Mikael Magnusson

[-- Attachment #2: 0001-attr-Fix-some-logic-errors-pointed-out-by-clang.patch --]
[-- Type: text/x-patch, Size: 2027 bytes --]

From: Mikael Magnusson <mikachu@gmail.com>
Date: Fri, 6 Nov 2009 23:40:10 +0100
Subject: [PATCH] attr: Fix some logic errors pointed out by clang

Three _len variables were checked when they were uninitialized
The case for returning 2 could never occur
---
 Src/Modules/attr.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/Src/Modules/attr.c b/Src/Modules/attr.c
index 7234862..a9e9949 100644
--- a/Src/Modules/attr.c
+++ b/Src/Modules/attr.c
@@ -98,7 +98,7 @@ static int
 bin_getattr(char *nam, char **argv, Options ops, UNUSED(int func))
 {
     int ret = 0;
-    int list_len, val_len, attr_len, slen;
+    int list_len, val_len = 0, attr_len = 0, slen;
     char *value, *file = argv[0], *attr = argv[1], *param = argv[2];
     int symlink = OPT_ISSET(ops, 'h');
 
@@ -125,9 +125,9 @@ bin_getattr(char *nam, char **argv, Options ops, UNUSED(int func))
             zfree(value, val_len+1);
         }
     }
-    if (list_len < 0 || val_len < 0 || attr_len < 0)  {
+    if (list_len < 0 || val_len < 0 || attr_len < 0 || attr_len > val_len)  {
         zwarnnam(nam, "%s: %e", metafy(file, slen, META_NOALLOC), errno);
-        ret = 1 + (attr_len > val_len);
+        ret = 1 + (attr_len > val_len || attr_len < 0);
     }
     return ret;
 }
@@ -172,7 +172,7 @@ static int
 bin_listattr(char *nam, char **argv, Options ops, UNUSED(int func))
 {
     int ret = 0;
-    int val_len, list_len, slen;
+    int val_len, list_len = 0, slen;
     char *value, *file = argv[0], *param = argv[1];
     int symlink = OPT_ISSET(ops, 'h');
 
@@ -214,9 +214,9 @@ bin_listattr(char *nam, char **argv, Options ops, UNUSED(int func))
         }
         zfree(value, val_len+1);
     }
-    if (val_len < 0 || list_len < 0) {
+    if (val_len < 0 || list_len < 0 || list_len > val_len) {
         zwarnnam(nam, "%s: %e", metafy(file, slen, META_NOALLOC), errno);
-        ret = 1 + (list_len > val_len);
+        ret = 1 + (list_len > val_len || list_len < 0);
     }
     return ret;
 }
-- 
1.6.5


                 reply	other threads:[~2009-11-07 19:10 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=237967ef0911071110x7b95a7a0kba90923d0e1961c1@mail.gmail.com \
    --to=mikachu@gmail.com \
    --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).