On Mon, Sep 03, 2018 at 01:53:41PM +0200, Denis Buga wrote:
> int main()
> {
> char * ptr = NULL;
> switch( *ptr )
> {
> default:
> fprintf(stderr,
>
> "where is exception ? default label exist for"
> "exclusive value, not for non-existent ! "
>
> "it can be security issue, when dereferencing NULL "
> "in switch formally pass and we go to default label\n");
> } }
>
> No ?
>
> 6.3 GENERIC.MP#8 amd64

As far as I know, since there is no explicit cases in the switch
statement, the value is not used at all, and the compiler never
generates code to dereference the pointer.

Had your code looked like

#include <stdio.h>
#include <stdlib.h>

int main() {
    char *ptr = NULL;

    switch (*ptr) {
        case 'a':
        default:
            fprintf(stderr,
                    "where is exception ? default label exist for"
                    "exclusive value, not for non-existent ! "
                    "it can be security issue, when dereferencing NULL "
                    "in switch formally pass and we go to default label\n");
    }

    return 0;
}

... then the compiler would be forced to generate code to dereference
the pointer (to compare it to 'a'), and you will get your segmentation
fault.

--
Andreas Kusalananda Kähäri,
National Bioinformatics Infrastructure Sweden (NBIS),
Uppsala University, Sweden.








När du har kontakt med oss på Uppsala universitet med e-post så innebär det att 
vi behandlar dina personuppgifter. För att läsa mer om hur vi gör det kan du 
läsa här: http://www.uu.se/om-uu/dataskydd-personuppgifter/

E-mailing Uppsala University means that we will process your personal data. For 
more information on how this is performed, please read here: 
http://www.uu.se/om-uu/dataskydd-personuppgifter/

Reply via email to