Skip to content

Replace strcpy with safe string copy#130547

Merged
jkotas merged 7 commits into
dotnet:mainfrom
am11:patch-54
Jul 13, 2026
Merged

Replace strcpy with safe string copy#130547
jkotas merged 7 commits into
dotnet:mainfrom
am11:patch-54

Conversation

@am11

@am11 am11 commented Jul 11, 2026

Copy link
Copy Markdown
Member

There are 10 usages of strcpy API under src/coreclr/nativeaot, but openbsd lld linker warns on this particular usage during PublishAot time. Overall, it's a harmless warning:

$ dotnet new webapiaot -n webapi-aot; cd $_
$ dotnet publish -o dist -c Release
Restore succeeded with 1 warning(s) in 2.7s
    /home/am11/projects/webapi-aot/webapi-aot.csproj : warning NU1603: webapi-aot depends on Microsoft.AspNetCore.OpenApi (>= 11.0.0-preview.7.26357.199) but Microsoft.AspNetCore.OpenApi 11.0.0-preview.7.26357.199 was not found. Microsoft.AspNetCore.OpenApi 11.0.0-preview.7.26358.101 was resolved instead.
    info NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
  webapi-aot net11.0 openbsd-x64 succeeded with 2 warning(s) (30.5s) → dist/
    /home/am11/projects/webapi-aot/webapi-aot.csproj : warning NU1603: webapi-aot depends on Microsoft.AspNetCore.OpenApi (>= 11.0.0-preview.7.26357.199) but Microsoft.AspNetCore.OpenApi 11.0.0-preview.7.26357.199 was not found. Microsoft.AspNetCore.OpenApi 11.0.0-preview.7.26358.101 was resolved instead.
    ld.lld : warning gcenv.ee.cpp:571 (/dotnet/src/runtime/src/coreclr/nativeaot/Runtime/gcenv.ee.cpp:571)(gcenv.ee.cpp.o:(GCToEEInterface::CreateThread(void (*)(void*), void*, bool, char const*)) in archive /home/am11/.dotnet/packs/Microsoft.NETCore.App.Runtime.NativeAOT.openbsd-x64/11.0.0-preview.7.26357.199/runtimes/openbsd-x64/native/libRuntime.ServerGC.a): warning: strcpy() is almost always misused, please use strlcpy()

Build succeeded with 3 warning(s) in 38.2s

$ dist/webapi-aot
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /home/am11/projects/webapi-aot
na^Cinfo: Microsoft.Hosting.Lifetime[0]
      Application is shutting down...

[1] 51537

$ curl -sSL http://localhost:5000/todos | jq
[
  {
    "id": 1,
    "title": "Walk the dog",
    "dueBy": null,
    "isComplete": false
  },
  {
    "id": 2,
    "title": "Do the dishes",
    "dueBy": "2026-07-11",
    "isComplete": false
  },
  {
    "id": 3,
    "title": "Do the laundry",
    "dueBy": "2026-07-12",
    "isComplete": false
  },
  {
    "id": 4,
    "title": "Clean the bathroom",
    "dueBy": null,
    "isComplete": false
  },
  {
    "id": 5,
    "title": "Clean the car",
    "dueBy": "2026-07-13",
    "isComplete": false
  }
]

@am11
am11 requested a review from MichalStrehovsky as a code owner July 11, 2026 11:25
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jul 11, 2026
@am11 am11 added the os-openbsd OpenBSD OS, currently not officially supported label Jul 11, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

@am11 am11 changed the title Replace strcpy with strlcpy for safer string copy Replace strcpy with safe string copy Jul 11, 2026
@am11
am11 requested a review from jkotas July 11, 2026 15:02
@jkotas

jkotas commented Jul 11, 2026

Copy link
Copy Markdown
Member

under src/coreclr/nativeaot, but openbsd lld linker warns on this particular usage during PublishAot time.

Why does it warn on this one, and not on all the other ones?

@am11

am11 commented Jul 12, 2026

Copy link
Copy Markdown
Member Author

Others are probably inlined by clang.

Comment thread src/coreclr/nativeaot/Runtime/gcenv.ee.cpp Outdated
Comment thread src/coreclr/nativeaot/Runtime/gcenv.ee.cpp

@jkotas jkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@jkotas
jkotas enabled auto-merge (squash) July 12, 2026 23:05
@jkotas

jkotas commented Jul 13, 2026

Copy link
Copy Markdown
Member

/ba-g infrastructure timeout

@jkotas
jkotas merged commit 010acab into dotnet:main Jul 13, 2026
111 of 112 checks passed
@am11
am11 deleted the patch-54 branch July 13, 2026 08:02
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 14, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
There are 10 usages of `strcpy` API under src/coreclr/nativeaot, but
openbsd lld linker warns on this particular usage during PublishAot
time. 

---------

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member os-openbsd OpenBSD OS, currently not officially supported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants