Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F153945132
D24095.id69587.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D24095.id69587.diff
View Options
Index: lib/libc/nls/msgcat.c
===================================================================
--- lib/libc/nls/msgcat.c
+++ lib/libc/nls/msgcat.c
@@ -43,6 +43,7 @@
#include <sys/queue.h>
#include <arpa/inet.h> /* for ntohl() */
+#include <machine/atomic.h>
#include <errno.h>
#include <fcntl.h>
@@ -76,19 +77,25 @@
#define NLERR ((nl_catd) -1)
#define NLRETERR(errc) { errno = errc; return (NLERR); }
-#define SAVEFAIL(n, l, e) { WLOCK(NLERR); \
- np = malloc(sizeof(struct catentry)); \
+#define SAVEFAIL(n, l, e) { np = calloc(1, sizeof(struct catentry)); \
if (np != NULL) { \
np->name = strdup(n); \
- np->path = NULL; \
np->catd = NLERR; \
- np->refcount = 0; \
np->lang = (l == NULL) ? NULL : \
strdup(l); \
np->caterrno = e; \
- SLIST_INSERT_HEAD(&cache, np, list); \
+ if (np->name == NULL || \
+ (l != NULL && np->lang == NULL)) { \
+ free(np->name); \
+ free(np->lang); \
+ free(np); \
+ } else { \
+ WLOCK(NLERR); \
+ SLIST_INSERT_HEAD(&cache, np, \
+ list); \
+ UNLOCK; \
+ } \
} \
- UNLOCK; \
errno = e; \
}
@@ -152,7 +159,7 @@
NLRETERR(np->caterrno);
} else {
/* Found cached successful entry */
- np->refcount++;
+ atomic_add_int(&(np->refcount), 1);
UNLOCK;
return (np->catd);
}
@@ -355,8 +362,8 @@
WLOCK(-1);
SLIST_FOREACH(np, &cache, list) {
if (catd == np->catd) {
- np->refcount--;
- if (np->refcount == 0)
+ atomic_add_int(&(np->refcount), -1);
+ if (atomic_load_int(&(np->refcount)) == 0)
catfree(np);
break;
}
@@ -376,6 +383,7 @@
nl_catd catd;
struct catentry *np;
void *data;
+ char *copy_path, *copy_name, *copy_lang;
int fd;
/* path/name will never be NULL here */
@@ -387,7 +395,7 @@
RLOCK(NLERR);
SLIST_FOREACH(np, &cache, list) {
if ((np->path != NULL) && (strcmp(np->path, path) == 0)) {
- np->refcount++;
+ atomic_add_int(&(np->refcount), 1);
UNLOCK;
return (np->catd);
}
@@ -432,7 +440,20 @@
NLRETERR(EFTYPE);
}
- if ((catd = malloc(sizeof (*catd))) == NULL) {
+ copy_name = strdup(name);
+ copy_path = strdup(path);
+ copy_lang = (lang == NULL) ? NULL : strdup(lang);
+ catd = malloc(sizeof (*catd));
+ np = calloc(1, sizeof(struct catentry));
+
+ if (copy_name == NULL || copy_path == NULL ||
+ (lang != NULL && copy_lang == NULL) ||
+ catd == NULL || np == NULL) {
+ free(copy_name);
+ free(copy_path);
+ free(copy_lang);
+ free(catd);
+ free(np);
munmap(data, (size_t)st.st_size);
SAVEFAIL(name, lang, ENOMEM);
NLRETERR(ENOMEM);
@@ -442,16 +463,13 @@
catd->__size = (int)st.st_size;
/* Caching opened catalog */
+ np->name = copy_name;
+ np->path = copy_path;
+ np->catd = catd;
+ np->lang = copy_lang;
+ atomic_store_int(&(np->refcount), 1);
WLOCK(NLERR);
- if ((np = malloc(sizeof(struct catentry))) != NULL) {
- np->name = strdup(name);
- np->path = strdup(path);
- np->catd = catd;
- np->lang = (lang == NULL) ? NULL : strdup(lang);
- np->refcount = 1;
- np->caterrno = 0;
- SLIST_INSERT_HEAD(&cache, np, list);
- }
+ SLIST_INSERT_HEAD(&cache, np, list);
UNLOCK;
return (catd);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Apr 26, 12:17 AM (20 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
32149755
Default Alt Text
D24095.id69587.diff (3 KB)
Attached To
Mode
D24095: Fix race condition in catopen(3).
Attached
Detach File
Event Timeline
Log In to Comment