Blame SOURCES/tree-static-analysis.patch

1c2cc5
From 48641275c0cd018441685f2d3145038017f1ea42 Mon Sep 17 00:00:00 2001
1c2cc5
From: Kamil Dudka <kdudka@redhat.com>
1c2cc5
Date: Tue, 6 Nov 2018 16:31:32 +0100
1c2cc5
Subject: [PATCH] tree: fix programming mistakes detected by static analysis
1c2cc5
1c2cc5
---
1c2cc5
 html.c |  5 +++--
1c2cc5
 json.c | 11 +++++------
1c2cc5
 tree.c |  2 +-
1c2cc5
 unix.c |  5 +++--
1c2cc5
 xml.c  | 11 +++++------
1c2cc5
 5 files changed, 17 insertions(+), 17 deletions(-)
1c2cc5
1c2cc5
diff --git a/html.c b/html.c
1c2cc5
index 75e2ed1..35fb525 100644
1c2cc5
--- a/html.c
1c2cc5
+++ b/html.c
1c2cc5
@@ -221,7 +221,7 @@ off_t html_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
1c2cc5
 	    if (*(*dir)->lnk == '/')
1c2cc5
 	      listdir((*dir)->lnk,dt,ft,lev+1,dev);
1c2cc5
 	    else {
1c2cc5
-	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->name)+1024));
1c2cc5
+	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->lnk)+1024));
1c2cc5
 	      if (fflag && !strcmp(d,"/")) sprintf(path,"%s%s",d,(*dir)->lnk);
1c2cc5
 	      else sprintf(path,"%s/%s",d,(*dir)->lnk);
1c2cc5
 	      listdir(path,dt,ft,lev+1,dev);
1c2cc5
@@ -254,7 +254,7 @@ off_t html_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
1c2cc5
 {
1c2cc5
   struct _info **dir;
1c2cc5
   off_t size = 0;
1c2cc5
-  char *err;
1c2cc5
+  char *err = NULL;
1c2cc5
   
1c2cc5
   dir = getfulltree(d, lev, dev, &size, &err;;
1c2cc5
   
1c2cc5
@@ -262,6 +262,7 @@ off_t html_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
1c2cc5
   
1c2cc5
   htmlr_listdir(dir, d, dt, ft, lev);
1c2cc5
   
1c2cc5
+  free(err);
1c2cc5
   return size;
1c2cc5
 }
1c2cc5
 
1c2cc5
diff --git a/json.c b/json.c
1c2cc5
index 4b15e0d..8c71324 100644
1c2cc5
--- a/json.c
1c2cc5
+++ b/json.c
1c2cc5
@@ -98,8 +98,7 @@ off_t json_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
1c2cc5
   while(*dir) {
1c2cc5
     if (!noindent) json_indent(lev);
1c2cc5
 
1c2cc5
-    if ((*dir)->lnk) mt = (*dir)->mode & S_IFMT;
1c2cc5
-    else mt = (*dir)->mode & S_IFMT;
1c2cc5
+    mt = (*dir)->mode & S_IFMT;
1c2cc5
     for(t=0;ifmt[t];t++)
1c2cc5
       if (ifmt[t] == mt) break;
1c2cc5
     fprintf(outfile,"{\"type\":\"%s\"", ftype[t]);
1c2cc5
@@ -141,7 +140,7 @@ off_t json_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
1c2cc5
 	    if (*(*dir)->lnk == '/')
1c2cc5
 	      listdir((*dir)->lnk,dt,ft,lev+1,dev);
1c2cc5
 	    else {
1c2cc5
-	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->name)+1024));
1c2cc5
+	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->lnk)+1024));
1c2cc5
 	      if (fflag && !strcmp(d,"/")) sprintf(path,"%s%s",d,(*dir)->lnk);
1c2cc5
 	      else sprintf(path,"%s/%s",d,(*dir)->lnk);
1c2cc5
 	      listdir(path,dt,ft,lev+1,dev);
1c2cc5
@@ -181,7 +180,7 @@ off_t json_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
1c2cc5
 {
1c2cc5
   struct _info **dir;
1c2cc5
   off_t size = 0;
1c2cc5
-  char *err;
1c2cc5
+  char *err = NULL;
1c2cc5
 
1c2cc5
   dir = getfulltree(d, lev, dev, &size, &err;;
1c2cc5
 
1c2cc5
@@ -189,6 +188,7 @@ off_t json_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
1c2cc5
 
1c2cc5
   jsonr_listdir(dir, d, dt, ft, lev);
1c2cc5
 
1c2cc5
+  free(err);
1c2cc5
   return size;
1c2cc5
 }
1c2cc5
 
1c2cc5
@@ -211,8 +211,7 @@ void jsonr_listdir(struct _info **dir, char *d, int *dt, int *ft, u_long lev)
1c2cc5
   while(*dir) {
1c2cc5
     if (!noindent) json_indent(lev);
1c2cc5
 
1c2cc5
-    if ((*dir)->lnk) mt = (*dir)->mode & S_IFMT;
1c2cc5
-    else mt = (*dir)->mode & S_IFMT;
1c2cc5
+    mt = (*dir)->mode & S_IFMT;
1c2cc5
     for(t=0;ifmt[t];t++)
1c2cc5
       if (ifmt[t] == mt) break;
1c2cc5
     fprintf(outfile,"{\"type\":\"%s\"", ftype[t]);
1c2cc5
diff --git a/tree.c b/tree.c
1c2cc5
index 03140fe..73dd101 100644
1c2cc5
--- a/tree.c
1c2cc5
+++ b/tree.c
1c2cc5
@@ -882,7 +882,7 @@ struct _info **unix_getfulltree(char *d, u_long lev, dev_t dev, off_t *size, cha
1c2cc5
 	    if (*(*dir)->lnk == '/')
1c2cc5
 	      (*dir)->child = unix_getfulltree((*dir)->lnk,lev+1,dev,&((*dir)->size),&((*dir)->err));
1c2cc5
 	    else {
1c2cc5
-	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->name)+1024));
1c2cc5
+	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->lnk)+1024));
1c2cc5
 	      if (fflag && !strcmp(d,"/")) sprintf(path,"%s%s",d,(*dir)->lnk);
