Skip to content

Commit d7f1aff

Browse files
dmantipovsmfrench
authored andcommitted
cifs: avoid extra calls to strlen() in cifs_get_spnego_key()
Since 'snprintf()' returns the number of characters emitted, an output position may be advanced with this return value rather than using an explicit calls to 'strlen()'. Compile tested only. Signed-off-by: Dmitry Antipov <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent b63335f commit d7f1aff

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

fs/smb/client/cifs_spnego.c

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -124,55 +124,44 @@ cifs_get_spnego_key(struct cifs_ses *sesInfo,
124124
dp = description;
125125
/* start with version and hostname portion of UNC string */
126126
spnego_key = ERR_PTR(-EINVAL);
127-
sprintf(dp, "ver=0x%x;host=%s;", CIFS_SPNEGO_UPCALL_VERSION,
128-
hostname);
129-
dp = description + strlen(description);
127+
dp += sprintf(dp, "ver=0x%x;host=%s;", CIFS_SPNEGO_UPCALL_VERSION,
128+
hostname);
130129

131130
/* add the server address */
132131
if (server->dstaddr.ss_family == AF_INET)
133-
sprintf(dp, "ip4=%pI4", &sa->sin_addr);
132+
dp += sprintf(dp, "ip4=%pI4", &sa->sin_addr);
134133
else if (server->dstaddr.ss_family == AF_INET6)
135-
sprintf(dp, "ip6=%pI6", &sa6->sin6_addr);
134+
dp += sprintf(dp, "ip6=%pI6", &sa6->sin6_addr);
136135
else
137136
goto out;
138137

139-
dp = description + strlen(description);
140-
141138
/* for now, only sec=krb5 and sec=mskrb5 and iakerb are valid */
142139
if (server->sec_kerberos)
143-
sprintf(dp, ";sec=krb5");
140+
dp += sprintf(dp, ";sec=krb5");
144141
else if (server->sec_mskerberos)
145-
sprintf(dp, ";sec=mskrb5");
142+
dp += sprintf(dp, ";sec=mskrb5");
146143
else if (server->sec_iakerb)
147-
sprintf(dp, ";sec=iakerb");
144+
dp += sprintf(dp, ";sec=iakerb");
148145
else {
149146
cifs_dbg(VFS, "unknown or missing server auth type, use krb5\n");
150-
sprintf(dp, ";sec=krb5");
147+
dp += sprintf(dp, ";sec=krb5");
151148
}
152149

153-
dp = description + strlen(description);
154-
sprintf(dp, ";uid=0x%x",
155-
from_kuid_munged(&init_user_ns, sesInfo->linux_uid));
150+
dp += sprintf(dp, ";uid=0x%x",
151+
from_kuid_munged(&init_user_ns, sesInfo->linux_uid));
156152

157-
dp = description + strlen(description);
158-
sprintf(dp, ";creduid=0x%x",
153+
dp += sprintf(dp, ";creduid=0x%x",
159154
from_kuid_munged(&init_user_ns, sesInfo->cred_uid));
160155

161-
if (sesInfo->user_name) {
162-
dp = description + strlen(description);
163-
sprintf(dp, ";user=%s", sesInfo->user_name);
164-
}
156+
if (sesInfo->user_name)
157+
dp += sprintf(dp, ";user=%s", sesInfo->user_name);
165158

166-
dp = description + strlen(description);
167-
sprintf(dp, ";pid=0x%x", current->pid);
159+
dp += sprintf(dp, ";pid=0x%x", current->pid);
168160

169-
if (sesInfo->upcall_target == UPTARGET_MOUNT) {
170-
dp = description + strlen(description);
171-
sprintf(dp, ";upcall_target=mount");
172-
} else {
173-
dp = description + strlen(description);
174-
sprintf(dp, ";upcall_target=app");
175-
}
161+
if (sesInfo->upcall_target == UPTARGET_MOUNT)
162+
dp += sprintf(dp, ";upcall_target=mount");
163+
else
164+
dp += sprintf(dp, ";upcall_target=app");
176165

177166
cifs_dbg(FYI, "key description = %s\n", description);
178167
saved_cred = override_creds(spnego_cred);

0 commit comments

Comments
 (0)