svn commit: r1931262 - subversion/trunk/subversion/libsvn_subr

[email protected]
Newsgroups gmane.comp.version-control.subversion.svn
Message-ID <176821872801.1240855.3469029382147373839@svn02-us-east.apache.org>
Author: brane
Date: Mon Jan 12 11:52:07 2026
New Revision: 1931262

Log:
Fix warnings in the new checksum code.

* subversion/libsvn_subr/checksum.c
  (svn_checksum): Remove unused variable.
* subversion/libsvn_subr/checksum_apr.c: Include <limits.h>.
  (svn_checksum__sha1, svn_checksum__sha1_ctx_update): Do not blindly cast
   or implicitly narrow the data length. Check the limits first.

Modified:
   subversion/trunk/subversion/libsvn_subr/checksum.c
   subversion/trunk/subversion/libsvn_subr/checksum_apr.c

Modified: subversion/trunk/subversion/libsvn_subr/checksum.c
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/checksum.c	Mon Jan 12 11:51:21 2026	(r1931261)
+++ subversion/trunk/subversion/libsvn_subr/checksum.c	Mon Jan 12 11:52:07 2026	(r1931262)
@@ -475,8 +475,6 @@ svn_checksum(svn_checksum_t **checksum,
              apr_size_t len,
              apr_pool_t *pool)
 {
-  apr_sha1_ctx_t sha1_ctx;
-
   SVN_ERR(validate_kind(kind));
   *checksum = svn_checksum_create(kind, pool);
 

Modified: subversion/trunk/subversion/libsvn_subr/checksum_apr.c
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/checksum_apr.c	Mon Jan 12 11:51:21 2026	(r1931261)
+++ subversion/trunk/subversion/libsvn_subr/checksum_apr.c	Mon Jan 12 11:52:07 2026	(r1931262)
@@ -21,6 +21,8 @@
  * ====================================================================
  */
 
+#include <limits.h>
+
 #include "svn_private_config.h"
 #ifdef SVN_CHECKSUM_BACKEND_APR
 
@@ -89,6 +91,10 @@ svn_checksum__sha1(unsigned char *digest
                    apr_size_t len)
 {
   apr_sha1_ctx_t sha1_ctx;
+
+  /* Do not blindly truncate the data length. */
+  SVN_ERR_ASSERT(len < UINT_MAX);
+
   apr_sha1_init(&sha1_ctx);
   apr_sha1_update(&sha1_ctx, data, (unsigned int)len);
   apr_sha1_final(digest, &sha1_ctx);
@@ -121,7 +127,9 @@ svn_checksum__sha1_ctx_update(svn_checks
                               const void *data,
                               apr_size_t len)
 {
-  apr_sha1_update(&ctx->apr_ctx, data, len);
+  /* Do not blindly truncate the data length. */
+  SVN_ERR_ASSERT(len < UINT_MAX);
+  apr_sha1_update(&ctx->apr_ctx, data, (unsigned int)len);
   return SVN_NO_ERROR;
 }
 
@@ -129,10 +137,8 @@ svn_error_t *
 svn_checksum__sha1_ctx_final(unsigned char *digest,
                              svn_checksum__sha1_ctx_t *ctx)
 {
-
   apr_sha1_final(digest, &ctx->apr_ctx);
   return SVN_NO_ERROR;
 }
 
 #endif /* SVN_CHECKSUM_BACKEND_APR */
-
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.