1c2cc5
 	      else sprintf(path,"%s/%s",d,(*dir)->lnk);
1c2cc5
 	      (*dir)->child = unix_getfulltree(path,lev+1,dev,&((*dir)->size),&((*dir)->err));
1c2cc5
diff --git a/unix.c b/unix.c
1c2cc5
index ca5f76f..9476307 100644
1c2cc5
--- a/unix.c
1c2cc5
+++ b/unix.c
1c2cc5
@@ -129,7 +129,7 @@ off_t unix_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
1c2cc5
 	    if (*(*dir)->lnk == '/')
1c2cc5
 	      listdir((*dir)->lnk,dt,ft,lev+1,dev);
1c2cc5
 	    else {
1c2cc5
-	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->name)+1024));
1c2cc5
+	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->lnk)+1024));
1c2cc5
 	      if (fflag && !strcmp(d,"/")) sprintf(path,"%s%s",d,(*dir)->lnk);
1c2cc5
 	      else sprintf(path,"%s/%s",d,(*dir)->lnk);
1c2cc5
 	      listdir(path,dt,ft,lev+1,dev);
1c2cc5
@@ -162,7 +162,7 @@ off_t unix_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
1c2cc5
 {
1c2cc5
   struct _info **dir;
1c2cc5
   off_t size = 0;
1c2cc5
-  char *err;
1c2cc5
+  char *err = NULL;
1c2cc5
   
1c2cc5
   dir = getfulltree(d, lev, dev, &size, &err;;
1c2cc5
 
1c2cc5
@@ -170,6 +170,7 @@ off_t unix_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
1c2cc5
 
1c2cc5
   r_listdir(dir, d, dt, ft, lev);
1c2cc5
 
1c2cc5
+  free(err);
1c2cc5
   return size;
1c2cc5
 }
1c2cc5
 
1c2cc5
diff --git a/xml.c b/xml.c
1c2cc5
index 32f3c0c..512eed7 100644
1c2cc5
--- a/xml.c
1c2cc5
+++ b/xml.c
1c2cc5
@@ -106,8 +106,7 @@ off_t xml_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
1c2cc5
   while(*dir) {
1c2cc5
     if (!noindent) xml_indent(lev);
1c2cc5
 
1c2cc5
-    if ((*dir)->lnk) mt = (*dir)->mode & S_IFMT;
1c2cc5
-    else mt = (*dir)->mode & S_IFMT;
1c2cc5
+    mt = (*dir)->mode & S_IFMT;
1c2cc5
     for(t=0;ifmt[t];t++)
1c2cc5
       if (ifmt[t] == mt) break;
1c2cc5
     fprintf(outfile,"<%s", ftype[t]);
1c2cc5
@@ -145,7 +144,7 @@ off_t xml_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
1c2cc5
 	    if (*(*dir)->lnk == '/')
1c2cc5
 	      listdir((*dir)->lnk,dt,ft,lev+1,dev);
1c2cc5
 	    else {
1c2cc5
-	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->name)+1024));
1c2cc5
+	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->lnk)+1024));
1c2cc5
 	      if (fflag && !strcmp(d,"/")) sprintf(path,"%s%s",d,(*dir)->lnk);
1c2cc5
 	      else sprintf(path,"%s/%s",d,(*dir)->lnk);
1c2cc5
 	      listdir(path,dt,ft,lev+1,dev);
1c2cc5
@@ -181,7 +180,7 @@ off_t xml_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
1c2cc5
 {
1c2cc5
   struct _info **dir;
1c2cc5
   off_t size = 0;
1c2cc5
-  char *err;
1c2cc5
+  char *err = NULL;
1c2cc5
   
1c2cc5
   dir = getfulltree(d, lev, dev, &size, &err;;
1c2cc5
   
1c2cc5
@@ -189,6 +188,7 @@ off_t xml_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
1c2cc5
   
1c2cc5
   xmlr_listdir(dir, d, dt, ft, lev);
1c2cc5
   
1c2cc5
+  free(err);
1c2cc5
   return size;
1c2cc5
 }
1c2cc5
 
1c2cc5
@@ -211,8 +211,7 @@ void xmlr_listdir(struct _info **dir, char *d, int *dt, int *ft, u_long lev)
1c2cc5
   while(*dir) {
1c2cc5
     if (!noindent) xml_indent(lev);
1c2cc5
 
1c2cc5
-    if ((*dir)->lnk) mt = (*dir)->mode & S_IFMT;
1c2cc5
-    else mt = (*dir)->mode & S_IFMT;
1c2cc5
+    mt = (*dir)->mode & S_IFMT;
1c2cc5
     for(t=0;ifmt[t];t++)
1c2cc5
       if (ifmt[t] == mt) break;
1c2cc5
     fprintf(outfile,"<%s", ftype[t]);
1c2cc5
-- 
1c2cc5
2.17.2
1c2cc5