@@ -72,6 +72,11 @@ extern int sqfs_opt_proc(void* data, const char* arg, int key, struct fuse_args*
7272
7373const char * fusermountPath = NULL ;
7474
75+ // Constants for namespace and capability management
76+ #define DEFAULT_LAST_CAP 39
77+ #define UINT32_FULL_RANGE 4294967295U
78+ #define UID_GID_MAP_BUFFER_SIZE 64
79+
7580typedef struct {
7681 uint32_t lo ;
7782 uint32_t hi ;
@@ -435,10 +440,10 @@ void restore_capabilities(bool verbose) {
435440 }
436441
437442 FILE * f = fopen ("/proc/sys/kernel/cap_last_cap" , "r" );
438- uint32_t last_cap = 39 ; // default fallback
443+ uint32_t last_cap = DEFAULT_LAST_CAP ; // default fallback
439444 if (f != NULL ) {
440445 if (fscanf (f , "%u" , & last_cap ) != 1 ) {
441- last_cap = 39 ;
446+ last_cap = DEFAULT_LAST_CAP ;
442447 }
443448 fclose (f );
444449 }
@@ -486,8 +491,8 @@ bool is_in_user_and_mount_namespace(void) {
486491 // Parse the uid_map: "target_uid host_uid count"
487492 uint32_t target_uid , host_uid , count ;
488493 if (sscanf (line , "%u %u %u" , & target_uid , & host_uid , & count ) == 3 ) {
489- // If count is less than full range (4294967295) , we're in a user namespace
490- if (count < 4294967295 ) {
494+ // If count is less than full range, we're in a user namespace
495+ if (count < UINT32_FULL_RANGE ) {
491496 result = try_make_mount_private ();
492497 }
493498 }
@@ -528,7 +533,7 @@ bool try_unshare(uid_t uid, gid_t gid, const char* unshare_uid, const char* unsh
528533 }
529534
530535 // Write uid_map
531- char uid_map [64 ];
536+ char uid_map [UID_GID_MAP_BUFFER_SIZE ];
532537 snprintf (uid_map , sizeof (uid_map ), "%u %u 1" , target_uid , uid );
533538 f = fopen ("/proc/self/uid_map" , "w" );
534539 if (f == NULL ) {
@@ -543,7 +548,7 @@ bool try_unshare(uid_t uid, gid_t gid, const char* unshare_uid, const char* unsh
543548 fclose (f );
544549
545550 // Write gid_map
546- char gid_map [64 ];
551+ char gid_map [UID_GID_MAP_BUFFER_SIZE ];
547552 snprintf (gid_map , sizeof (gid_map ), "%u %u 1" , target_gid , gid );
548553 f = fopen ("/proc/self/gid_map" , "w" );
549554 if (f == NULL ) {
0 commit comments