commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r806479 - /commons/sandbox/runtime/trunk/src/main/native/os/unix/psema.c
Date Fri, 21 Aug 2009 09:49:30 GMT
Author: mturk
Date: Fri Aug 21 09:49:29 2009
New Revision: 806479

URL: http://svn.apache.org/viewvc?rev=806479&view=rev
Log:
Do not allow dots in semaphore names as well

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/unix/psema.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/psema.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/psema.c?rev=806479&r1=806478&r2=806479&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/psema.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/psema.c Fri Aug 21 09:49:29 2009
@@ -55,7 +55,7 @@
 struct acr_semaphore_t {
     sem_t *sem;
     int    locked;
-    char   name[NAME_MAX];
+    char   name[NAME_MAX + 1];
 };
 
 static int semaphore_cleanup(void *sema, int type, unsigned int flags)
@@ -90,10 +90,10 @@
     else {
         if (*name != '/')
             s->name[0] = '/';
-        strlcat(s->name, name, NAME_MAX - 2);
+        strlcat(s->name, name, NAME_MAX);
     }
     for (p = &s->name[1]; *p; p++) {
-        if (*p == '/')
+        if (*p == '/' || *p == '.')
             *p = '_';
     }
     do {
@@ -150,9 +150,9 @@
         return -1;
     if (*name != '/')
         s->name[0] = '/';
-    strlcat(s->name, name, NAME_MAX - 2);
+    strlcat(s->name, name, NAME_MAX);
     for (p = &s->name[1]; *p; p++) {
-        if (*p == '/')
+        if (*p == '/' || *p == '.')
             *p = '_';
     }
 
@@ -185,14 +185,18 @@
 
 ACR_DECLARE(int) ACR_SemaphoreRemove(JNIEnv *_E, const acr_pchar_t *sname)
 {
-    char name[NAME_MAX] = "";
+    char *p;
+    char  name[NAME_MAX + 1] = "";
     if (!sname) {
         return ACR_EINVAL;
     }
     if (*sname != '/')
         name[0] = '/';
-    strlcat(name, sname, NAME_MAX -2);
-
+    strlcat(name, sname, NAME_MAX);
+    for (p = &name[1]; *p; p++) {
+        if (*p == '/' || *p == '.')
+            *p = '_';
+    }
     return sem_unlink(name);
 }
 



Mime
View raw message