<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">On 08.09.20 16:03, Amit anand wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAMkFpM50EQumLKHkL1Jz21H4ET-f1xyWFbqq_LTwJUc06hqdJg@mail.gmail.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div dir="ltr">Hi, <br>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, Sep 8, 2020 at 6:23
PM Ulrich Windl <<a
href="mailto:Ulrich.Windl@rz.uni-regensburg.de"
moz-do-not-send="true">Ulrich.Windl@rz.uni-regensburg.de</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">Hi!<br>
<br>
vbuf is initialized: It has some address on the stack, so
"if (value != vbuf)" is comparing adresses, if I got it
right...<br>
</blockquote>
<div>vbuf having some address on stack and "if(value!=vbuf)"
is comparing addresses doesn't necessarily implies that vbuf
is initialized. <br>
</div>
<div>I am still not clear about where vbuf is initialized.</div>
</div>
</div>
</blockquote>
<p>It is initialized with the strscpy() call.</p>
<p>The comparison just compares the pointer in *value (+) with the
ADDRESS of "vbuf"!</p>
<p>(+) Please ignore my previous remark. I don't know what I had
been smoking at that time!<br>
</p>
<p>So if "value" does not point at "vbuf", it points at some other
buffer, but the data in that buffer should be in "vbuf", so the
contents of the buffer "value" points at is copied into the buffer
named "vbuf"!</p>
<p>If "value" points at "vbuf", the call to
"sd_device_get_sysattr_value" would have already put the data
into "vbuf" and thus the strscpy() would not be needed, as it
would copy "vbuf" into itself.</p>
<p>HTH,</p>
<p>Josef<br>
</p>
<blockquote type="cite"
cite="mid:CAMkFpM50EQumLKHkL1Jz21H4ET-f1xyWFbqq_LTwJUc06hqdJg@mail.gmail.com">
<div dir="ltr">
<div class="gmail_quote">
<div>Also, expecting some information regarding my queries in
below mail.</div>
<div><br>
</div>
<div>Thanks, <br>
</div>
<div>Amit<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<br>
>>> Amit anand <<a
href="mailto:amit.table@gmail.com" target="_blank"
moz-do-not-send="true">amit.table@gmail.com</a>>
schrieb am 08.09.2020 um 13:56 in Nachricht<br>
<CAMkFpM5NFmN+pc_cztmMZW=<a
href="mailto:j1vn2RYC16AgJ3LYL6RSgdqP1eA@mail.gmail.com"
target="_blank" moz-do-not-send="true">j1vn2RYC16AgJ3LYL6RSgdqP1eA@mail.gmail.com</a>>:<br>
> Hi systemd-devel team,<br>
> <br>
> I am trying to understand where "vbuf" is initialized
in function<br>
> "token_match_attr()" in file udev-rules.c<br>
> <br>
> Below code snippet :<br>
> static bool* token_match_attr*(UdevRuleToken *token,
sd_device *dev,<br>
> UdevEvent *event) {<br>
> *char* nbuf[UTIL_NAME_SIZE], *vbuf*[UTIL_NAME_SIZE];
// Here, vbuf is<br>
> defined, however not initialized.<br>
> *const char* *name, **value; *// Here, value is
declared to be of<br>
> type const char *, however, not initialized.<br>
> ...<br>
> ... // some code<br>
> ...<br>
> switch (token->attr_subst_type) { // *Event 1* :
This evaluates to<br>
> SUBST_TYPE_PLAIN<br>
> ...<br>
> case *SUBST_TYPE_PLAIN*: if
(sd_device_get_sysattr_value(dev, name,<br>
> &value) < 0) // *Event 2* :The if condition
evaluates to false.<br>
> return
false;<br>
> break;<br>
> ...// some code<br>
> ...<br>
> }<br>
> <br>
> if
(token->attr_match_remove_trailing_whitespace) { //
*Event<br>
> 4*: If condition evaluates to true<br>
> if (value != vbuf) { // *Event 5*
: vbuf and value<br>
> are both declared but not initialized. Comparison is
done without<br>
> initializing "vbuf" and "value".<br>
> strscpy(vbuf, sizeof(vbuf),
value);<br>
> value = vbuf;<br>
> } // End of if.<br>
> <br>
> delete_trailing_chars(vbuf, NULL);
// *Event 6*:<br>
> trying to delete trailing chars from "vbuf" which is
not initialzed. ??<br>
> } // End of outer if.<br>
> ... // some code<br>
> } /End of function : *token_match_attr()*<br>
> <br>
> Below are my queries :<br>
> 1. *Event 5 *above, we are comparing two resources
("value" and "vbuf")<br>
> even before initializing them.<br>
> Are we doing this comparision to do decision making
based on whether<br>
> the pointer type variable "value" is pointing to "vbuf"
or not.<br>
> *Query*: Kindly confirm whether my understanding is
correct.<br>
> <br>
> 2. *Event 6* above, delete_trailing_chars(vbuf, NULL)
is called outside *if<br>
> (value != vbuf).*<br>
> This implies there may occur a situation where:<br>
> step 1 ) *if (value != vbuf) *condition
fails --> step 2 )<br>
> *vbuf* is not initialzed inside the *if(value != vbuf)
*--> step 3 )<br>
> delete_trailing_chars(*vbuf*, NULL).<br>
> Here, delete_trailing_chars() called for "*vbuf*" which
is not necessarily<br>
> initiazlied.<br>
> *Query*: Kindly let me know if my understanding is
correct or I am missing<br>
> something.<br>
> <br>
> Thanks,<br>
> Amit<br>
<br>
<br>
<br>
<br>
</blockquote>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
systemd-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:systemd-devel@lists.freedesktop.org">systemd-devel@lists.freedesktop.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freedesktop.org/mailman/listinfo/systemd-devel">https://lists.freedesktop.org/mailman/listinfo/systemd-devel</a>
</pre>
</blockquote>
<p><br>
</p>
</body>
</html>