problems in daemon/lookup.c
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.
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
Ian Kent
maintainerQuoted 28 lines · Paul Wankadia
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:
1104cache_readlock(mc);
1105 me = cache_lookup_distinct(mc,
Quoted 7 lines
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.
Thanks, I'll fix these.
Ian
Ian Kent
maintainerQuoted 34 lines · Ian Kent
Quoted 33 lines · Paul Wankadia
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:
1104cache_readlock(mc);
1105 me = cache_lookup_distinct(mc,next_key); 1106 free(key); 1107 free(path); 1108 free(next_key);
Quoted 4 lines
Quoted 2 lines
Those are double free(3) calls. Oh, and `next_key' is used after being freed.
Thanks, I'll fix these.
Fortunately, these cases usually don't happen so we haven't seen a problem with it already.
Anyway, i think this is all we need although continuing after an malloc fail is a bit questionable. Suggestions?
autofs-5.0.4 - couple of lookup.c corrections
From: Ian Kent <[email protected]>
A couple of mistakes in lookup.c were reported:
- a malloc(3) allocation return was not being checked in make_fullpath().
- a double free and a use after free was identified in lookup_prune_cache().
---
daemon/lookup.c | 20 ++++++++------------ 1 files changed, 8 insertions(+), 12 deletions(-)
daemon/lookup.c +8 -12
@@ -998,12 +998,16 @@ static char *make_fullpath(const char *root, const char *key)if (l >KEY_MAX_LEN )return NULL ; path =malloc (l); +if (!path) +return NULL ;strcpy (path, key); }else { l =strlen (key) +1 +strlen (root) +1 ;if (l >KEY_MAX_LEN )return NULL ; path =malloc (l); +if (!path) +return NULL ;sprintf (path,"%s/%s" , root, key); }return path;
@@ -1073,10 +1077,6 @@ int lookup_prune_cache(struct autofs_point *ap, time_t age) this =cache_lookup_distinct (mc, key);if (!this) {cache_unlock (mc); -free (key); -if (next_key) -free (next_key); -free (path); goto next; }
@@ -1094,18 +1094,14 @@ int lookup_prune_cache(struct autofs_point *ap, time_t age) }cache_unlock (mc); -if (!next_key) { -free (key); -free (path); -cache_readlock (mc); -continue ; - } next:cache_readlock (mc); - me =cache_lookup_distinct (mc, next_key); +if (next_key) { + me =cache_lookup_distinct (mc, next_key); +free (next_key); + }free (key);free (path); -free (next_key); }pthread_cleanup_pop (1 ); map->stale =0 ;
On Wed, Jan 21, 2009 at 2:49 PM, Ian Kent <[email protected]> wrote:
Fortunately, these cases usually don't happen so we haven't seen a
Quoted 4 lines
problem with it already.
Anyway, i think this is all we need although continuing after an malloc fail is a bit questionable. Suggestions?
In this case, make_fullpath() is called from only one place and its return value is checked, but I was asking in general, yes.
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
Ian Kent
maintainerQuoted 6 lines · Paul Wankadia
On Wed, Jan 21, 2009 at 2:49 PM, Ian Kent <[email protected]> wrote:
Fortunately, these cases usually don't happen so we haven't seen a
problem with it already.
Quoted 6 lines
Anyway, i think this is all we need although continuing after an malloc
fail is a bit questionable. Suggestions?In this case,
make_fullpath()is called from only one place and its return value is checked, but I was asking in general, yes.
Not sure I understand the question.
Functions like make_fullpath() need to return a NULL in such a case because it has to be up to the caller to decide on how to handle the fail.
In the case above it is questionable whether we continue the prune but then another thread could free() heap memory so we might still be able to make some useful progress.
Ian
Quoted 5 lines · Ian Kent
In this case,
make_fullpath()is called from only one place and itsQuoted 1 line
return value is checked, but I was asking in general, yes.
Not sure I understand the question.
Quoted 7 lines
Functions like
make_fullpath()need to return a NULL in such a case because it has to be up to the caller to decide on how to handle the fail.In the case above it is questionable whether we continue the prune but then another thread could
free()heap memory so we might still be able to make some useful progress.
A daemon shouldn't run out of memory. Generally speaking, it's an exceptional condition that justifies abnormal termination.
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
Ian Kent
maintainerQuoted 16 lines · Paul Wankadia
On Wed, Jan 21, 2009 at 4:29 PM, Ian Kent <[email protected]> wrote:
> In this case,
make_fullpath()is called from only one place and its
> return value is checked, but I was asking in general, yes.Not sure I understand the question.
Functions like
make_fullpath()need to return a NULL in such a case
because it has to be up to the caller to decide on how to handle the
fail.
Quoted 8 lines
In the case above it is questionable whether we continue the prune but
then another thread couldfree()heap memory so we might still be able
to make some useful progress.A daemon shouldn't run out of memory. Generally speaking, it's an exceptional condition that justifies abnormal termination.
Don't think it being a daemon makes any difference?
I'm not entirely sure how this works but I thought that modified pages are written to swap. If swap fills up I think alocs can fail even though heap is available. If that is then fixed by external intervention the alocs could then succeed. So, maybe termination isn't the right chioce here. In any case it should be evident from the log that the situation exists and the admin can decide what action to take. OTOH if heap is really exhausted then termination probably is the right choice.
In any case I prefer to try and continue.
Ian
Quoted 13 lines · Ian Kent
A daemon shouldn't run out of memory. Generally speaking, it's an
Quoted 1 line
exceptional condition that justifies abnormal termination.
Don't think it being a daemon makes any difference?
I'm not entirely sure how this works but I thought that modified pages are written to swap. If swap fills up I think alocs can fail even though heap is available. If that is then fixed by external intervention the alocs could then succeed. So, maybe termination isn't the right chioce here. In any case it should be evident from the log that the situation exists and the admin can decide what action to take. OTOH if heap is really exhausted then termination probably is the right choice.
Quoted 1 line
In any case I prefer to try and continue.
Sorry, I just don't understand why that's the right thing to do. If a daemon can't allocate memory in order to perform the operations that it needs to perform, then how can it provide the functionality that it's expected to provide? Why should it continue indefinitely instead of aborting and being restarted automatically?
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
BTW, I'm still working through the analysis results. A few more problems have turned up.
modules/lookup_hosts.c:
119 int lookup_mount(struct autofs_point *ap, const char *name, intname_len, void *context)
...
146 if (!me->mapent) {
147 cache_delete(me->mc, name);
148 me = NULL;
149 }
150
151 cache_unlock(me->mc);That is a NULL pointer dereference.
lib/macros.c:
163 int macro_parse_globalvar(const char *define)
164 {
165 char buf[MAX_MACRO_STRING];
166 char *pbuf, *value;
167
168 if (strlen(define) > MAX_MACRO_STRING)
169 return 0;
170
171 strcpy(buf, define);That is a buffer overflow.
modules/parse_hesiod.c:
84 static int parse_nfs(struct autofs_point *ap,
...
108 for (i = 0; (!isspace(p[i]) && i < (int) sizeof(mount));
i++) {
109 mount[i] = p[i];
110 }
111
112 mount[i] = 0;
113 p += i;That is a buffer overflow. There are six more loops with similar problems.
daemon/indirect.c:
86 static int do_mount_autofs_indirect(struct autofs_point *ap, const
char *root)
...
160 free(options);
161
162 ret = stat(root, &st);
163 if (ret == -1) {
164 crit(ap->logopt,
165 "failed to stat mount for autofs path %s",
ap->path);
166 goto out_umount;
167 }
...
185 out_umount:
186 umount(root);
187 out_rmdir:
188 if (ap->flags & MOUNT_FLAG_DIR_CREATED)
189 rmdir(root);
190 out_err:
191 if (options)
192 free(options);That is a double free(3) call.
lib/cache.c:
180 struct mapent_cache *cache_init(struct autofs_point *ap, structmap_source *map)
...
195 mc->hash = malloc(mc->size * sizeof(struct entry *));
...
231 struct mapent_cache *cache_init_null_cache(struct master *master)
...
246 mc->hash = malloc(mc->size * sizeof(struct entry *));`struct mapent *' might be more correct. ;)
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
Ian Kent
maintainerQuoted 2 lines · Paul Wankadia
BTW, I'm still working through the analysis results. A few more problems have turned up.
Yeah, I can't see for looking.
Keep'em coming.
Quoted 83 lines
modules/lookup_hosts.c:
119 int lookup_mount(structautofs_point*ap, const char *name,
intname_len, void *context)
...146 if (!me->mapent) { 147 cache_delete(me->mc, name); 148 me = NULL; 149 } 150 151 cache_unlock(me->mc);That is a NULL pointer dereference.
lib/macros.c:163 int macro_parse_globalvar(const char *define) 164 { 165 char buf[MAX_MACRO_STRING]; 166 char *pbuf, *value; 167 168 if (strlen(define) > MAX_MACRO_STRING) 169 return 0; 170 171 strcpy(buf, define);That is a buffer overflow.
modules/parse_hesiod.c:
84 static int parse_nfs(structautofs_point*ap,
...108 for (i = 0; (!isspace(p[i]) && i < (int) sizeof(mount)); i++) { 109 mount[i] = p[i]; 110 } 111 112 mount[i] = 0; 113 p += i;That is a buffer overflow. There are six more loops with similar problems.
daemon/indirect.c:
86 static int do_mount_autofs_indirect(structautofs_point*ap,
const char *root)
...160 free(options); 161 162 ret = stat(root, &st); 163 if (ret == -1) { 164 crit(ap->logopt, 165 "failed to stat mount for autofs path % s", ap->path); 166 goto out_umount; 167 } ... 185 out_umount: 186 umount(root); 187 out_rmdir: 188 if (ap->flags & MOUNT_FLAG_DIR_CREATED) 189 rmdir(root); 190 out_err: 191 if (options) 192 free(options);That is a double free(3) call.
lib/cache.c:
180 structmapent_cache*cache_init(structautofs_point*ap,
structmap_source*map)
...195 mc->hash = malloc(mc->size * sizeof(struct entry *));...
231 structmapent_cache*cache_init_null_cache(struct master
*master)
...246 mc->hash = malloc(mc->size * sizeof(struct entry *));`struct mapent *' might be more correct. ;)
daemon/direct.c:
1045 int handle_packet_expire_direct(struct autofs_point *ap,autofs_packet_expire_direct_t *pkt)
...
1087 crit(ap->logopt, "can't find map entry for
(%lu,%lu)",
1088 (unsigned long) pkt->dev, (unsigned long)pkt->ino);
1089 master_source_unlock(ap->entry); 1090 master_mutex_unlock(); 1091 pthread_setcancelstate(state, NULL); 1092 return 1;
...
1099 if (ioctlfd == -1) {
1100 crit(ap->logopt, "can't open ioctlfd for
%s",
1101 me->key);
1102 pthread_setcancelstate(state, NULL);
1103 return 1;
1104 }
mc->rwlock' and ap->entry->source_lock' are still held at line 1103.
Also, is line 1090 unlocking the right thing?
modules/lookup_multi.c:
137 int lookup_init(const char *my_mapfmt, int argc, const char *const
*argv, void **context)
...
162 if (!(ctxt->m = malloc(ctxt->n * sizeof(struct
module_info))) ||
163 !(ctxt->argl = malloc((argc + 1) * sizeof(const char
*))))
164 goto nomem;
...
210 nomem:
211 estr = strerror_r(errno, buf, MAX_ERR_BUF);
212 logerr(MODPREFIX "error: %s", estr);
213 error_out:
214 if (ctxt) {
215 for (i = 0; i < ctxt->n; i++) {
216 if (ctxt->m[i].mod)
217 close_lookup(ctxt->m[i].mod);
218 if (ctxt->m[i].argv)
219 free_argv(ctxt->m[i].argc,
ctxt->m[i].argv);
220 }`ctxt->m' is unchecked within the loop.
modules/lookup_program.c:
106 int lookup_mount(struct autofs_point *ap, const char *name, intname_len, void *context)
...
199 mapent = (char *) malloc(MAPENT_MAX_LEN + 1);
...
395 cache_writelock(mc);
396 ret = cache_update(mc, source, name, mapent, time(NULL));
397 cache_unlock(mc);
398 if (ret == CHE_FAIL)
399 return NSS_STATUS_UNAVAIL;That is a memory leak.
modules/mount_nfs.c:
57 int mount_mount(struct autofs_point *ap, const char *root, const
char *name, int name_len,
...
223 loc = malloc(strlen(this->name) + 1 +
strlen(this->path) + 1);
224 strcpy(loc, this->name);
225 strcat(loc, ":");
226 strcat(loc, this->path);That is an unchecked malloc(3) call.
lib/mounts.c:
206 struct mnt_list *get_mnt_list(const char *table, const char *path,
int include)
...
265 ent->path = malloc(len + 1);
266 if (!ent->path) {
267 endmntent(tab);
268 free_mnt_list(list);
269 return NULL;
270 }
271 strcpy(ent->path, mnt->mnt_dir);
272
273 ent->fs_name = malloc(strlen(mnt->mnt_fsname) + 1);
274 if (!ent->fs_name) {
275 endmntent(tab);
276 free_mnt_list(list);
277 return NULL;
278 }
279 strcpy(ent->fs_name, mnt->mnt_fsname);
280
281 ent->fs_type = malloc(strlen(mnt->mnt_type) + 1);
282 if (!ent->fs_type) {
283 endmntent(tab);
284 free_mnt_list(list);
285 return NULL;
286 }
287 strcpy(ent->fs_type, mnt->mnt_type);
288
289 ent->opts = malloc(strlen(mnt->mnt_opts) + 1);
290 if (!ent->opts) {
291 endmntent(tab);
292 free_mnt_list(list);
293 return NULL;
294 }
295 strcpy(ent->opts, mnt->mnt_opts);...
659 struct mnt_list *tree_make_mnt_tree(const char *table, const char
*path)
...
705 ent->path = malloc(len + 1);
706 if (!ent->path) {
707 endmntent(tab);
708 tree_free_mnt_tree(tree);
709 return NULL;
710 }
711 strcpy(ent->path, mnt->mnt_dir);Those are memory leaks. (`ent' isn't cleaned up and/or freed.)
Also, strdup(3) is useful. :P
modules/parse_sun.c:
840 static int parse_mapent(const char *ent, char *g_options, char
**options, char **location, int logopt)
...
895 if (*p == '/') {
896 warn(logopt, MODPREFIX "error location begins with
\"/\"");
897 free(myoptions);
898 return 0;
899 }...
1316 int parse_mount(struct autofs_point *ap, const char *name,
...
1637 if (*p == '/') {
1638 free(options);
1639 warn(ap->logopt,
1640 MODPREFIX "error location begins with
\"/\"");
1641 return 1;
1642 }
Those are memory leaks. (`loc' isn't freed.)
modules/parse_sun.c:
266 int parse_init(int argc, const char *const *argv, void **context)
...
387 } else {
388 noptstr = (char *) malloc(len + 1);
389 strcpy(noptstr, argv[i] + offset);
390 optlen = len;
391 }That is an unchecked malloc(3) call.
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
Ian Kent
maintainerOn Fri, 2009-01-23 at 13:00 +1100, Paul Wankadia wrote:
Where getting quite a list of goodies for this.
Quoted 21 lines
daemon/direct.c:
1045 int handle_packet_expire_direct(structautofs_point*ap,autofs_packet_expire_direct_t*pkt)
...
1087 crit(ap->logopt, "can't find map entry for (%
lu,%lu)",
1088 (unsigned long)pkt->dev, (unsigned long)pkt->ino); 1089 master_source_unlock(ap->entry); 1090 master_mutex_unlock(); 1091 pthread_setcancelstate(state, NULL); 1092 return 1; ... 1099 if (ioctlfd == -1) { 1100 crit(ap->logopt, "can't open ioctlfd for %s", 1101 me->key); 1102 pthread_setcancelstate(state, NULL); 1103 return 1; 1104 }
Quoted 1 line
mc->rwlock' andap->entry->source_lock' are still held at line 1103.
Mmmm ... thought I fixed this but clearly not.
Quoted 2 lines
Also, is line 1090 unlocking the right thing?
No it's not, the master map mutex is not aquired here (although it was at one time but that may not have made it to a release).
snip ...
Quoted 5 lines
lib/mounts.c:
206 structmnt_list*get_mnt_list(const char *table, const char
*path, int include)
...
at this point either list == ent or ent is linked into list.
Quoted 33 lines
265 ent->path = malloc(len + 1);
266 if (!ent->path) {
267 endmntent(tab);
268 free_mnt_list(list);
269 return NULL;
270 }
271 strcpy(ent->path, mnt->mnt_dir);
272
273 ent->fs_name = malloc(strlen(mnt->mnt_fsname)
+ 1);
274 if (!ent->fs_name) {
275 endmntent(tab);
276 free_mnt_list(list);
277 return NULL;
278 }
279 strcpy(ent->fs_name, mnt->mnt_fsname);
280
281 ent->fs_type = malloc(strlen(mnt->mnt_type) +
1);
282 if (!ent->fs_type) {
283 endmntent(tab);
284 free_mnt_list(list);
285 return NULL;
286 }
287 strcpy(ent->fs_type, mnt->mnt_type);
288
289 ent->opts = malloc(strlen(mnt->mnt_opts) + 1);
290 if (!ent->opts) {
291 endmntent(tab);
292 free_mnt_list(list);
293 return NULL;
294 }
295 strcpy(ent->opts, mnt->mnt_opts);Quoted 1 line
...
So in all these cases it looks to me like free_mnt_list() handles the dealloc.
Quoted 11 lines
659 struct
mnt_list*tree_make_mnt_tree(const char *table, const
char *path)
...705 ent->path = malloc(len + 1); 706 if (!ent->path) { 707 endmntent(tab); 708 tree_free_mnt_tree(tree); 709 return NULL; 710 } 711 strcpy(ent->path, mnt->mnt_dir);
Quoted 1 line
Those are memory leaks. (`ent' isn't cleaned up and/or freed.)
But this is a mistake.
Quoted 2 lines
Also, strdup(3) is useful. :P
Sure, but not this time around, ;)
Ian
On Fri, Jan 23, 2009 at 3:08 PM, Ian Kent <[email protected]> wrote:
at this point either list == ent or ent is linked into list.
...
Quoted 2 lines
So in all these cases it looks to me like
free_mnt_list()handles the dealloc.
Oh, I see. Thanks.
Quoted 3 lines
Also, strdup(3) is useful. :P
Sure, but not this time around, ;)
Hmm?
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
Ian Kent
maintainerQuoted 12 lines · Paul Wankadia
On Fri, Jan 23, 2009 at 3:08 PM, Ian Kent <[email protected]> wrote:
at this point either list == ent or ent is linked into list....
So in all these cases it looks to me like
free_mnt_list()handles the
dealloc.Oh, I see. Thanks.
Quoted 6 lines
> Also, strdup(3) is useful. :P
Sure, but not this time around, ;)
Hmm?
Well maybe, ;)
Ian Kent
maintainerQuoted 25 lines · Paul Wankadia
On Thu, Jan 22, 2009 at 1:06 PM, Ian Kent <[email protected]> wrote:
> A daemon shouldn't run out of memory. Generally speaking, it's an
> exceptional condition that justifies abnormal termination.Don't think it being a daemon makes any difference?
I'm not entirely sure how this works but I thought that modified pages
are written to swap. If swap fills up I think alocs can fail even though
heap is available. If that is then fixed by external intervention the
alocs could then succeed. So, maybe termination isn't the right chioce
here. In any case it should be evident from the log that the situation
exists and the admin can decide what action to take. OTOH if heap is
really exhausted then termination probably is the right choice.
Quoted 7 lines
In any case I prefer to try and continue.
Sorry, I just don't understand why that's the right thing to do. If a daemon can't allocate memory in order to perform the operations that it needs to perform, then how can it provide the functionality that it's expected to provide? Why should it continue indefinitely instead of aborting and being restarted automatically?
Yeah, your entitled to your option but this has been discussed in the past and some people say just the opposite. I'm going to leave things the way they are for now.
Ian
Quoted 9 lines · Ian Kent
Sorry, I just don't understand why that's the right thing to do. If a
Quoted 4 lines
daemon can't allocate memory in order to perform the operations that it needs to perform, then how can it provide the functionality that it's expected to provide? Why should it continue indefinitely instead of aborting and being restarted automatically?
Yeah, your entitled to your option but this has been discussed in the past and some people say just the opposite. I'm going to leave things the way they are for now.
I wanted to understand your position...
Oh, and I've just noticed that there's a `fatal' macro that calls abort(3). It seems to be used widely, but solely for unexpected Pthreads errors?
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
Ian Kent
maintainerQuoted 20 lines · Paul Wankadia
On Thu, Jan 22, 2009 at 5:00 PM, Ian Kent <[email protected]> wrote:
> Sorry, I just don't understand why that's the right thing to do. If a
> daemon can't allocate memory in order to perform the operations that
> it needs to perform, then how can it provide the functionality that
> it's expected to provide? Why should it continue indefinitely instead
> of aborting and being restarted automatically?Yeah, your entitled to your option but this has been discussed in the
past and some people say just the opposite. I'm going to leave things
the way they are for now.
Quoted 5 lines
I wanted to understand your position...
Oh, and I've just noticed that there's a `fatal' macro that calls abort(3). It seems to be used widely, but solely for unexpected Pthreads errors?
So, now it looks like I'm contradicting myself, well called, ;)
The fatal() function was added much later than the times we got complains about autofs exiting upon errors, which lead to the common approach of continue if at all possible. The call is used almost exclusively for checking pthreads call returns that should "never" fail. The idea is that, rather than not bother checking them, abort so we can see where the fail occurred and get a backtrace from the core.
Ian
Quoted 6 lines · Ian Kent
I wanted to understand your position...
Quoted 4 lines
Oh, and I've just noticed that there's a `fatal' macro that calls abort(3). It seems to be used widely, but solely for unexpected Pthreads errors?
Quoted 8 lines
So, now it looks like I'm contradicting myself, well called, ;)
The
fatal()function was added much later than the times we got complains about autofs exiting upon errors, which lead to the common approach of continue if at all possible. The call is used almost exclusively for checking pthreads call returns that should "never" fail. The idea is that, rather than not bother checking them, abort so we can see where the fail occurred and get a backtrace from the core.
Does dmalloc provide similar functionality in the event of memory exhaustion?
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
Ian Kent
maintainerQuoted 25 lines · Paul Wankadia
On Thu, Jan 22, 2009 at 8:39 PM, Ian Kent <[email protected]> wrote:
> I wanted to understand your position...
>
> Oh, and I've just noticed that there's a `fatal' macro that calls
> abort(3). It seems to be used widely, but solely for unexpected
> Pthreads errors?So, now it looks like I'm contradicting myself, well called, ;)
The
fatal()function was added much later than the times we got
complains about autofs exiting upon errors, which lead to the common
approach of continue if at all possible. The call is used almost
exclusively for checking pthreads call returns that should "never" fail.
The idea is that, rather than not bother checking them, abort so we can
see where the fail occurred and get a backtrace from the core.
Quoted 2 lines
Does dmalloc provide similar functionality in the event of memory exhaustion?
No.
Dmalloc is more like valgrind but is linked in as a library. I found Dmalloc much better in pointing to trouble spots than valgrind. Unfortunately, I have not been able to get it to work for some time now and I never got the 64 bit library to function.
Ian
modules/replicated.c:
303 static int add_host(struct host **list, struct host *host)
...
307 if (!list) {
308 *list = host;
309 return 1;
310 }That is a NULL pointer dereference.
lib/alarm.c:
223 int alarm_start_handler(void)
...
230 status = pthread_attr_init(pattrs);
...
240 status = pthread_create(&thid, pattrs, alarm_handler, NULL);
241 if (status)
242 return 0;
243
244 return 1;Should you call pthread_attr_destroy(3) before returning?
lib/defaults.c:
544 struct ldap_searchdn *defaults_get_searchdns(void)
...
566 if (!new) {
567 defaults_free_searchdns(sdn);
568 return NULL;
569 }That is a resource leak. (`f' is not closed.)
modules/mount_changer.c:
142 int swapCD(const char *device, const char *slotName)
...
161 if (total_slots_available <= 1) {
162 logerr(MODPREFIX
163 "Device %s is not an ATAPI compliant CD
changer.",
164 device);
165 return 1;
166 }
...
170 if (slot < 0) {
171 logerr(MODPREFIX "CDROM_SELECT_DISC failed");
172 return 1;
173 }Those are resource leaks. (`fd' is not closed.)
daemon/state.c:
1124 int st_start_handler(void)
...
1131 status = pthread_attr_init(pattrs);
...
1141 status = pthread_create(&thid, pattrs, st_queue_handler,
NULL);
1142 if (status)
1143 return 0;
1144
1145 return 1;
Should you call pthread_attr_destroy(3) before returning?
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
Ian Kent
maintainerQuoted 9 lines · Paul Wankadia
modules/replicated.c:
303 static intadd_host(struct host **list, struct host *host)
...307 if (!list) { 308 *list = host; 309 return 1; 310 }That is a NULL pointer dereference.
Oops!
Quoted 14 lines
lib/alarm.c:
223 intalarm_start_handler(void)
...230 status = pthread_attr_init(pattrs); ... 240 status = pthread_create(&thid, pattrs, alarm_handler, NULL); 241 if (status) 242 return 0; 243 244 return 1;
Quoted 1 line
Should you call
pthread_attr_destroy(3)before returning?
Yes, missed that as it used to use a global attributes.
Quoted 29 lines
lib/defaults.c:
544 structldap_searchdn*defaults_get_searchdns(void)
...566 if (!new) { 567 defaults_free_searchdns(sdn); 568 return NULL; 569 }That is a resource leak. (`f' is not closed.)
modules/mount_changer.c:
142 intswapCD(const char *device, const char *slotName)
...
161 if (total_slots_available<= 1) {
162 logerr(MODPREFIX
163 "Device %s is not an ATAPI compliant CD
changer.",164 device); 165 return 1; 166 } ... 170 if (slot < 0) { 171 logerr(MODPREFIX "CDROM_SELECT_DISC failed"); 172 return 1; 173 }
Quoted 1 line
Those are resource leaks. (`fd' is not closed.)
Great, obvious catches.
Quoted 8 lines
daemon/state.c:1124 int st_start_handler(void)...
1131 status =pthread_attr_init(pattrs);
...
1141 status = pthread_create(&thid, pattrs,
Quoted 7 lines
st_queue_handler, NULL); 1142 if (status) 1143 return 0; 1144 1145 return 1;Should you call
pthread_attr_destroy(3)before returning?
Yes, also missed that as it used to use a global attributes.
Ian
Quoted 9 lines · Ian Kent
Does dmalloc provide similar functionality in the event of memory
Quoted 1 line
exhaustion?
No.
Dmalloc is more like valgrind but is linked in as a library. I found Dmalloc much better in pointing to trouble spots than valgrind. Unfortunately, I have not been able to get it to work for some time now and I never got the 64 bit library to function.
What problem(s) were you having?
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
Ian Kent
maintainerQuoted 10 lines · Paul Wankadia
On Fri, Jan 23, 2009 at 8:05 PM, Ian Kent <[email protected]> wrote:
> Does dmalloc provide similar functionality in the event of memory
> exhaustion?No.
Quoted 8 lines
Dmalloc is more like valgrind but is linked in as a library. I found Dmalloc much better in pointing to trouble spots than valgrind.
Unfortunately, I have not been able to get it to work for some time now
and I never got the 64 bit library to function.What problem(s) were you having?
This was added during the development of version 5 when I did memory management (leak) checking. The idea was that as time passed and changes were made I could simply enable DMALLOC and run checks from time to time but it didn't work out. The code analysis seems quite good at detecting those mistakes that seem to be inevitable or mistakes in code that hasn't been looked since taking over maintenance of a product.
Ian
Quoted 8 lines · Ian Kent
What problem(s) were you having?
This was added during the development of version 5 when I did memory management (leak) checking. The idea was that as time passed and changes were made I could simply enable DMALLOC and run checks from time to time but it didn't work out. The code analysis seems quite good at detecting those mistakes that seem to be inevitable or mistakes in code that hasn't been looked since taking over maintenance of a product.
What problem(s) were you having with dmalloc?
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
Ian Kent
maintainerQuoted 18 lines · Paul Wankadia
On Sun, Jan 25, 2009 at 2:23 PM, Ian Kent <[email protected]> wrote:
> What problem(s) were you having?
This was added during the development of version 5 when I did memory
management (leak) checking. The idea was that as time passed and changes
were made I could simply enable DMALLOC and run checks from time to time
but it didn't work out. The code analysis seems quite good at detecting
those mistakes that seem to be inevitable or mistakes in code that
hasn't been looked since taking over maintenance of a product.
Quoted 1 line
What problem(s) were you having with dmalloc?
Can't remember now but I think, compilation problems, link problems and then not being able to find the shared libraries mostly. Mostly it I just ended up spending too much time on it. I probably should spend some time on it again.
Ian
Quoted 6 lines · Ian Kent
What problem(s) were you having with dmalloc?
Can't remember now but I think, compilation problems, link problems and then not being able to find the shared libraries mostly. Mostly it I just ended up spending too much time on it. I probably should spend some time on it again.
Aren't there any Red Hat packages for dmalloc? I just installed the Ubuntu packages and then rebuilt autofs without any trouble.
BTW, perhaps you could check dmalloc's log file as part of the automated testing?
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
Ian Kent
maintainerQuoted 14 lines · Paul Wankadia
On Sun, Jan 25, 2009 at 7:36 PM, Ian Kent <[email protected]> wrote:
> What problem(s) were you having with dmalloc?
Can't remember now but I think, compilation problems, link problems and
then not being able to find the shared libraries mostly. Mostly it I
just ended up spending too much time on it. I probably should spend some
time on it again.
Quoted 2 lines
Aren't there any Red Hat packages for dmalloc? I just installed the Ubuntu packages and then rebuilt autofs without any trouble.
Nope.
I have a spec file I can use but the tarball from the download site still doesn't compile. I'll get back to that some time but not just now.
What version was installed?
Quoted 3 lines
BTW, perhaps you could check dmalloc's log file as part of the automated testing?
If I could easily build an rpm each time I updated Fedora then I would script something and run it regularly. Maybe looking at the patches applied by the deb would be useful.
Ian
Quoted 6 lines · Ian Kent
Aren't there any Red Hat packages for dmalloc? I just installed the
Quoted 1 line
Ubuntu packages and then rebuilt autofs without any trouble.
Nope.
I have a spec file I can use but the tarball from the download site still doesn't compile. I'll get back to that some time but not just now.
I suspect that Red Hat packages could be useful for a lot of users. If you don't have time to maintain them, then perhaps one of your colleagues does?
What version was installed?
Dapper and Feisty have version 5.4.2.
Gutsy, Hardy, Intrepid and Jaunty have version 5.5.1.
Quoted 6 lines
BTW, perhaps you could check dmalloc's log file as part of the
Quoted 1 line
automated testing?
If I could easily build an rpm each time I updated Fedora then I would script something and run it regularly. Maybe looking at the patches applied by the deb would be useful.
FWIW, SourceForge seems to offer i386 and src .rpm downloads for version 5.4.2.
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
Ian Kent
maintainerQuoted 13 lines · Paul Wankadia
On Mon, Jan 26, 2009 at 12:54 PM, Ian Kent <[email protected]> wrote:
> Aren't there any Red Hat packages for dmalloc? I just installed the
> Ubuntu packages and then rebuilt autofs without any trouble.Nope.
I have a spec file I can use but the tarball from the download site
still doesn't compile. I'll get back to that some time but not just now.
Quoted 3 lines
I suspect that Red Hat packages could be useful for a lot of users. If you don't have time to maintain them, then perhaps one of your colleagues does?
Maintaining an rpm isn't so bad but I don't have a good enough understanding of the package internals to make it work so I'm not likely to be useful at fixing bugs, case in point below. The other issue is that the upstream support is pretty much non-existent so the former is actually a big issue as far as adding a new package to Fedora goes.
Quoted 6 lines
What version was installed?
Dapper and Feisty have version 5.4.2.
Gutsy, Hardy, Intrepid and Jaunty have version 5.5.1.
I've tried 5.4.2 and 5.5.2.
I think that 4.8.1 worked at some stage but I haven't gone their again.
I spent a couple of hours on it again after sending my last mail and ended up in exactly the same spot I did last time.
[root@zeus ~]# /etc/init.d/autofs start
Starting automount: automount: symbol lookup error: /usr/lib/libdmallocth.so: undefined symbol: __stack_chk_fail_local
There's clearly something wrong with the linking but after stuffing around with the make file to even get this far I tend to run out of steam at this stage.
Quoted 7 lines
> BTW, perhaps you could check dmalloc's log file as part of the
> automated testing?
Quoted 8 lines
If I could easily build an rpm each time I updated Fedora then I would
script something and run it regularly. Maybe looking at the patches
applied by the deb would be useful.FWIW, SourceForge seems to offer i386 and src .rpm downloads for version 5.4.2.
I checked a few src rpms.
I haven't checked any debs yet but I'll do that before giving completely, again.
Ian