this patch avoids a possible undefined behviour at the loop when it tries to
access the password field after the 6th position (password is a fixed size
string of 6 chars)
/home/netto/Desktop/osv/osv-tomcat9/tests/tst-crypt.c:44:29: warning: iteration
6 invokes undefined behavior [-Waggressive-loop-optimizations]
buf[i * 8 + j] = password[i] >> j & 1;
~~~~~~~~^~~
/home/netto/Desktop/osv/osv-tomcat9/tests/tst-crypt.c:42:2: note: within this
loop
for (i = 0; i < 8; i++) {
^~~
Signed-off-by: geraldo netto <[email protected]>
---
tests/tst-crypt.c | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/tests/tst-crypt.c b/tests/tst-crypt.c
index dc9a6341..25a81aba 100644
--- a/tests/tst-crypt.c
+++ b/tests/tst-crypt.c
@@ -39,36 +39,32 @@ int main(void) {
// http://man7.org/linux/man-pages/man3/encrypt.3.html
char key[64];
char buf[64];
- char txt[9];
+ char txt[7];
int i, j;
- for (i = 0; i < 8; i++) {
+ for (i = 0; i < 6; i++) {
for (j = 0; j < 8; j++) {
buf[i * 8 + j] = password[i] >> j & 1;
}
-
- setkey(key);
}
+ setkey(key);
encrypt(buf, 0);
- for (i = 0; i < 8; i++) {
+ for (i = 0; i < 6; i++) {
for (j = 0, txt[i] = '\0'; j < 8; j++) {
txt[i] |= buf[i * 8 + j] << j;
}
-
- txt[8] = '\0';
}
-
+ txt[6] = '\0';
if (strcmp(password, txt) == 0) return -5;
+
encrypt(buf, 1);
- for (i = 0; i < 8; i++) {
+ for (i = 0; i < 6; i++) {
for (j = 0, txt[i] = '\0'; j < 8; j++) {
txt[i] |= buf[i * 8 + j] << j;
}
-
- txt[8] = '\0';
}
-
+ txt[6] = '\0';
return (strcmp(password, txt) == 0) ? 0 : -6;
}
\ No newline at end of file
--
2.17.1
--
You received this message because you are subscribed to the Google Groups "OSv
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.