From: Paul Wankadia Subject: problems in daemon/lookup.c Date: Tue, 20 Jan 2009 16:48:50 +1100 Message-ID: <408431290901192148idf9499xe12e58fb2b36a975@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============8238147250629707282==" Return-path: List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: autofs-bounces@linux.kernel.org Errors-To: autofs-bounces@linux.kernel.org To: Ian Kent Cc: autofs@linux.kernel.org --===============8238147250629707282== Content-Type: multipart/alternative; boundary=001485f02570f952d00460e3972a --001485f02570f952d00460e3972a Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit A friend of mine was kind enough to run some analysis for me. A couple of problems jumped out immediately. 991 static char *make_fullpath(const char *root, const char *key) ... 1000 path = malloc(l); 1001 strcpy(path, key); ... 1006 path = malloc(l); 1007 sprintf(path, "%s/%s", root, key); Those are unchecked malloc(3) calls. How would you prefer to handle failures? 1012 int lookup_prune_cache(struct autofs_point *ap, time_t age) ... 1075 cache_unlock(mc); 1076 free(key); 1077 if (next_key) 1078 free(next_key); 1079 free(path); 1080 goto next; ... 1103 next: 1104 cache_readlock(mc); 1105 me = cache_lookup_distinct(mc, next_key); 1106 free(key); 1107 free(path); 1108 free(next_key); Those are double free(3) calls. Oh, and `next_key' is used after being freed. --001485f02570f952d00460e3972a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable A friend of mine was kind enough to run some analysis for me. A couple of p= roblems jumped out immediately.


    991 static ch= ar *make_fullpath(const char *root, const char *key)
...
  = 1000           &nbs= p;     path =3D malloc(l);
   1001         &nbs= p;       strcpy(path, key);
...
 &= nbsp; 1006           = ;      path =3D malloc(l);
   1007&nb= sp;            =     sprintf(path, "%s/%s", root, key);

Thos= e are unchecked malloc(3) calls. How would you prefer to handle failures?

   1012 int lookup_prune_cache(struct autofs_point *ap, t= ime_t age)
...
   1075      &= nbsp;           &nbs= p;            &= nbsp; cache_unlock(mc);
   1076     &= nbsp;           &nbs= p;            &= nbsp;  free(key);
   1077     &n= bsp;            = ;            &n= bsp;  if (next_key)
   1078         &nbs= p;            &= nbsp;           &nbs= p;      free(next_key);
   1079 =             &nb= sp;            =        free(path);
   1080 =             &nb= sp;            =        goto next;
...
   1103= next:
   1104        =             &nb= sp;    cache_readlock(mc);
   1105         &nbs= p;            &= nbsp;  me =3D cache_lookup_distinct(mc, next_key);
   110= 6            &n= bsp;            free= (key);
   1107        =             &nb= sp;    free(path);
   1108   &nb= sp;            =          free(next_key);

Those are double free(3) calls. Oh, and `next_key' is used after be= ing freed.
--001485f02570f952d00460e3972a-- --===============8238147250629707282== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ autofs mailing list autofs@linux.kernel.org http://linux.kernel.org/mailman/listinfo/autofs --===============8238147250629707282==--