8308071: [REDO] update for deprecated sprintf for src/utils#13995
8308071: [REDO] update for deprecated sprintf for src/utils#13995XueleiFan wants to merge 5 commits intoopenjdk:masterfrom
Conversation
|
👋 Welcome back xuelei! A progress list of the required criteria for merging this PR into |
|
@XueleiFan The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
|
/reviewers 2 |
|
@XueleiFan |
| if (delays) sprintf(p += strlen(p), " delay='%d'", delays); | ||
| size_t used_size = strlen(close); | ||
| char* p = buf + used_size; | ||
| bufsize -= used_size; |
There was a problem hiding this comment.
May not happen in practice, but if used_size is larger than bufsize this will wrap to a very large value. Perhaps the strcpy above should also be an snprintf, and the return value handled the same way as for the subsequent snprintf calls?
There was a problem hiding this comment.
I think it is safe as the buf size has been checked at around line 230. However, it may make the code easier to read if replacing strcpy with snprintf. The patch was updated accordingly.
There was a problem hiding this comment.
This and all uses of snprintf in this change are incorrect. If the output is truncated, snprintf returns the
number of characters that would have been written if there had been enough space. That is, the result
may be larger than bufsize.
There was a problem hiding this comment.
This and all uses of snprintf in this change are incorrect. If the output is truncated, snprintf returns the number of characters that would have been written if there had been enough space. That is, the result may be larger than bufsize.
The correctness of this change depends on the fact that the buffer has sufficient capacity, which has been checked at line 230. I agreed that this is not a typical use of snprintf that the returned value is not checked. I will make an update to check the returned value of snprintf.
There was a problem hiding this comment.
OK, I missed that. (The relevant code doesn't show up in the default github diff. I really ought to know better
than to use that view for reviewing.) Even having been pointed to the code, I had to do some counting and
such to convince myself that it was safe. A bit of commentary might save some time for the next reader.
| if (delays) sprintf(p += strlen(p), " delay='%d'", delays); | ||
| size_t used_size = strlen(close); | ||
| char* p = buf + used_size; | ||
| bufsize -= used_size; |
There was a problem hiding this comment.
This and all uses of snprintf in this change are incorrect. If the output is truncated, snprintf returns the
number of characters that would have been written if there had been enough space. That is, the result
may be larger than bufsize.
| if (dsize) sprintf(p += strlen(p), " dsize='%d'", dsize); | ||
| if (delays) sprintf(p += strlen(p), " delay='%d'", delays); | ||
| size_t used_size = snprintf(buf, bufsize, "%s", close); | ||
| if ((used_size < 0) || (used_size >= bufsize)) { |
There was a problem hiding this comment.
(used_size < 0) is tautologically false, since used_size is a size_t, so unsigned. I'm somewhat surprised
this doesn't trigger a warning from some compiler.
There was a problem hiding this comment.
Updated to use int to replace size_t.. Thank you for the catching.
There was a problem hiding this comment.
bufsize is size_t, so that's a comparison between signed and unsigned values, which I think some compilers
will warn about. Maybe the preceding check for negative is getting rid of that? But will that still occur in
a slowdebug build, or will the lack of optimization lead to a warning?
There was a problem hiding this comment.
As always, this comment helps a lot. Thank you!
Updated to cast int to size_t explicitly.
There was a problem hiding this comment.
@kimbarrett Did you have a chance to have another look? Please let me know if you prefer to the update that the returned value of snprintf() is not checked because the memory size has been checked previously.
| if (delays) sprintf(p += strlen(p), " delay='%d'", delays); | ||
| size_t used_size = strlen(close); | ||
| char* p = buf + used_size; | ||
| bufsize -= used_size; |
There was a problem hiding this comment.
OK, I missed that. (The relevant code doesn't show up in the default github diff. I really ought to know better
than to use that view for reviewing.) Even having been pointed to the code, I had to do some counting and
such to convince myself that it was safe. A bit of commentary might save some time for the next reader.
|
@XueleiFan This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
|
@XueleiFan This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the |
Hi,
This is a redo of JDK-8307855, where issues were found after integration.
The sprintf is deprecated in Xcode 14, and Microsoft Virtual Studio, because of security concerns. The issue was addressed in JDK-8296812 for building failure, and JDK-8299378/JDK-8299635/JDK-8301132 for testing issues . This is a break-down update for sprintf uses in the src/utils directory.
Thanks,
Xuelei
Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/13995/head:pull/13995$ git checkout pull/13995Update a local copy of the PR:
$ git checkout pull/13995$ git pull https://git.openjdk.org/jdk.git pull/13995/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 13995View PR using the GUI difftool:
$ git pr show -t 13995Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/13995.diff
Webrev
Link to Webrev Comment