Article View: cn.comp.security
Article #13Re: extern��ָ���ָ�����
From: nukq
Date: Thu, 20 Nov 2003 08:36
Date: Thu, 20 Nov 2003 08:36
174 lines
9063 bytes
9063 bytes
���岻ͬ�ˡ�*table[]��table�����飬��table������û�д洢�ռ�ģ���Ȼ���ʾ��
����ַ��talbe[0] table[1] ..�Ÿ�����4byte�Ŀռ䡣
����Ҫ����
o.c�����Ϊ
void *__table[]={"0","1","2","3",NULL};
void **table=__table;
"Qing, Quan" <skipme@263.net> д���ʼ� news:bpfrjc$17uo$1@mail.cn99.com...
> > 804841e: a1 18 95 04 08 mov 0x8049518,%eax <-----��
> 0x8049518��ַ�е�ֵ�ŵ�eax��
> > 8048423: 83 c0 04 add $0x4,%eax <-----�ٰ�
��
> ��ֵ��4������Ȼ�����ǵı����г���
>
> > table 8049518
> > &table[1] 8048507 <-----������Ȼ����������Ҫ��
> > table[1] (null) <-----������dz�����
>
> 0x8049518+0x04=0x804951c����ʹ�ӡ������զ��ϵ�ϵ��أ�:(
> ��ô����û�д?��
>
> --
> ------
> Qing, Quan
> Center for Nanoscale Science and Technology
> Peking University
> Beijing, P.R. China
> http://www.chem.pku.edu.cn/nanochemistry
> "NewBlue" <NewBlue@yaako.com> д���ʼ� news:uad84zjij.fsf@yaako.com...
> > [tips] extern��ָ���ָ�����
> >
> > alert7 �����ڣ�2003-09-08 13:02
> >
> > extern��ָ���ָ�����
> >
> > by alert7
> >
> > gcc��һ��С����,�������Ѿ�֪�����ȽϷ�dz�����Dz�֪���Ŀ��ܻ����ƺü���
С
> ʱ��
> >
> > һֱ���������Ƕ���Ϊchar *argv[]��char **argv�ǵȼ۵ġ���������
> > Ҳһֱû�г��?���Խ��ҵ���Ϊchar *argv[]��char **argv�ǵȼ۵ģ�ԭ��
> > ��һ��������ͨ�õġ�
> > ���ǣ������һ��BUG������һ�죬���ƾ���֮�������Ƕ���ָ���ָ���
��
> > �ǵĻ�������ԭ�ͣ�Ӧ�ö����ָ�����顣���������ְѾ���д�ɱ��ģ���ʹ��
��
> ��
> > ��һЩ��·��
> >
> > ���µ��������ҳ�������ģ�table�������ָ�����飬��ʵ����ʵ��o.c������
��
> ��
> > ���ṩ�������û��Դ���룬����ܲݲݵİ�table����Ϊextern void ** ;
> >
> > [root@redhat73 root]# cat o.c
> > #include <stdio.h>
> > void * table[]={"0","1","2","3",NULL};
> >
> > int test(void )
> > {
> >
> > return 0;
> > }
> >
> > [root@redhat73 root]# cat t.c
> > #include <stdio.h>
> > int main(int argc, char *argv[])
> > {
> > extern void **table;
> > int t;
> >
> > printf("table %x\n",&table);
> > printf("&table[1] %x\n",&table[1]);
> > printf("table[1] %s\n",table[1]);
> >
> > return 0;
> > }
> > [root@redhat73 root]# gcc -c t.c
> > [root@redhat73 root]# gcc -o t t.o o.o
> > [root@redhat73 root]# ./t
> > table 8049518
> > &table[1] 8048507 <-----������Ȼ����������Ҫ��
> > table[1] (null) <-----������dz�����
> >
> > ���������»�����
> > 08048400 <main>:
> > 8048400: 55 push %ebp
> > 8048401: 89 e5 mov %esp,%ebp
> > 8048403: 83 ec 08 sub $0x8,%esp
> > 8048406: 83 ec 08 sub $0x8,%esp
> > 8048409: 68 18 95 04 08 push $0x8049518 <------table��
ַ
> > 804840e: 68 d8 84 04 08 push $0x80484d8
> > 8048413: e8 d8 fe ff ff call 80482f0 <_init+0x58>
> > 8048418: 83 c4 10 add $0x10,%esp
> > 804841b: 83 ec 08 sub $0x8,%esp
> > 804841e: a1 18 95 04 08 mov 0x8049518,%eax <-----��
> 0x8049518��ַ�е�ֵ�ŵ�eax��
> > 8048423: 83 c0 04 add $0x4,%eax <-----�ٰ�
��
> ��ֵ��4������Ȼ�����ǵı����г���
> > 8048426: 50 push %eax
> > 8048427: 68 e2 84 04 08 push $0x80484e2
> > 804842c: e8 bf fe ff ff call 80482f0 <_init+0x58>
> > 8048431: 83 c4 10 add $0x10,%esp
> > 8048434: 83 ec 08 sub $0x8,%esp
> > 8048437: a1 18 95 04 08 mov 0x8049518,%eax
> > 804843c: 83 c0 04 add $0x4,%eax
> > 804843f: ff 30 pushl (%eax)
> > 8048441: 68 f0 84 04 08 push $0x80484f0
> > 8048446: e8 a5 fe ff ff call 80482f0 <_init+0x58>
> > 804844b: 83 c4 10 add $0x10,%esp
> > 804844e: b8 00 00 00 00 mov $0x0,%eax
> > 8048453: c9 leave
> > 8048454: c3 ret
> >
> > �������°���ԭ�Ͷ����extern void *table[];
> > #include <stdio.h>
> > int main(int argc, char *argv[])
> > {
> > extern void *table[];
> > int t;
> >
> > printf("table %x\n",&table);
> > printf("&table[1] %x\n",&table[1]);
> > printf("table[1] %s\n",table[1]);
> >
> > return 0;
> > }
> > [root@redhat73 root]# gcc -c t.c
> > [root@redhat73 root]# gcc -o t t.o o.o
> > [root@redhat73 root]# ./t
> > table 8049508
> > &table[1] 804950c
> > table[1] 1
> > 08048400 <main>:
> > 8048400: 55 push %ebp
> > 8048401: 89 e5 mov %esp,%ebp
> > 8048403: 83 ec 08 sub $0x8,%esp
> > 8048406: 83 ec 08 sub $0x8,%esp
> > 8048409: 68 08 95 04 08 push $0x8049508
> > 804840e: 68 c8 84 04 08 push $0x80484c8
> > 8048413: e8 d8 fe ff ff call 80482f0 <_init+0x58>
> > 8048418: 83 c4 10 add $0x10,%esp
> > 804841b: 83 ec 08 sub $0x8,%esp
> > 804841e: 68 0c 95 04 08 push $0x804950c <--------����
��
> ����
> > 8048423: 68 d2 84 04 08 push $0x80484d2
> > 8048428: e8 c3 fe ff ff call 80482f0 <_init+0x58>
> > 804842d: 83 c4 10 add $0x10,%esp
> > 8048430: 83 ec 08 sub $0x8,%esp
> > 8048433: ff 35 0c 95 04 08 pushl 0x804950c
> > 8048439: 68 e0 84 04 08 push $0x80484e0
> > 804843e: e8 ad fe ff ff call 80482f0 <_init+0x58>
> > 8048443: 83 c4 10 add $0x10,%esp
> > 8048446: b8 00 00 00 00 mov $0x0,%eax
> > 804844b: c9 leave
> > 804844c: c3 ret
> >
> > ���ԣ����ǻ���Ҫ�ϸ��պ����ԭ�������塣
> >
> > ����һЩʵ�飬ָ���ָ���������extern����������Ҫע���ˣ�
> > ��ʱ��ָ���ָ�������ָ������Ͳ���ͨ���ˡ�
> > --
> > NewBlue
> > �Դ����뿪���Ժ���һֱ�ȴ��������
>
>
Technical Details
Message-ID:
<bphude$p0f$1@news.yaako.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.media.kyoto-u.ac.jp!news.cn99.com!news.yaako.com!not-for-mailReferences:
<uad84zjij.fsf@yaako.com> <bpfrjc$17uo$1@mail.cn99.com>Show Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB X-Google-Thread: 1009e6,a15f179b39aafe37 X-Google-Attributes: gid1009e6,public X-Google-Thread: 1098a9,a15f179b39aafe37 X-Google-Attributes: gid1098a9,public X-Google-Thread: 11047e,a15f179b39aafe37 X-Google-Attributes: gid11047e,public X-Google-Thread: 10b277,a15f179b39aafe37 X-Google-Attributes: gid10b277,public X-Google-Thread: 113009,a15f179b39aafe37 X-Google-Attributes: gid113009,public X-Google-Thread: f5fb9,a15f179b39aafe37 X-Google-Attributes: gidf5fb9,public X-Google-ArrivalTime: 2003-11-20 00:37:35 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.media.kyoto-u.ac.jp!news.cn99.com!news.yaako.com!not-for-mail From: "nukq" <simenking@sohu.com> Newsgroups: cn.comp.security,cn.comp.programm,cn.comp.lang.c,cn.comp.os.linux,cn.comp.os.freebsd,cn.comp.hacker Subject: Re: extern��ָ���ָ����� Date: Thu, 20 Nov 2003 16:36:13 +0800 Organization: Bentium Ltd. (CN99) Lines: 176 Message-ID: <bphude$p0f$1@news.yaako.com> References: <uad84zjij.fsf@yaako.com> <bpfrjc$17uo$1@mail.cn99.com> Reply-To: "nukq" <simenking@sohu.com> NNTP-Posting-Host: 218.72.8.119 X-Trace: news.yaako.com 1069317358 25615 218.72.8.119 (20 Nov 2003 08:35:58 GMT) X-Complaints-To: usenet@news.yaako.com NNTP-Posting-Date: Thu, 20 Nov 2003 08:35:58 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165