<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<meta content="text/html; charset=US-ASCII" http-equiv="Content-Type">
<title>
GitLab
</title>
<style>img {
max-width: 100%; height: auto;
}
</style>
</head>
<body>
<div class="content">
<p style="color: #777777;">
<a href="https://gitlab.com/dueno">Daiki Ueno</a>
started a new
discussion on <a href="https://gitlab.com/gnutls/gnutls/-/merge_requests/1560#note_881711609">lib/pkcs11.c</a>:
</p>
<table class="code" style="font-family: monospace; font-size: 90%;" bgcolor="#fff" width="100%" cellpadding="0" cellspacing="0">
<tr class="line_holder" style="line-height: 1.6;">
<td class="old_line diff-line-num" data-linenumber="3100" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
3100
</td>
<td class="new_line diff-line-num" data-linenumber="3100" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
3100
</td>
<td class="line_content" style="padding-left: 0.5em; padding-right: 0.5em;"><pre style="margin: 0;"> <span id="LC3100" class="line" lang="c"> <span class="p">}</span></span>
</pre></td>
</tr>
<tr class="line_holder" style="line-height: 1.6;">
<td class="old_line diff-line-num" data-linenumber="3101" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
3101
</td>
<td class="new_line diff-line-num" data-linenumber="3101" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
3101
</td>
<td class="line_content" style="padding-left: 0.5em; padding-right: 0.5em;"><pre style="margin: 0;"> <span id="LC3101" class="line" lang="c"></span>
</pre></td>
</tr>
<tr class="line_holder" style="line-height: 1.6;">
<td class="old_line diff-line-num" data-linenumber="3102" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
3102
</td>
<td class="new_line diff-line-num" data-linenumber="3102" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
3102
</td>
<td class="line_content" style="padding-left: 0.5em; padding-right: 0.5em;"><pre style="margin: 0;"> <span id="LC3102" class="line" lang="c"> <span class="k" style="font-weight: 600;">if</span> <span class="p">(</span><span class="n" style="color: #333;">current</span> <span class="o" style="font-weight: 600;">></span> <span class="n" style="color: #333;">list</span><span class="o" style="font-weight: 600;">-></span><span class="n" style="color: #333;">key_ids_size</span><span class="p">)</span></span>
</pre></td>
</tr>
<tr class="line_holder" style="line-height: 1.6;">
<td class="old_line diff-line-num" data-linenumber="3103" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
3103
</td>
<td class="new_line diff-line-num" data-linenumber="3103" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
3103
</td>
<td class="line_content" style="padding-left: 0.5em; padding-right: 0.5em;"><pre style="margin: 0;"> <span id="LC3103" class="line" lang="c"> <span class="k" style="font-weight: 600;">break</span><span class="p">;</span></span>
</pre></td>
</tr>
</table>
<div class="md" style="">
<p dir="auto">I suspect this condition might have an off-by-one error (and might potentially cause out-of-bound write to <code>list->key_ids</code> array in a hypothetical case, i.e., the second C_FindObjects returns more results than the first call does).</p>
<p dir="auto">To make the loop invariant clear, maybe it could be merged into the <code>while</code> condition above, something like:</p>
<div class="gl-relative markdown-code-block js-markdown-code">
<pre class="code highlight js-syntax-highlight language-c" lang="c" v-pre="true" style="border-radius: 2px; background-color: #fff; font-family: monospace; font-size: 90%; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 100%; margin: 0 0 8px; padding: 8px 12px; border: 1px solid #dbdbdb;"><code><span id="LC1" class="line" lang="c"> <span class="k" style="font-weight: 600;">while</span> <span class="p">(</span><span class="n" style="color: #333;">pkcs11_find_objects</span></span>
<span id="LC2" class="line" lang="c"> <span class="p">(</span><span class="n" style="color: #333;">sinfo</span><span class="o" style="font-weight: 600;">-></span><span class="n" style="color: #333;">module</span><span class="p">,</span> <span class="n" style="color: #333;">sinfo</span><span class="o" style="font-weight: 600;">-></span><span class="n" style="color: #333;">pks</span><span class="p">,</span> <span class="o" style="font-weight: 600;">&</span><span class="n" style="color: #333;">ctx</span><span class="p">,</span> <span class="mi" style="color: #099;">1</span><span class="p">,</span> <span class="o" style="font-weight: 600;">&</span><span class="n" style="color: #333;">count</span><span class="p">)</span> <span class="o" style="font-weight: 600;">==</span> <span class="n" style="color: #333;">CKR_OK</span></span>
<span id="LC3" class="line" lang="c"> <span class="o" style="font-weight: 600;">&&</span> <span class="n" style="color: #333;">count</span> <span class="o" style="font-weight: 600;">==</span> <span class="mi" style="color: #099;">1</span></span>
<span id="LC4" class="line" lang="c"> <span class="o" style="font-weight: 600;">&&</span> <span class="n" style="color: #333;">current</span> <span class="o" style="font-weight: 600;"><</span> <span class="n" style="color: #333;">list</span><span class="o" style="font-weight: 600;">-></span><span class="n" style="color: #333;">key_ids_size</span><span class="p">)</span> <span class="p">{</span></span></code></pre>
<copy-code></copy-code>
</div>
</div>
</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #666;">
—
<br>
Reply to this email directly or <a href="https://gitlab.com/gnutls/gnutls/-/merge_requests/1560#note_881711609">view it on GitLab</a>.
<br>
You're receiving this email because of your account on gitlab.com.
If you'd like to receive fewer emails, you can
<a href="https://gitlab.com/-/sent_notifications/1704df8d5ccb8eee38001afc1b71d8dc/unsubscribe">unsubscribe</a>
from this thread or
adjust your notification settings.
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Merge request","url":"https://gitlab.com/gnutls/gnutls/-/merge_requests/1560#note_881711609"}}</script>
</p>
</div>
</body>
</html>