* Does struct qstr->name should be terminated ?
@ 2004-03-23 10:56 Jerome de Vivie
2004-03-24 9:09 ` Jan Hudec
0 siblings, 1 reply; 5+ messages in thread
From: Jerome de Vivie @ 2004-03-23 10:56 UTC (permalink / raw)
To: linux-fsdevel
I've work with "struct qstr" for a while without bothering with the last
caracter: qstr->name[qstr->len]. I get oops from my module but after
investigation, i found lines in fs/namei.c that are using this caracter:
In do_rename:
/* unless the source is a directory trailing slashes give
-ENOTDIR */
if (!S_ISDIR(old_dentry->d_inode->i_mode)) {
error = -ENOTDIR;
if (oldnd.last.name[oldnd.last.len])
goto exit4;
if (newnd.last.name[newnd.last.len])
goto exit4;
}
So, do i need to initialize this caracter when allocating new qstr ? Is
this caracter is used in other place in the VFS ?
regards,
j.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: Does struct qstr->name should be terminated ?
2004-03-23 10:56 Does struct qstr->name should be terminated ? Jerome de Vivie
@ 2004-03-24 9:09 ` Jan Hudec
2004-03-24 13:05 ` Matthew Wilcox
0 siblings, 1 reply; 5+ messages in thread
From: Jan Hudec @ 2004-03-24 9:09 UTC (permalink / raw)
To: Jerome de Vivie; +Cc: linux-fsdevel
[-- Attachment #1: Type: text/plain, Size: 1091 bytes --]
On Tue, Mar 23, 2004 at 11:56:01 +0100, Jerome de Vivie wrote:
>
> I've work with "struct qstr" for a while without bothering with the last
> caracter: qstr->name[qstr->len]. I get oops from my module but after
> investigation, i found lines in fs/namei.c that are using this caracter:
>
> In do_rename:
> /* unless the source is a directory trailing slashes give
> -ENOTDIR */
> if (!S_ISDIR(old_dentry->d_inode->i_mode)) {
> error = -ENOTDIR;
> if (oldnd.last.name[oldnd.last.len])
> goto exit4;
> if (newnd.last.name[newnd.last.len])
> goto exit4;
> }
>
> So, do i need to initialize this caracter when allocating new qstr ? Is
> this caracter is used in other place in the VFS ?
I'd think that it's treated as a nomral string in quite a few places, so
it needs to be NUL terminated. (But not searched the sources.)
-------------------------------------------------------------------------------
Jan 'Bulb' Hudec <bulb@ucw.cz>
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: Does struct qstr->name should be terminated ?
2004-03-24 9:09 ` Jan Hudec
@ 2004-03-24 13:05 ` Matthew Wilcox
2004-03-24 17:09 ` Bryan Henderson
0 siblings, 1 reply; 5+ messages in thread
From: Matthew Wilcox @ 2004-03-24 13:05 UTC (permalink / raw)
To: Jan Hudec; +Cc: Jerome de Vivie, linux-fsdevel
On Wed, Mar 24, 2004 at 10:09:26AM +0100, Jan Hudec wrote:
> I'd think that it's treated as a nomral string in quite a few places, so
> it needs to be NUL terminated. (But not searched the sources.)
Why not? It isn't hard to find.
fs/dcache.c:703: str[name->len] = 0;
--
"Next the statesmen will invent cheap lies, putting the blame upon
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince
himself that the war is just, and will thank God for the better sleep
he enjoys after this process of grotesque self-deception." -- Mark Twain
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Does struct qstr->name should be terminated ?
2004-03-24 13:05 ` Matthew Wilcox
@ 2004-03-24 17:09 ` Bryan Henderson
2004-03-25 0:09 ` Jerome de Vivie
0 siblings, 1 reply; 5+ messages in thread
From: Bryan Henderson @ 2004-03-24 17:09 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: Jan Hudec, Jerome de Vivie, linux-fsdevel
>> I'd think that it's treated as a nomral string in quite a few places,
so
>> it needs to be NUL terminated. (But not searched the sources.)
>
>Why not? It isn't hard to find.
>
>fs/dcache.c:703: str[name->len] = 0;
That's technically an area where it's treated like a normal string, but
not really relevant to the question (which is "what if I don't
nul-terminate the thing"? Do you have an example handy of a strcmp() or
such that would fail if the NUL terminator were not there?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Does struct qstr->name should be terminated ?
2004-03-24 17:09 ` Bryan Henderson
@ 2004-03-25 0:09 ` Jerome de Vivie
0 siblings, 0 replies; 5+ messages in thread
From: Jerome de Vivie @ 2004-03-25 0:09 UTC (permalink / raw)
To: Bryan Henderson; +Cc: Matthew Wilcox, Jan Hudec, linux-fsdevel
Bryan Henderson wrote:
>>>I'd think that it's treated as a nomral string in quite a few places,
>
> so
>
>>>it needs to be NUL terminated. (But not searched the sources.)
>>
>>Why not? It isn't hard to find.
>>
>>fs/dcache.c:703: str[name->len] = 0;
>
>
> That's technically an area where it's treated like a normal string, but
I thougth that qstr->name was not treated as a normal string and has
been design to speedup d_compare test with strncmp instead of strcmp.
That's why i never bother with the null termination caracter.
> not really relevant to the question (which is "what if I don't
> nul-terminate the thing"? Do you have an example handy of a strcmp() or
> such that would fail if the NUL terminator were not there?
In yourfs->d_lookup, you can reallocate qstr and pad d_name with random
caracters. After that, unexpected behavior could happen after a mv(1):
the VFS could increment qstr->len. The result is one more caracter for
some entries after a ls(1).
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-03-25 0:04 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-23 10:56 Does struct qstr->name should be terminated ? Jerome de Vivie
2004-03-24 9:09 ` Jan Hudec
2004-03-24 13:05 ` Matthew Wilcox
2004-03-24 17:09 ` Bryan Henderson
2004-03-25 0:09 ` Jerome de Vivie
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.