Skip to contentSkip to conversation

kill IN_STRING_C

PATCH Paweł Sikora 1 participant 1 message Nov 8, 2004

lore
Share & tools
lore
#0 lore raw
Quoted 58 lines · you
Quoted 17 lines · Pawe?? Sikora
Quoted 11 lines · you
Quoted 6 lines · Andi Kleen
Quoted 3 lines

Rethinking it, I don't even understand the sprintf example in your changelog entry - shouldn't an inclusion of kernel.h always get it right?

Newer gcc rewrites sprintf(buf,"%s",str) to strcpy(buf,str) transparently.

Which gcc is "Newer"?

My gcc 3.4.2 didn't show this problem.

#include <stdio.h>
#include <string.h>
char buf[128];
void test(char *str)

Quoted 6 lines
{
    sprintf(buf, "%s", str);
}

...
jmp strcpy
...

This is the userspace example.

The kernel example is:

#include <linux/string.h>
#include <linux/kernel.h>

char buf[128];
void test(char *str)
{
sprintf(buf, "%s", str);
}

This results with gcc-3.4 (GCC) 3.4.2 (Debian 3.4.2-3) in:

        .file   "test.c"
        .section        .rodata.str1.1,"aMS",@progbits,1
.LC0:
        .string "%s"
        .text
        .p2align 4,,15
.globl test
        .type   test, @function
test:
        pushl   %eax
        pushl   $.LC0
        pushl   $buf
        call    sprintf
        addl    $12, %esp

ret
.size test, .-test
.globl buf

Quoted 8 lines
        .bss
        .align 32
        .type   buf, @object
        .size   buf, 128
buf:
        .zero   128
        .section        .note.GNU-stack,"",@progbits
        .ident  "GCC: (GNU) 3.4.2 (Debian 3.4.2-3)"

[~/rpm/BUILD] # cat sp.c

#include <linux/string.h>
#include <linux/kernel.h>

char buf[128];
void test(char *str)

{
    sprintf(buf, "%s", str);
}

[~/rpm/BUILD] # gcc -Wall sp.c -S -O2 -fomit-frame-pointer -mregparm=3
-nostdinc -isystem /usr/src/linux/include

sp.c: In function `test':
sp.c:7: warning: implicit declaration of function `sprintf'

[~/rpm/BUILD] # cat sp.s

        .file   "sp.c"
        .text
        .p2align 4,,15
.globl test
        .type   test, @function
test:
        movl    %eax, %edx
        movl    $buf, %eax
        jmp     strcpy
        .size   test, .-test
        .comm   buf,128,32
        .section        .note.GNU-stack,"",@progbits
        .ident  "GCC: (GNU) 3.4.3 (PLD Linux)"

What now?

Signature · 3 lines
/* Copyright (C) 2003, SCO, Inc. This is valuable Intellectual Property. */

                           #define say(x) lie(x)