lists.arthurdejong.org
RSS feed

[PATCH] Use an explicit base of 10 for strtouid()/strtogid() calls

[Date Prev][Date Next] [Thread Prev][Thread Next]

[PATCH] Use an explicit base of 10 for strtouid()/strtogid() calls



This patch came up as a suggestion during Nalin's peer code review of my
earlier strto* patches.

If a broken LDAP server entry had the uidNumber so it looks like a number
from a different base then 10 to strto* functions, we would have converted
it in the respective base instead of 10. For instance "010" would have
been converted to "8".

I managed to break the configuration by putting "0100" into a custom
attribute and then mapping the uidNumber to it by using "map uidNumber
foobar". "getent passwd octaluid" then reported 512 for UID.
>From d9eeea76a2539ee297cb569d2dfc944eedb3acbc Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Tue, 27 Sep 2011 11:38:49 +0200
Subject: [PATCH] Use an explicit base of 10 for strtouid()/strtogid() calls

---
 nslcd/cfg.c    |    4 ++--
 nslcd/group.c  |    2 +-
 nslcd/passwd.c |    6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/nslcd/cfg.c b/nslcd/cfg.c
index 00dd8c4..e5c3b1a 100644
--- a/nslcd/cfg.c
+++ b/nslcd/cfg.c
@@ -431,7 +431,7 @@ static void get_uid(const char *filename,int lnr,
   
check_argumentcount(filename,lnr,keyword,get_token(line,token,sizeof(token))!=NULL);
   /* check if it is a valid numerical uid */
   errno=0;
-  *var=strtouid(token,&tmp,0);
+  *var=strtouid(token,&tmp,10);
   if ((*token!='\0')&&(*tmp=='\0')&&(errno==0))
     return;
   /* find by name */
@@ -457,7 +457,7 @@ static void get_gid(const char *filename,int lnr,
   
check_argumentcount(filename,lnr,keyword,get_token(line,token,sizeof(token))!=NULL);
   /* check if it is a valid numerical gid */
   errno=0;
-  *var=strtogid(token,&tmp,0);
+  *var=strtogid(token,&tmp,10);
   if ((*token!='\0')&&(*tmp=='\0')&&(errno==0))
     return;
   /* find by name */
diff --git a/nslcd/group.c b/nslcd/group.c
index 41d8f8f..4725295 100644
--- a/nslcd/group.c
+++ b/nslcd/group.c
@@ -281,7 +281,7 @@ static int write_group(TFILE *fp,MYLDAP_ENTRY *entry,const 
char *reqname,
       else
       {
         errno=0;
-        gids[numgids]=strtogid(gidvalues[numgids],&tmp,0);
+        gids[numgids]=strtogid(gidvalues[numgids],&tmp,10);
         if ((*(gidvalues[numgids])=='\0')||(*tmp!='\0'))
         {
           log_log(LOG_WARNING,"%s: %s: non-numeric",
diff --git a/nslcd/passwd.c b/nslcd/passwd.c
index ab097c6..9eba10c 100644
--- a/nslcd/passwd.c
+++ b/nslcd/passwd.c
@@ -195,7 +195,7 @@ static int entry_has_valid_uid(MYLDAP_ENTRY *entry)
     else
     {
       errno=0;
-      uid=strtouid(values[i],&tmp,0);
+      uid=strtouid(values[i],&tmp,10);
       if ((*(values[i])=='\0')||(*tmp!='\0'))
       {
         log_log(LOG_WARNING,"%s: %s: non-numeric",
@@ -492,7 +492,7 @@ static int write_passwd(TFILE *fp,MYLDAP_ENTRY *entry,const 
char *requser,
       else
       {
         errno=0;
-        uids[numuids]=strtouid(tmpvalues[numuids],&tmp,0);
+        uids[numuids]=strtouid(tmpvalues[numuids],&tmp,10);
         if ((*(tmpvalues[numuids])=='\0')||(*tmp!='\0'))
         {
           log_log(LOG_WARNING,"%s: %s: non-numeric",
@@ -530,7 +530,7 @@ static int write_passwd(TFILE *fp,MYLDAP_ENTRY *entry,const 
char *requser,
       return 0;
     }
     errno=0;
-    gid=strtogid(gidbuf,&tmp,0);
+    gid=strtogid(gidbuf,&tmp,10);
     if ((gidbuf[0]=='\0')||(*tmp!='\0'))
     {
       log_log(LOG_WARNING,"%s: %s: non-numeric",
-- 
1.7.6.2

-- 
To unsubscribe send an email to
nss-pam-ldapd-users-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/nss-pam-ldapd-users/