Skip to contentSkip to conversation

Taking strlen of buffers copied from userspace

DISCUSSION Robert Hancock 2 participants 2 messages Mar 16, 2005 3 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 9 lines · Randy.Dunlap

The latter one does (before the listed code):

    memset(line, 0, LINE_SIZE);
    if (len > LINE_SIZE)
        len = LINE_SIZE;
    if (copy_from_user(line, buf, len - 1))
        return -EFAULT;

so isn't line[LINE_SIZE - 1] always 0 ?

In that case, yes (I hadn't looked at the surrounding code). Rather an odd way of doing it, but shouldn't have that problem. Could still be subject to problems if buf contains a null at the first character, unless they're somehow preventing that too..

Signature · 3 lines
Robert Hancock      Saskatoon, SK, Canada
To email, remove "nospam" from [email protected]
Home Page: http://www.roberthancock.com/
#4 lore raw
Quoted 10 lines · Robert Hancock
Quoted 8 lines · Randy.Dunlap

The latter one does (before the listed code):

    memset(line, 0, LINE_SIZE);
    if (len > LINE_SIZE)
        len = LINE_SIZE;
    if (copy_from_user(line, buf, len - 1))
        return -EFAULT;
Quoted 4 lines
Quoted 1 line

so isn't line[LINE_SIZE - 1] always 0 ?

In that case, yes (I hadn't looked at the surrounding code). Rather an odd way of doing it, but shouldn't have that problem. Could still be subject to problems if buf contains a null at the first character, unless they're somehow preventing that too..

Yes, that's still a problem.

Signature · 1 line
~Randy