You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our current logic is unsafe, as the second call of basename() can
silently overwrite the previous result.
a_base = basename(a);
b_base = basename(b); // can overwrite a_base
This occurs because basename(3) is allowed to use a static buffer
for the return value (and it indeed does so on macOS).
These functions may return pointers to statically allocated
memory which may be overwritten by subsequent calls.
-- Man page of basename(3)
A true portable way to use basename() is to call strdup() twice.
a_copy = strdup(a);
a_base = strdup(basename(a_copy));
This commit fixes it thusly.
Signed-off-by: Fujimoto Seiji <[email protected]>
0 commit comments