* [devel] Нужно ли вызывать endpwent() после использования getpwuid() ?
@ 2007-02-26 13:32 Slava Semushin
2007-02-26 13:44 ` Mikhail Gusarov
0 siblings, 1 reply; 5+ messages in thread
From: Slava Semushin @ 2007-02-26 13:32 UTC (permalink / raw)
To: ALT Devel discussion list
Здравствуйте!
Листал тут на работе книжку от O'Reilly "Secure Programming Book for C
and C++" и увидел такой пример:
%%
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <pwd.h>
int main(int argc, char *argv[]) {
uid_t uid;
struct passwd *pwd;
uid = getuid();
printf("User's UID is %d.\n", (int)uid);
if ( ! (pwd = getpwuid(uid))) {
printf("Unable to get user's password file record!\n");
endpwent();
return 1;
}
printf("User's home directory is %s\n", pwd->pw_dir);
endpwent();
return 0;
}
%%
Собственно, привлёк внимание факт вызова endpwent(). Почитал ман к
Линуксу, к Нетке, ещё каких-то в интернете и не очень понял,
действительно ли нужно после вызова getpwuid() вызывать endpwent().
Пожалуйста, разъясните этот момент, ведь если я правильно понял, то
невызов endpwent() чреват утечкой файлового дескриптора.
Заранее спасибо!
--
+ Slava Semushin | slava.semushin @ gmail.com
+ ALT Linux Team | php-coder @ altlinux.ru
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [devel] Нужно ли вызывать endpwent() после использования getpwuid() ?
2007-02-26 13:32 [devel] Нужно ли вызывать endpwent() после использования getpwuid() ? Slava Semushin
@ 2007-02-26 13:44 ` Mikhail Gusarov
2007-02-26 13:49 ` Damir Shayhutdinov
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Mikhail Gusarov @ 2007-02-26 13:44 UTC (permalink / raw)
To: ALT Devel discussion list
Twas brillig at 16:32:03 when Slava Semushin did gyre and gimble:
SS> Пожалуйста, разъясните этот момент, ведь если я правильно понял,
SS> то невызов endpwent() чреват утечкой файлового дескриптора.
Невызов endpwent() чреват тем, что если в промежутке между getpwuid()
и endpwent() злоумышленик получит каким-либо образом доступ к памяти
процесса, то он имеет шансы прочитать содержимое /etc/passwd.
ps: а как этот вопрос относится к devel@? Может, лучше в sisyphus@
спрашивать?
--
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [devel] Нужно ли вызывать endpwent() после использования getpwuid() ?
2007-02-26 13:44 ` Mikhail Gusarov
@ 2007-02-26 13:49 ` Damir Shayhutdinov
2007-02-26 13:52 ` [devel] [SUMMARY][OFF]Re: " Slava Semushin
2007-02-26 13:56 ` [devel] " Dmitry V. Levin
2 siblings, 0 replies; 5+ messages in thread
From: Damir Shayhutdinov @ 2007-02-26 13:49 UTC (permalink / raw)
To: ALT Devel discussion list
> SS> Пожалуйста, разъясните этот момент, ведь если я правильно понял,
> SS> то невызов endpwent() чреват утечкой файлового дескриптора.
>
> Невызов endpwent() чреват тем, что если в промежутке между getpwuid()
> и endpwent() злоумышленик получит каким-либо образом доступ к памяти
> процесса, то он имеет шансы прочитать содержимое /etc/passwd.
>
> ps: а как этот вопрос относится к devel@? Может, лучше в sisyphus@
> спрашивать?
ИМХО, в community@, ибо не вижу сизифной специфики.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [devel] [SUMMARY][OFF]Re: Нужно ли вызывать endpwent() после использования getpwuid() ?
2007-02-26 13:44 ` Mikhail Gusarov
2007-02-26 13:49 ` Damir Shayhutdinov
@ 2007-02-26 13:52 ` Slava Semushin
2007-02-26 13:56 ` [devel] " Dmitry V. Levin
2 siblings, 0 replies; 5+ messages in thread
From: Slava Semushin @ 2007-02-26 13:52 UTC (permalink / raw)
To: ALT Devel discussion list
2007/2/26, Mikhail Gusarov <dottedmag / dottedmag.net>:
> SS> Пожалуйста, разъясните этот момент, ведь если я правильно понял,
> SS> то невызов endpwent() чреват утечкой файлового дескриптора.
Пришел dfo@ и надоумил меня использовать strace, после чего я ясно
увидел, что утечки не происходит и волноваться не стОит :)
2dfo@: Thanks!
> ps: а как этот вопрос относится к devel@? Может, лучше в sisyphus@
> спрашивать?
Простите за offtopic.
--
+ Slava Semushin | slava.semushin @ gmail.com
+ ALT Linux Team | php-coder @ altlinux.ru
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [devel] Нужно ли вызывать endpwent() после использования getpwuid() ?
2007-02-26 13:44 ` Mikhail Gusarov
2007-02-26 13:49 ` Damir Shayhutdinov
2007-02-26 13:52 ` [devel] [SUMMARY][OFF]Re: " Slava Semushin
@ 2007-02-26 13:56 ` Dmitry V. Levin
2 siblings, 0 replies; 5+ messages in thread
From: Dmitry V. Levin @ 2007-02-26 13:56 UTC (permalink / raw)
To: ALT Devel discussion list
[-- Attachment #1: Type: text/plain, Size: 592 bytes --]
On Mon, Feb 26, 2007 at 07:44:27PM +0600, Mikhail Gusarov wrote:
> Twas brillig at 16:32:03 when Slava Semushin did gyre and gimble:
>
> SS> Пожалуйста, разъясните этот момент, ведь если я правильно понял,
> SS> то невызов endpwent() чреват утечкой файлового дескриптора.
>
> Невызов endpwent() чреват тем, что если в промежутке между getpwuid()
> и endpwent() злоумышленик получит каким-либо образом доступ к памяти
> процесса, то он имеет шансы прочитать содержимое /etc/passwd.
До вызова endpwent может оставаться незакрытый дескриптор и неочищенная
память.
--
ldv
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-02-26 13:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-26 13:32 [devel] Нужно ли вызывать endpwent() после использования getpwuid() ? Slava Semushin
2007-02-26 13:44 ` Mikhail Gusarov
2007-02-26 13:49 ` Damir Shayhutdinov
2007-02-26 13:52 ` [devel] [SUMMARY][OFF]Re: " Slava Semushin
2007-02-26 13:56 ` [devel] " Dmitry V. Levin
ALT Linux Team development discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
public-inbox-index devel
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.devel
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git