Does struct qstr->name should be terminated ?
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.
Quoted 16 lines · Jerome de Vivie
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 infs/namei.cthat 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; }
Quoted 2 lines
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 <[email protected]>
Quoted 2 lines · Jan Hudec
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;
Signature · 6 lines
"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
Quoted 1 line
Quoted 1 line
I'd think that it's treated as a nomral string in quite a few places,
so
Quoted 5 lines
Quoted 1 line
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?
Quoted 4 lines · Bryan Henderson
Quoted 1 line
Quoted 1 line
I'd think that it's treated as a nomral string in quite a few places,
so
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
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.
Quoted 1 line
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).